Extend applyLoopGuards() to take into account conditions/assumes proving some value %v to be divisible by D by rewriting %v to (%v / D) * D. This lets the loop unroller and the loop vectorizer identify more loops as not requiring remainder loops.
Details
Diff Detail
Event Timeline
llvm/test/Transforms/LoopUnroll/runtime-unroll-assume-no-remainder.ll | ||
---|---|---|
8 | could you also add version of this test that checks %cmp in the guard condition, instead of an assume? | |
46 | is this extra branch needed? | |
58 | the extra blocks should not be needed for unrolling. | |
69 | can we either change %i.011 to i64 or the users to use i32 instead of the extension? | |
81 | should not be needed for unrolling. |
llvm/lib/Analysis/ScalarEvolution.cpp | ||
---|---|---|
13282 | Nevermind, I was thinking about something else and we probably need the div & multiply to make sure the SCEV logic can determine the right multiple. |
LGTM with the additional tests, thanks!
I did some testing and it appears this exposes a crash in matchURem. I'm taking a look at that now, I think it would be good to wait with landing the change until this is resolved.
llvm/test/Transforms/LoopUnroll/runtime-unroll-assume-no-remainder.ll | ||
---|---|---|
8 | could you add a similar negative test, e.g. where the and does not strip the lowest bit? | |
llvm/test/Transforms/LoopVectorize/dont-fold-tail-for-divisible-TC.ll | ||
67 | could you add a similar negative test, e.g. where the and does not strip the lowest bit? Perhaps also add a test using urem? |
Excellent, thanks!
llvm/test/Transforms/LoopVectorize/dont-fold-tail-for-divisible-TC.ll | ||
---|---|---|
67 |
Will do.
Ah, good catch!
|
llvm/test/Transforms/LoopVectorize/dont-fold-tail-for-divisible-TC.ll | ||
---|---|---|
67 |
That sounds like an independent improvement to SCEV.
Sounds good, thanks! |
Here we basically are matching a SCEV URem expression, right? There's a helper for that (matchURem), which should help to simplify the code a bit?