Skip to content

Commit 4d12229

Browse files
committed
[LV] Preserve GEP nusw when widening memory
1 parent 194360c commit 4d12229

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7487,12 +7487,11 @@ VPRecipeBuilder::tryToWidenMemory(Instruction *I, ArrayRef<VPValue *> Operands,
74877487
VPSingleDefRecipe *VectorPtr;
74887488
if (Reverse) {
74897489
// When folding the tail, we may compute an address that we don't in the
7490-
// original scalar loop and it may not be inbounds. Drop Inbounds in that
7491-
// case.
7490+
// original scalar loop: use none in this case.
74927491
GEPNoWrapFlags Flags =
7493-
(CM.foldTailByMasking() || !GEP || !GEP->isInBounds())
7492+
CM.foldTailByMasking() || !GEP
74947493
? GEPNoWrapFlags::none()
7495-
: GEPNoWrapFlags::inBounds();
7494+
: GEP->getNoWrapFlags().withoutNoUnsignedWrap();
74967495
VectorPtr =
74977496
new VPVectorEndPointerRecipe(Ptr, &Plan.getVF(), getLoadStoreType(I),
74987497
/*Stride*/ -1, Flags, I->getDebugLoc());

llvm/test/Transforms/LoopVectorize/reverse-induction-gep-nowrap-flags.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ define i32 @preserve_nusw(i64 %start, ptr %ptr) {
7474
; CHECK-NEXT: [[OFFSET_IDX:%.*]] = sub i64 [[START]], [[INDEX]]
7575
; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[OFFSET_IDX]], -1
7676
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr nusw i32, ptr [[PTR]], i64 [[TMP0]]
77-
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr i32, ptr [[TMP1]], i32 0
78-
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr i32, ptr [[TMP2]], i32 -3
77+
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr nusw i32, ptr [[TMP1]], i32 0
78+
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr nusw i32, ptr [[TMP2]], i32 -3
7979
; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP3]], align 4
8080
; CHECK-NEXT: [[REVERSE:%.*]] = shufflevector <4 x i32> [[WIDE_LOAD]], <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
8181
; CHECK-NEXT: [[TMP4]] = add <4 x i32> [[REVERSE]], [[VEC_PHI]]

0 commit comments

Comments
 (0)