-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SCEV] Generalize (C * A /u C) -> A fold to (C1 * A /u C2) -> C1/C2 * A. #157159
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 all commits
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 |
---|---|---|
|
@@ -3216,13 +3216,16 @@ const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl<const SCEV *> &Ops, | |
}; | ||
} | ||
|
||
// Try to fold (C * D /u C) -> D, if C is a power-of-2 and D is a multiple | ||
// of C. | ||
// Try to fold (C1 * D /u C2) -> C1/C2 * D, if C1 and C2 are powers-of-2, | ||
// D is a multiple of C2, and C1 is a multiple of C1. | ||
const SCEV *D; | ||
if (match(Ops[1], m_scev_UDiv(m_SCEV(D), m_scev_Specific(LHSC))) && | ||
LHSC->getAPInt().isPowerOf2() && | ||
LHSC->getAPInt().logBase2() <= getMinTrailingZeros(D)) { | ||
return D; | ||
const SCEVConstant *C2; | ||
const APInt &LHSV = LHSC->getAPInt(); | ||
if (LHSV.isPowerOf2() && | ||
match(Ops[1], m_scev_UDiv(m_SCEV(D), m_SCEVConstant(C2))) && | ||
C2->getAPInt().isPowerOf2() && LHSV.uge(C2->getAPInt()) && | ||
LHSV.logBase2() <= getMinTrailingZeros(D)) { | ||
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. FWIW, the actual underlying API for getMinTrailingZeros() is getConstantMultiple(), so this is probably easy to generalize to the non-pow2 case. 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. Yep, initially I was checking for multiples directly, but started with just the power-of-2 cases, then extend it further |
||
return getMulExpr(getUDivExpr(LHSC, C2), D); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably say C1 is a multiple of C2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I adjusted this in a follow-up PR (#157555), but can also fix separately.