-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SCEV] Better preserve wrapping info in SimplifyICmpOperands for UGE. #144404
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 |
---|---|---|
|
@@ -10892,7 +10892,12 @@ bool ScalarEvolution::SimplifyICmpOperands(CmpPredicate &Pred, const SCEV *&LHS, | |
} | ||
break; | ||
case ICmpInst::ICMP_UGE: | ||
if (!getUnsignedRangeMin(RHS).isMinValue()) { | ||
// If RHS is an op we can fold the -1, try that first. | ||
// Otherwise prefer LHS to preserve the nuw flag. | ||
if ((isa<SCEVConstant>(RHS) || | ||
(isa<SCEVAddExpr, SCEVAddRecExpr>(RHS) && | ||
isa<SCEVConstant>(cast<SCEVNAryExpr>(RHS)->getOperand(0)))) && | ||
!getUnsignedRangeMin(RHS).isMinValue()) { | ||
RHS = getAddExpr(getConstant(RHS->getType(), (uint64_t)-1, true), RHS); | ||
Pred = ICmpInst::ICMP_UGT; | ||
Changed = true; | ||
|
@@ -10901,6 +10906,10 @@ bool ScalarEvolution::SimplifyICmpOperands(CmpPredicate &Pred, const SCEV *&LHS, | |
SCEV::FlagNUW); | ||
Pred = ICmpInst::ICMP_UGT; | ||
Changed = true; | ||
} else if (!getUnsignedRangeMin(RHS).isMinValue()) { | ||
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. I really don't like the code structure here, but I don't have a good suggestion on improving it either... 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. Same here, but I also didn't find anything better :( 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. @nikic Not sure if this could be an acceptable alternative: https://gist.github.com/antoniofrighetto/83c188d5ad0a4988eec8d4c30684dafe. It started relatively well, it didn't really end up as good as originally envisioned (NFCI, as RHS is checked first for UGE, might not want this as we probably should preserve the flag). |
||
RHS = getAddExpr(getConstant(RHS->getType(), (uint64_t)-1, true), RHS); | ||
Pred = ICmpInst::ICMP_UGT; | ||
Changed = true; | ||
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. Does unconditionally swapping the cases cause regressions? 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, we would loose flags in The current version doesn't have any regression on a large test-set of C/C++ workloads. 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. llvm-opt-benchmark results are available here: https://github.com/dtcxzyw/llvm-opt-benchmark/pull/2452/files |
||
} | ||
break; | ||
default: | ||
|
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.
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.
Added thanks