[SCEV] Apply loop guards against min/max for its arguments
This replaces several rewriting rules in ScalarEvolution::applyLoopGuards that are applied to min/max expressions with the equivalent ones but applied to its arguments. So previously given we had a loop guard min(a, b) >= c, the min expression would get rewritten as max(c, min(a, b)). With such approach, we were unable to apply the rewrite if min operands were zext for example (min(zext(a), zext(b))), however it's equivalent to the expression zext(min(a, b)) for which we could apply the rewrite. Now we'd rewrite the min operands also with these expressions: a -> max(c, a) and b -> max(c, b). and this would allow us to apply the loop guard in this and similar cases: min(zext(a), zext(b)) would get rewritten as min(zext(max(c, a)), zext(max(c, b))) instead of just being skipped. The list of added rules (omitting predicates signedness for simplicity): 1. Guard: min(a, b) >= c Old rule: min(a, b) -> max(c, min(a, b)) New rules: a -> max(a, c) and b -> max(b, c) 2. Guard: min(a, b) > c Old rule: min(a, b) -> max(c + 1, min(a, b)) New rules: a -> max(a, c + 1) and b -> max(b, c + 1) 3. Guard: max(a, b) <= c Old rule: max(a, b) -> min(c, max(a, b)) New rules: a -> min(a, c) and b -> min(b, c) 4. Guard: max(a, b) < c Old rule: max(a, b) -> min(c - 1, max(a, b)) New rules: a -> min(a, c - 1) and b -> min(b, c - 1) The old rewrites still hold. Differential Revision: https://reviews.llvm.org/D145230
Loading
Please sign in to comment