[llvm] [LLVM][SCEV] Look through common vscale multiplicand when simplifying compares. (PR #141798)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 18 04:51:19 PDT 2025
================
@@ -10785,6 +10785,25 @@ bool ScalarEvolution::SimplifyICmpOperands(CmpPredicate &Pred, const SCEV *&LHS,
if (Depth >= 3)
return false;
+ const SCEV *NewLHS, *NewRHS;
+ if (match(LHS, m_scev_c_Mul(m_SCEV(NewLHS), m_SCEVVScale())) &&
+ match(RHS, m_scev_c_Mul(m_SCEV(NewRHS), m_SCEVVScale()))) {
+ const SCEVMulExpr *LMul = cast<SCEVMulExpr>(LHS);
+ const SCEVMulExpr *RMul = cast<SCEVMulExpr>(RHS);
+
+ // (X * vscale) uicmp/eq/ne (Y * vscale) ==> X uicmp/eq/ne Y
+ // when neither multiply wraps.
+ // (X * vscale) sicmp (Y * vscale) ==> X sicmp Y
+ // when neither multiply changes sign.
+ if ((LMul->hasNoSignedWrap() && RMul->hasNoSignedWrap()) ||
+ (LMul->hasNoUnsignedWrap() && RMul->hasNoUnsignedWrap() &&
+ !ICmpInst::isSigned(Pred))) {
----------------
fhahn wrote:
Would be good to reorder & update comment to match the condition?
```suggestion
// (X * vscale) pred (Y * vscale) ==> X pred Y
// when both multiples are NSW.
// (X * vscale) uicmp/eq/ne (Y * vscale) ==> X uicmp/eq/ne Y
// when both multiples are NUW.
if ((LMul->hasNoSignedWrap() && RMul->hasNoSignedWrap()) ||
(LMul->hasNoUnsignedWrap() && RMul->hasNoUnsignedWrap() &&
!ICmpInst::isSigned(Pred))) {
```
https://github.com/llvm/llvm-project/pull/141798
More information about the llvm-commits
mailing list