[llvm] [LLVM][SCEV] Look through common multiplicand when simplifying compares. (PR #141798)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Fri May 30 08:45:07 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) &&
----------------
paulwalker-arm wrote:
To be advantageous the result needs to fold away and I wasn't to test anything other than this scenario, whereby constants are canonicalised to be the first SCEVMulExpr operand.
https://github.com/llvm/llvm-project/pull/141798
More information about the llvm-commits
mailing list