[llvm] [VPlan] Refine DerivedIV nowrap contract (PR #205908)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 2 03:00:58 PDT 2026
================
@@ -4008,12 +4016,22 @@ static void expandVPDerivedIV(VPDerivedIVRecipe *R) {
case InductionDescriptor::IK_IntInduction: {
assert(Index->getScalarType() == Start->getScalarType() &&
"Index type does not match StartValue type");
+ VPIRFlags::WrapFlagsTy NW;
+ auto *RFlags = dyn_cast<VPRecipeWithIRFlags>(Index);
+ if (RFlags && RFlags->hasNoWrapFlags())
+ NW = RFlags->getNoWrapFlags();
return R->replaceAllUsesWith(Builder.createAdd(
- Start, Builder.createOverflowingOp(Instruction::Mul, {Index, Step})));
+ Start,
+ Builder.createOverflowingOp(Instruction::Mul, {Index, Step},
+ R->getNoWrapFlags()),
+ R->getDebugLoc(), "", NW));
}
case InductionDescriptor::IK_PtrInduction:
- return R->replaceAllUsesWith(Builder.createPtrAdd(
- Start, Builder.createOverflowingOp(Instruction::Mul, {Index, Step})));
+ return R->replaceAllUsesWith(Builder.createNoWrapPtrAdd(
+ Start,
+ Builder.createOverflowingOp(Instruction::Mul, {Index, Step},
+ R->getNoWrapFlags(), R->getDebugLoc()),
+ GEPNoWrapFlags::noUnsignedSignedWrap()));
----------------
fhahn wrote:
I think here we also need to check the flags from the induction, otherwsie we may add `nusw` to a pointer induction formed by a GEP w/o nusw, making the result more poisonous? https://alive2.llvm.org/ce/z/oU4fiA
https://github.com/llvm/llvm-project/pull/205908
More information about the llvm-commits
mailing list