More constant multiplies will be folded. This prevents SCEVs from
being generated with mismatches such as
{((4 * ((-1 * %x1) + %X.unr)) + %1),+,32}<%Loop>
vs
{((4 * %X.unr) + (-4 * %x1) + %1),+,32}
Differential D6487
Add more opportunities for constant folding in ScalarEvolution. timmurray on Dec 2 2014, 3:11 PM. Authored by
Details
More constant multiplies will be folded. This prevents SCEVs from {((4 * ((-1 * %x1) + %X.unr)) + %1),+,32}<%Loop> vs {((4 * %X.unr) + (-4 * %x1) + %1),+,32}
Diff Detail Event Timeline
Comment Actions LGTM with comment.
Comment Actions It looks like I LGTM'd it with comments that aren't resolved. If you don't have commit access, please upload a version which I can commit for you with no changes. Usually I LGTM+comments with the expectation that you can resolve the comments and commit without going through another round of review. |
I forget; are expr's guaranteed to be "GroupByComplexity"'d? If so, ContainsConstantSomewhere can be optimized greatly. If there's any constant, it's guaranteed to be in a group at the end. You only recurse on Add and Mul, so if you've gone past those (to umax, smax, unknown or could-not-compute, you can stop).
Also, please iterate with a worklist instead of recursing. Create a SmallVector<SCEV*>, push your starting element into it, use pop_back_val to grab the latest one off the top of the list. If you're worried about revisiting the same thing multiple times, add a SmallSet<SCEV*> and test whether inserting the new element succeeds -- if it doesn't, it's already in the set.