Reassociate should sometimes be redone after loop canonicalization
| Bugzilla Link | 16116 |
| Version | trunk |
| OS | Windows NT |
| CC | @atrick,@hfinkel |
Extended Description
The normal order of passes are:
- reassociate
- loop simplication/rotate
- licm (loop invariant code motion)
I found a speed regression between 3.1 and 3.2 (and later) because of the following :
In the samples below I observer the following behavior:
Both start with the same expression: %add = add i32 %total.0, %next.0 %add1 = add i32 %add, 1
-LLVM-3.1 converts this into: --after Reassociate expressions: %add = add i32 %next.0, 1 %add1 = add i32 %add, %total.0 -- after Canonicalize natural loops: %add = add i32 %next.0.ph, 1 %add1 = add i32 %add, %total.0 -- and during 'loop invariant code motion': LICM hoisting to while.cond.outer: %add = add i32 %next.0.ph, 1
- LLVM-3.2 converts it into: (Notice the reversion of %total.0 and %next.0) --after Reassociate expressions: %add = add i32 %total.0, 1 %add1 = add i32 %add, %next.0 -- after Canonicalize natural loops: %add = add i32 %total.0, 1 %add1 = add i32 %add, %next.0.ph -- and during 'loop invariant code motion': -> %next.0.ph and '1' are loop invariant, but because those are spreaded, they are not moved any more.
So:
- loop canonicalization introduces new opportunities for variables to be moved outside the loop, but as reassociate expression is not redone, it depends on 'luck' (= order of the expression) if the opportunity is indeed seen.
Yes. I think we should have an early round of loop simplify/rotate/full unroll before the main SSA opts. LICM would run later in the second round of loop opts. I'm not quite ready to start moving passes around, that will take some analysis. I did make a note of this issue for whenever I get around to that sort of work.