[flang-commits] [flang] [llvm] [VPlan] Expand WidenInt inductions with nuw/nsw (PR #163538)

Luke Lau via flang-commits flang-commits at lists.llvm.org
Fri Oct 24 01:49:39 PDT 2025


================
@@ -122,6 +122,22 @@ std::optional<VPValue *>
 getRecipesForUncountableExit(VPlan &Plan,
                              SmallVectorImpl<VPRecipeBase *> &Recipes,
                              SmallVectorImpl<VPRecipeBase *> &GEPs);
+
+/// Extracts and returns nowrap flags from the induction binop in \p ID. \p
+/// DropNWFlags tells us whether whether we should drop NoWrap flags, which we
+/// should when tail-folding, for example.
+inline VPIRFlags getNoWrapFlagsFromIndDesc(const InductionDescriptor &ID,
+                                           bool DropNWFlags) {
+  if (ID.getKind() == InductionDescriptor::IK_FpInduction)
+    return ID.getInductionBinOp()->getFastMathFlags();
----------------
lukel97 wrote:

Oh I see the FP flags used to be propagated in expandWidenIntOrFpInduction. 

> Not sure why we need to drop FMF for tail-folded loops?

For the same reason we would need to drop it for integer inductions, i.e. to prevent generating poison on masked off lanes.

But after thinking about this the masked off lanes aren't used anyway, so I think it's actually safe to just always copy the flags. Since we're doing that for the fast math flags already.

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


More information about the flang-commits mailing list