Skip to content

Commit f25fd0b

Browse files
committed
[LV] Use IVUpdateMayOverflow to set HasNUW.
If IVUpdateMayOverflow is false, we proved that the induction increment cannot overflow in the vector loop. This allows setting NUW in some cases when folding the tail.
1 parent dac0f7e commit f25fd0b

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9014,9 +9014,12 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
90149014

90159015
DebugLoc DL = getDebugLocFromInstOrOperands(Legal->getPrimaryInduction());
90169016
TailFoldingStyle Style = CM.getTailFoldingStyle(IVUpdateMayOverflow);
9017-
// When not folding the tail, we know that the induction increment will not
9018-
// overflow.
9019-
bool HasNUW = Style == TailFoldingStyle::None;
9017+
// Use NUW for the induction increment if we proved that it won't overflow in
9018+
// the vector loop or when not folding the tail. Then we know that the
9019+
// induction increment will not overflow as the vector trip count is >=
9020+
// increment and a multiple of the increment.
9021+
bool HasNUW = !IVUpdateMayOverflow || Style == TailFoldingStyle::None;
9022+
;
90209023
addCanonicalIVRecipes(*Plan, Legal->getWidestInductionType(), HasNUW, DL);
90219024

90229025
VPRecipeBuilder RecipeBuilder(*Plan, OrigLoop, TLI, Legal, CM, PSE, Builder);

llvm/test/Transforms/LoopVectorize/ARM/tail-folding-loop-hint.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ define dso_local void @predicate_loop_hint(ptr noalias nocapture %A, ptr noalias
5050
; CHECK: %[[WML2:.*]] = call <4 x i32> @llvm.masked.load.v4i32.p0({{.*}}<4 x i1> %active.lane.mask
5151
; CHECK: %[[ADD:.*]] = add nsw <4 x i32> %[[WML2]], %[[WML1]]
5252
; CHECK: call void @llvm.masked.store.v4i32.p0(<4 x i32> %[[ADD]], {{.*}}<4 x i1> %active.lane.mask
53-
; CHECK: %index.next = add i64 %index, 4
53+
; CHECK: %index.next = add nuw i64 %index, 4
5454
; CHECK: br i1 %{{.*}}, label %{{.*}}, label %vector.body, !llvm.loop [[VEC_LOOP2:![0-9]+]]
5555
;
5656
; CHECK: br i1 %{{.*}}, label %{{.*}}, label %for.body, !llvm.loop [[SCALAR_LOOP2:![0-9]+]]

llvm/test/Transforms/LoopVectorize/RISCV/pr88802.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ define void @test(ptr %p, i64 %a, i8 %b) {
5555
; CHECK-NEXT: br label [[PRED_STORE_CONTINUE8]]
5656
; CHECK: pred.store.continue8:
5757
; CHECK-NEXT: [[VEC_IND_NEXT]] = add <4 x i32> [[VEC_IND]], <i32 4, i32 4, i32 4, i32 4>
58-
; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], 4
58+
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
5959
; CHECK-NEXT: br i1 true, label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY1]], !llvm.loop [[LOOP0:![0-9]+]]
6060
; CHECK: middle.block:
6161
; CHECK-NEXT: br i1 true, label [[EXIT:%.*]], label [[SCALAR_PH]]

llvm/test/Transforms/LoopVectorize/X86/pr81872.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ define void @test(ptr noundef align 8 dereferenceable_or_null(16) %arr) #0 {
3535
; CHECK-NEXT: [[TMP8:%.*]] = getelementptr i64, ptr [[TMP7]], i32 -3
3636
; CHECK-NEXT: [[REVERSE:%.*]] = shufflevector <4 x i1> [[TMP4]], <4 x i1> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
3737
; CHECK-NEXT: call void @llvm.masked.store.v4i64.p0(<4 x i64> <i64 1, i64 1, i64 1, i64 1>, ptr [[TMP8]], i32 8, <4 x i1> [[REVERSE]])
38-
; CHECK-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 4
38+
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
3939
; CHECK-NEXT: [[VEC_IND_NEXT]] = add <4 x i64> [[VEC_IND]], <i64 -4, i64 -4, i64 -4, i64 -4>
4040
; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], 12
4141
; CHECK-NEXT: br i1 [[TMP9]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !prof [[PROF1:![0-9]+]], !llvm.loop [[LOOP2:![0-9]+]]

0 commit comments

Comments
 (0)