-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[ScalarEvolutionExpander] Don't drop nowrap flags on addrec expansion #78199
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-llvm-transforms Author: William Moses (wsmoses) ChangesWhen performing expand on a SCEVAddRecNode with nowrap applied (e.g. if deduced from an iv with an increment with nowrap), the generated multiply will not have the nowrap. This PR preserves the nowrap behavior on the generated code. Full diff: https://github.com/llvm/llvm-project/pull/78199.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index a1d7f0f9ba0f74..e87b430d6bee8f 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -1254,7 +1254,8 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
expand(SE.getTruncateOrNoop(
SE.getMulExpr(SE.getUnknown(CanonicalIV),
SE.getNoopOrAnyExtend(S->getOperand(1),
- CanonicalIV->getType())),
+ CanonicalIV->getType()),
+ S->getNoWrapFlags(SCEV::FlagNW)),
Ty));
// If this is a chain of recurrences, turn it into a closed form, using the
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
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.
Tests?
SE.getMulExpr( | ||
SE.getUnknown(CanonicalIV), | ||
SE.getNoopOrAnyExtend(S->getOperand(1), CanonicalIV->getType()), | ||
S->getNoWrapFlags(SCEV::FlagNW)), |
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.
This doesn't make sense. NW is only meaningful/supported on addrecs, while you're applying it to a mul.
Yeah I wasn't quite sure where to add them, if you had any pointers |
I'm not sure where exactly we expand addrecs in canonical mode, so I'd suggest adding an assert into the branch and seeing which tests fail, then modify those. |
Ah well, it looks like you effectively already did that by trying to use an invalid nowrap flag. List of failing tests:
Probably LoopIdiom is the best candidate for a test case. |
When performing expand on a SCEVAddRecNode with nowrap applied (e.g. if deduced from an iv with an increment with nowrap), the generated multiply will not have the nowrap. This PR preserves the nowrap behavior on the generated code.