[llvm] [VPlan] Avoid copying over nsw on certain inductions (PR #168922)

Danila Malyutin via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 20 10:22:46 PST 2025


================
@@ -87,9 +87,15 @@ inline VPIRFlags getFlagsFromIndDesc(const InductionDescriptor &ID) {
     return ID.getInductionBinOp()->getFastMathFlags();
 
   if (auto *OBO = dyn_cast_if_present<OverflowingBinaryOperator>(
-          ID.getInductionBinOp()))
-    return VPIRFlags::WrapFlagsTy(OBO->hasNoUnsignedWrap(),
-                                  OBO->hasNoSignedWrap());
+          ID.getInductionBinOp())) {
+    // We must drop nsw if the signs of the induction start and the induction
+    // step differ, as this could sign-wrap over iterations.
+    bool HasNSW = OBO->hasNoSignedWrap() && ID.getConstIntStartValue() &&
+                  ID.getConstIntStepValue() &&
+                  !(ID.getConstIntStartValue()->isNegative() ^
+                    ID.getConstIntStepValue()->isNegative());
----------------
danilaml wrote:

Can this just be `ID.getConstIntStartValue()->isNegative() == ID.getConstIntStepValue()->isNegative()`?

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


More information about the llvm-commits mailing list