[llvm] [ScalarEvolutionExpander] Don't drop nowrap flags on addrec expansion (PR #78199)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 15 10:26:32 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: William Moses (wsmoses)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/78199.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp (+2-1) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/78199


More information about the llvm-commits mailing list