remove useless loop in a function body

Bug #554190 reported by Roman Marynchak
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Confirmed
Wishlist
Unassigned

Bug Description

I cannot imagine the simpler example than this one:

(defun completely-useless ()
    (loop for i from 1 to 10000000000 do (= 1 1)))

However, it does iterates in that loop... Is there some misunderstanding from my side, or SBCL just gives up any loop optimizations? I will not even try more complex examples from the famous book "Optimizing Compilers for Modern Architectures: A Dependence-based Approach", since they require more advanced loop analysis logic in the compiler than SBCL seems to have these days.

Regards,
Roman

Tags: optimization
Revision history for this message
Nathan Froyd (froydnj) wrote :

SBCL does not do any classic loop optimizations (e.g. unrolling), let alone any of the higher-level transforms described in Allen and Kennedy.

Changed in sbcl:
importance: Undecided → Wishlist
tags: added: optimization
Changed in sbcl:
status: New → Confirmed
Revision history for this message
Nikodemus Siivola (nikodemus) wrote :

SBCL does rudimentary loop analysis to aid register allocation and aligning loop heads -- but that's it.

In this case it's particularly sad as the (= 1 1) is optimized away -- so the loop is quite breathtaking:

; B0: L0: 4883C108 ADD RCX, 8
; B4: L1: 483B0D25000000 CMP RCX, [RIP+37]
; BB: 7EF3 JLE L0

summary: - SBCL fails to remove the simplest useless loop in a function body
+ remove useless loop in a function body
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.