[llvm] [LLVM][SCEV] Look through common multiplicand when simplifying compares. (PR #141798)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 1 07:23:08 PDT 2025
================
@@ -10748,6 +10748,22 @@ bool ScalarEvolution::SimplifyICmpOperands(CmpPredicate &Pred, const SCEV *&LHS,
if (Depth >= 3)
return false;
+ // (X * Z) icmp (Y * Z) ==> X icmp Y
+ // when neither multiply wraps and Z is positive.
+ if (isa<SCEVMulExpr>(LHS) && isa<SCEVMulExpr>(RHS)) {
+ const SCEVMulExpr *LMul = cast<SCEVMulExpr>(LHS);
+ const SCEVMulExpr *RMul = cast<SCEVMulExpr>(RHS);
+
+ if (LMul->getNumOperands() == 2 && RMul->getNumOperands() == 2 &&
+ LMul->getOperand(1) == RMul->getOperand(1) &&
----------------
nikic wrote:
I think a simple case would be something like `range(0, 10) %a, range(10, 20) %b` and then `%a * vscale` and `%b * vscale`? I think in that case the common operand would be the first.
https://github.com/llvm/llvm-project/pull/141798
More information about the llvm-commits
mailing list