diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -4989,6 +4989,13 @@ case Instruction::SRem: return I->getOperand(1); + case Instruction::Br: { + const auto *BranchI = cast(I); + if (!BranchI->isConditional()) + return nullptr; + return BranchI->getCondition(); + } + case Instruction::Call: if (auto *II = dyn_cast(I)) { switch (II->getIntrinsicID()) { diff --git a/llvm/test/Analysis/ScalarEvolution/limit-depth.ll b/llvm/test/Analysis/ScalarEvolution/limit-depth.ll --- a/llvm/test/Analysis/ScalarEvolution/limit-depth.ll +++ b/llvm/test/Analysis/ScalarEvolution/limit-depth.ll @@ -46,7 +46,7 @@ define void @test_sext(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) { ; CHECK-LABEL: @test_sext ; CHECK: %se2 = sext i64 %iv2.inc to i128 -; CHECK-NEXT: --> {(1 + (sext i64 {(sext i32 (1 + %a) to i64),+,1}<%loop> to i128)),+,1}<%loop2> +; CHECK-NEXT: --> {(1 + (sext i64 {(sext i32 (1 + %a) to i64),+,1}<%loop> to i128)),+,1}<%loop2> entry: br label %loop @@ -102,7 +102,7 @@ define void @test_trunc(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) { ; CHECK-LABEL: @test_trunc ; CHECK: %trunc2 = trunc i64 %iv2.inc to i32 -; CHECK-NEXT: --> {(trunc i64 (1 + {7,+,1}<%loop>) to i32),+,1}<%loop2> +; CHECK-NEXT: --> {(trunc i64 (1 + {7,+,1}<%loop>) to i32),+,1}<%loop2> entry: br label %loop diff --git a/llvm/test/Analysis/ScalarEvolution/trip-count12.ll b/llvm/test/Analysis/ScalarEvolution/trip-count12.ll --- a/llvm/test/Analysis/ScalarEvolution/trip-count12.ll +++ b/llvm/test/Analysis/ScalarEvolution/trip-count12.ll @@ -1,7 +1,7 @@ ; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s ; CHECK: Determining loop execution counts for: @test -; CHECK: Loop %for.body: backedge-taken count is ((-2 + %len) /u 2) +; CHECK: Loop %for.body: backedge-taken count is ((-2 + %len) /u 2) ; CHECK: Loop %for.body: max backedge-taken count is 1073741823 define zeroext i16 @test(i16* nocapture %p, i32 %len) nounwind readonly { diff --git a/llvm/test/Analysis/ScalarEvolution/trip-count9.ll b/llvm/test/Analysis/ScalarEvolution/trip-count9.ll --- a/llvm/test/Analysis/ScalarEvolution/trip-count9.ll +++ b/llvm/test/Analysis/ScalarEvolution/trip-count9.ll @@ -224,9 +224,9 @@ define void @nsw_startx(i4 %n, i4 %x) { ; CHECK-LABEL: 'nsw_startx' ; CHECK-NEXT: Determining loop execution counts for: @nsw_startx -; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax %n)) +; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax %n)) ; CHECK-NEXT: Loop %loop: max backedge-taken count is -1 -; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax %n)) +; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax %n)) ; CHECK-NEXT: Predicates: ; CHECK: Loop %loop: Trip multiple is 1 ; @@ -245,9 +245,9 @@ define void @nsw_startx_step2(i4 %n, i4 %x) { ; CHECK-LABEL: 'nsw_startx_step2' ; CHECK-NEXT: Determining loop execution counts for: @nsw_startx_step2 -; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax %n)) /u 2) +; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax %n)) /u 2) ; CHECK-NEXT: Loop %loop: max backedge-taken count is 7 -; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax %n)) /u 2) +; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax %n)) /u 2) ; CHECK-NEXT: Predicates: ; CHECK: Loop %loop: Trip multiple is 1 ; @@ -486,9 +486,9 @@ define void @even_nsw_startx(i4 %n, i4 %x) { ; CHECK-LABEL: 'even_nsw_startx' ; CHECK-NEXT: Determining loop execution counts for: @even_nsw_startx -; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax (2 * %n))) +; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax (2 * %n))) ; CHECK-NEXT: Loop %loop: max backedge-taken count is -2 -; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax (2 * %n))) +; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + (-1 * %x) + ((1 + %x) smax (2 * %n))) ; CHECK-NEXT: Predicates: ; CHECK: Loop %loop: Trip multiple is 1 ; @@ -508,9 +508,9 @@ define void @even_nsw_startx_step2(i4 %n, i4 %x) { ; CHECK-LABEL: 'even_nsw_startx_step2' ; CHECK-NEXT: Determining loop execution counts for: @even_nsw_startx_step2 -; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax (2 * %n))) /u 2) +; CHECK-NEXT: Loop %loop: backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax (2 * %n))) /u 2) ; CHECK-NEXT: Loop %loop: max backedge-taken count is 7 -; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax (2 * %n))) /u 2) +; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is ((-1 + (-1 * %x) + ((2 + %x) smax (2 * %n))) /u 2) ; CHECK-NEXT: Predicates: ; CHECK: Loop %loop: Trip multiple is 1 ; diff --git a/llvm/test/Transforms/IndVarSimplify/X86/loop-invariant-conditions.ll b/llvm/test/Transforms/IndVarSimplify/X86/loop-invariant-conditions.ll --- a/llvm/test/Transforms/IndVarSimplify/X86/loop-invariant-conditions.ll +++ b/llvm/test/Transforms/IndVarSimplify/X86/loop-invariant-conditions.ll @@ -345,7 +345,7 @@ ; CHECK-NEXT: br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[START]], [[ENTRY:%.*]] ], [ [[INDVARS_IV_NEXT:%.*]], [[BACKEDGE:%.*]] ] -; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], 1 +; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nsw i64 [[INDVARS_IV]], 1 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 25 ; CHECK-NEXT: br i1 [[CMP]], label [[BACKEDGE]], label [[FOR_END:%.*]] ; CHECK: backedge: diff --git a/llvm/test/Transforms/IndVarSimplify/lftr-reuse.ll b/llvm/test/Transforms/IndVarSimplify/lftr-reuse.ll --- a/llvm/test/Transforms/IndVarSimplify/lftr-reuse.ll +++ b/llvm/test/Transforms/IndVarSimplify/lftr-reuse.ll @@ -67,7 +67,7 @@ ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 0, [[SUB1]] ; CHECK-NEXT: br i1 [[CMP1]], label [[OUTER_PREHEADER:%.*]], label [[EXIT:%.*]] ; CHECK: outer.preheader: -; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[ARG]], -1 +; CHECK-NEXT: [[TMP0:%.*]] = add nsw i32 [[ARG]], -1 ; CHECK-NEXT: br label [[OUTER:%.*]] ; CHECK: outer: ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i32 [ [[TMP0]], [[OUTER_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[OUTER_INC:%.*]] ] diff --git a/llvm/test/Transforms/LoopUnroll/runtime-small-upperbound.ll b/llvm/test/Transforms/LoopUnroll/runtime-small-upperbound.ll --- a/llvm/test/Transforms/LoopUnroll/runtime-small-upperbound.ll +++ b/llvm/test/Transforms/LoopUnroll/runtime-small-upperbound.ll @@ -1,22 +1,24 @@ -; RUN: opt -S -loop-unroll -unroll-runtime %s -o - | FileCheck %s -; RUN: opt -S -loop-unroll -unroll-runtime -unroll-max-upperbound=6 %s -o - | FileCheck %s --check-prefix=UPPER +; RUN: opt -S -loop-unroll -unroll-runtime -unroll-max-upperbound=2 %s -o - | FileCheck %s --check-prefix=HOGE3-UNROLLED --check-prefix=HOGE5-UNROLLED +; RUN: opt -S -loop-unroll -unroll-runtime -unroll-max-upperbound=5 %s -o - | FileCheck %s --check-prefix=HOGE3-NOUNROLL --check-prefix=HOGE5-UNROLLED +; RUN: opt -S -loop-unroll -unroll-runtime -unroll-max-upperbound=6 %s -o - | FileCheck %s --check-prefix=HOGE3-NOUNROLL --check-prefix=HOGE5-NOUNROLL target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" @global = dso_local local_unnamed_addr global i32 0, align 4 @global.1 = dso_local local_unnamed_addr global i8* null, align 4 -; Check that loop in hoge_3, with a runtime upperbound of 3, is not unrolled. -; CHECK-LABEL: hoge_3 -; CHECK: loop: -; CHECK: store -; CHECK-NOT: store -; CHECK: br i1 %{{.*}}, label %loop -; UPPER-LABEL: hoge_3 -; UPPER: loop: -; UPPER: store -; UPPER-NOT: store -; UPPER: br i1 %{{.*}}, label %loop +; Check that loop in hoge_3, with a runtime upperbound of 3, is not unrolled with -unroll-max-upperbound=5 or 6, but is unrolled with -unroll-max-upperbound=2. +; HOGE3-UNROLLED-LABEL: hoge_3 +; HOGE3-UNROLLED: loop: +; HOGE3-UNROLLED: store +; HOGE3-UNROLLED: store +; HOGE3-UNROLLED: store +; HOGE3-UNROLLED: br i1 %{{.*}}, label %loop +; HOGE3-NOUNROLL-LABEL: hoge_3 +; HOGE3-NOUNROLL: loop: +; HOGE3-NOUNROLL: store +; HOGE3-NOUNROLL-NOT: store +; HOGE3-NOUNROLL: br i1 %{{.*}}, label %loop define dso_local void @hoge_3(i8 %arg) { entry: %x = load i32, i32* @global, align 4 @@ -37,18 +39,21 @@ ret void } -; Check that loop in hoge_5, with a runtime upperbound of 5, is unrolled when -unroll-max-upperbound=4 -; CHECK-LABEL: hoge_5 -; CHECK: loop: -; CHECK: store -; CHECK-NOT: store -; CHECK: br i1 %{{.*}}, label %loop -; UPPER-LABEL: hoge_5 -; UPPER: loop: -; UPPER: store -; UPPER: store -; UPPER: store -; UPPER: br i1 %{{.*}}, label %loop +; Check that loop in hoge_5, with a runtime upperbound of 5, is unrolled when +; -unroll-max-upperbound=5, but not unrolled with -unroll-max-upperbound=6 +; HOGE5-UNROLLED-LABEL: hoge_5 +; HOGE5-UNROLLED: loop: +; HOGE5-UNROLLED: store +; HOGE5-UNROLLED: store +; HOGE5-UNROLLED: store +; HOGE5-UNROLLED: store +; HOGE5-UNROLLED: store +; HOGE5-UNROLLED: br i1 %{{.*}}, label %loop +; HOGE5-NOUNROLL-LABEL: hoge_5 +; HOGE5-NOUNROLL: loop: +; HOGE5-NOUNROLL: store +; HOGE5-NOUNROLL-NOT: store +; HOGE5-NOUNROLL: br i1 %{{.*}}, label %loop define dso_local void @hoge_5(i8 %arg) { entry: %x = load i32, i32* @global, align 4 diff --git a/llvm/test/Transforms/LoopVectorize/X86/small-size.ll b/llvm/test/Transforms/LoopVectorize/X86/small-size.ll --- a/llvm/test/Transforms/LoopVectorize/X86/small-size.ll +++ b/llvm/test/Transforms/LoopVectorize/X86/small-size.ll @@ -136,7 +136,7 @@ ; CHECK-NEXT: [[TMP17:%.*]] = icmp eq i32 [[N]], 0 ; CHECK-NEXT: br i1 [[TMP17]], label [[DOT_CRIT_EDGE:%.*]], label [[DOTLR_PH_PREHEADER:%.*]] ; CHECK: .lr.ph.preheader: -; CHECK-NEXT: [[TMP18:%.*]] = add i32 [[N]], -1 +; CHECK-NEXT: [[TMP18:%.*]] = add nsw i32 [[N]], -1 ; CHECK-NEXT: [[TMP19:%.*]] = zext i32 [[TMP18]] to i64 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH8:%.*]], label [[VECTOR_PH10:%.*]] ; CHECK: vector.ph10: @@ -323,7 +323,7 @@ ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[N:%.*]], 0 ; CHECK-NEXT: br i1 [[TMP1]], label [[DOT_CRIT_EDGE:%.*]], label [[DOTLR_PH_PREHEADER:%.*]] ; CHECK: .lr.ph.preheader: -; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[N]], -1 +; CHECK-NEXT: [[TMP2:%.*]] = add nsw i32 [[N]], -1 ; CHECK-NEXT: [[TMP3:%.*]] = zext i32 [[TMP2]] to i64 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]] ; CHECK: vector.ph: diff --git a/llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll b/llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll --- a/llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll +++ b/llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll @@ -63,7 +63,7 @@ %tmp1 = getelementptr inbounds i32, i32* %a, i64 %i %tmp2 = load i32, i32* %tmp1, align 8 %tmp3 = add i32 %tmp0, %tmp2 - %i.next = add nuw nsw i64 %i, -1 + %i.next = add nsw i64 %i, -1 %cond = icmp sgt i64 %i.next, 0 br i1 %cond, label %for.body, label %for.end @@ -179,7 +179,7 @@ %tmp4 = load i32, i32* %tmp2, align 8 %tmp5 = add i32 %tmp3, %tmp4 %tmp6 = add i32 %tmp0, %tmp5 - %i.next = add nuw nsw i64 %i, -1 + %i.next = add nsw i64 %i, -1 %cond = icmp sgt i64 %i.next, 0 br i1 %cond, label %for.body, label %for.end