-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[LLVM][SCEV] Look through common vscale multiplicand when simplifying compares. #141798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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))) { | ||||||||||||||||||||||||||||||
Comment on lines
10796
to
10800
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to reorder & update comment to match the condition?
Suggested change
|
||||||||||||||||||||||||||||||
LHS = NewLHS; | ||||||||||||||||||||||||||||||
RHS = NewRHS; | ||||||||||||||||||||||||||||||
Changed = true; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// Canonicalize a constant to the right side. | ||||||||||||||||||||||||||||||
if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(LHS)) { | ||||||||||||||||||||||||||||||
// Check for both operands constant. | ||||||||||||||||||||||||||||||
|
@@ -10959,7 +10978,7 @@ bool ScalarEvolution::SimplifyICmpOperands(CmpPredicate &Pred, const SCEV *&LHS, | |||||||||||||||||||||||||||||
// Recursively simplify until we either hit a recursion limit or nothing | ||||||||||||||||||||||||||||||
// changes. | ||||||||||||||||||||||||||||||
if (Changed) | ||||||||||||||||||||||||||||||
return SimplifyICmpOperands(Pred, LHS, RHS, Depth + 1); | ||||||||||||||||||||||||||||||
return SimplifyICmpOperands(Pred, LHS, RHS, Depth + 1), true; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
Comment on lines
10980
to
10982
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this change necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SimplifyICmpOperands is supposed to return true when a change is made, but this recursive call (based on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, comma expressions are uncommon in LLVM, so kindly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hopefully you don't mind but the extra return looked a little weird so I dropped the return instead? |
||||||||||||||||||||||||||||||
return Changed; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.