Index: llvm/lib/Analysis/ValueTracking.cpp =================================================================== --- llvm/lib/Analysis/ValueTracking.cpp +++ llvm/lib/Analysis/ValueTracking.cpp @@ -5089,6 +5089,11 @@ break; } + case Instruction::Br: + case Instruction::Switch: + Operands.insert(I->getOperand(0)); + break; + default: break; } Index: llvm/test/Analysis/ScalarEvolution/exact-exit-count-more-precise.ll =================================================================== --- llvm/test/Analysis/ScalarEvolution/exact-exit-count-more-precise.ll +++ llvm/test/Analysis/ScalarEvolution/exact-exit-count-more-precise.ll @@ -10,7 +10,7 @@ ; CHECK-NEXT: %_tmp25.i = phi i16 [ %in, %bb2 ], [ %_tmp6.i, %bb1.i ] ; CHECK-NEXT: --> {%in,+,1}<%bb1.i> U: full-set S: full-set Exits: 1 LoopDispositions: { %bb1.i: Computable, %bb2: Variant } ; CHECK-NEXT: %_tmp6.i = add nsw i16 %_tmp25.i, 1 -; CHECK-NEXT: --> {(1 + %in),+,1}<%bb1.i> U: full-set S: full-set Exits: 2 LoopDispositions: { %bb1.i: Computable, %bb2: Variant } +; CHECK-NEXT: --> {(1 + %in),+,1}<%bb1.i> U: full-set S: full-set Exits: 2 LoopDispositions: { %bb1.i: Computable, %bb2: Variant } ; CHECK-NEXT: %or.cond = and i1 %_tmp10.i, %exitcond.i ; CHECK-NEXT: --> %or.cond U: full-set S: full-set Exits: true LoopDispositions: { %bb1.i: Variant, %bb2: Variant } ; CHECK-NEXT: Determining loop execution counts for: @test_and @@ -48,7 +48,7 @@ ; CHECK-NEXT: %1 = trunc i64 %indvars.iv to i32 ; CHECK-NEXT: --> -1 U: [-1,0) S: [-1,0) Exits: -1 LoopDispositions: { %BB: Invariant } ; CHECK-NEXT: %2 = add nsw i32 %1, %sum.01 -; CHECK-NEXT: --> {(-1 + undef),+,-1}<%BB> U: full-set S: full-set Exits: -1 LoopDispositions: { %BB: Computable } +; CHECK-NEXT: --> {(-1 + undef),+,-1}<%BB> U: full-set S: full-set Exits: -1 LoopDispositions: { %BB: Computable } ; CHECK-NEXT: %B3 = add i32 %1, %2 ; CHECK-NEXT: --> {(-2 + undef),+,-1}<%BB> U: full-set S: full-set Exits: -2 LoopDispositions: { %BB: Computable } ; CHECK-NEXT: %B = or i1 %C5, %C11 Index: llvm/test/Analysis/ScalarEvolution/limit-depth.ll =================================================================== --- llvm/test/Analysis/ScalarEvolution/limit-depth.ll +++ llvm/test/Analysis/ScalarEvolution/limit-depth.ll @@ -60,7 +60,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 @@ -116,7 +116,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 Index: llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll =================================================================== --- llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll +++ llvm/test/Analysis/ScalarEvolution/max-backedge-taken-count-guard-info.ll @@ -12,7 +12,7 @@ ; CHECK-NEXT: %idx = getelementptr inbounds i32, i32* %a, i64 %iv ; CHECK-NEXT: --> {((4 * %i) + %a),+,4}<%loop> U: full-set S: full-set Exits: (60 + %a) LoopDispositions: { %loop: Computable } ; CHECK-NEXT: %iv.next = add nuw nsw i64 %iv, 1 -; CHECK-NEXT: --> {(1 + %i),+,1}<%loop> U: full-set S: full-set Exits: 16 LoopDispositions: { %loop: Computable } +; CHECK-NEXT: --> {(1 + %i),+,1}<%loop> U: [1,0) S: [-9223372036854775807,-9223372036854775808) Exits: 16 LoopDispositions: { %loop: Computable } ; CHECK-NEXT: Determining loop execution counts for: @test_guard_less_than_16 ; CHECK-NEXT: Loop %loop: backedge-taken count is (15 + (-1 * %i)) ; CHECK-NEXT: Loop %loop: max backedge-taken count is 15 @@ -44,7 +44,7 @@ ; CHECK-NEXT: %idx = getelementptr inbounds i32, i32* %a, i64 %iv ; CHECK-NEXT: --> {((4 * %i) + %a),+,4}<%loop> U: full-set S: full-set Exits: (60 + %a) LoopDispositions: { %loop: Computable } ; CHECK-NEXT: %iv.next = add nuw nsw i64 %iv, 1 -; CHECK-NEXT: --> {(1 + %i),+,1}<%loop> U: full-set S: full-set Exits: 16 LoopDispositions: { %loop: Computable } +; CHECK-NEXT: --> {(1 + %i),+,1}<%loop> U: [1,0) S: [-9223372036854775807,-9223372036854775808) Exits: 16 LoopDispositions: { %loop: Computable } ; CHECK-NEXT: Determining loop execution counts for: @test_guard_less_than_16_operands_swapped ; CHECK-NEXT: Loop %loop: backedge-taken count is (15 + (-1 * %i)) ; CHECK-NEXT: Loop %loop: max backedge-taken count is 15 @@ -76,7 +76,7 @@ ; CHECK-NEXT: %idx = getelementptr inbounds i32, i32* %a, i64 %iv ; CHECK-NEXT: --> {((4 * %i) + %a),+,4}<%loop> U: full-set S: full-set Exits: (60 + %a) LoopDispositions: { %loop: Computable } ; CHECK-NEXT: %iv.next = add nuw nsw i64 %iv, 1 -; CHECK-NEXT: --> {(1 + %i),+,1}<%loop> U: full-set S: full-set Exits: 16 LoopDispositions: { %loop: Computable } +; CHECK-NEXT: --> {(1 + %i),+,1}<%loop> U: [1,0) S: [-9223372036854775807,-9223372036854775808) Exits: 16 LoopDispositions: { %loop: Computable } ; CHECK-NEXT: Determining loop execution counts for: @test_guard_less_than_16_branches_flipped ; CHECK-NEXT: Loop %loop: backedge-taken count is (15 + (-1 * %i)) ; CHECK-NEXT: Loop %loop: max backedge-taken count is -1 @@ -108,7 +108,7 @@ ; CHECK-NEXT: %idx = getelementptr inbounds i32, i32* %a, i64 %iv ; CHECK-NEXT: --> {((4 * %i) + %a),+,4}<%loop> U: full-set S: full-set Exits: (60 + %a) LoopDispositions: { %loop: Computable } ; CHECK-NEXT: %iv.next = add nuw nsw i64 %iv, 1 -; CHECK-NEXT: --> {(1 + %i),+,1}<%loop> U: full-set S: full-set Exits: 16 LoopDispositions: { %loop: Computable } +; CHECK-NEXT: --> {(1 + %i),+,1}<%loop> U: [1,0) S: [-9223372036854775807,-9223372036854775808) Exits: 16 LoopDispositions: { %loop: Computable } ; CHECK-NEXT: Determining loop execution counts for: @test_guard_uge_16_branches_flipped ; CHECK-NEXT: Loop %loop: backedge-taken count is (15 + (-1 * %i)) ; CHECK-NEXT: Loop %loop: max backedge-taken count is 15 Index: llvm/test/Analysis/ScalarEvolution/trip-count12.ll =================================================================== --- llvm/test/Analysis/ScalarEvolution/trip-count12.ll +++ llvm/test/Analysis/ScalarEvolution/trip-count12.ll @@ -2,7 +2,7 @@ ; RUN: opt < %s -disable-output "-passes=print" 2>&1 | 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 { Index: llvm/test/Analysis/ScalarEvolution/trip-count9.ll =================================================================== --- llvm/test/Analysis/ScalarEvolution/trip-count9.ll +++ llvm/test/Analysis/ScalarEvolution/trip-count9.ll @@ -225,9 +225,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 ; @@ -246,9 +246,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 ; @@ -487,9 +487,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 ; @@ -509,9 +509,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 ; Index: llvm/test/Transforms/IndVarSimplify/X86/loop-invariant-conditions.ll =================================================================== --- llvm/test/Transforms/IndVarSimplify/X86/loop-invariant-conditions.ll +++ llvm/test/Transforms/IndVarSimplify/X86/loop-invariant-conditions.ll @@ -193,7 +193,7 @@ define void @test7(i64 %start, i64* %inc_ptr) { ; CHECK-LABEL: @test7( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[INC:%.*]] = load i64, i64* [[INC_PTR:%.*]], !range !0 +; CHECK-NEXT: [[INC:%.*]] = load i64, i64* [[INC_PTR:%.*]], align 8, [[RNG0:!range !.*]] ; CHECK-NEXT: [[OK:%.*]] = icmp sge i64 [[INC]], 0 ; CHECK-NEXT: br i1 [[OK]], label [[LOOP_PREHEADER:%.*]], label [[FOR_END:%.*]] ; CHECK: loop.preheader: @@ -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: @@ -405,7 +405,7 @@ define void @test8(i64 %start, i64* %inc_ptr) { ; CHECK-LABEL: @test8( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[INC:%.*]] = load i64, i64* [[INC_PTR:%.*]], !range !1 +; CHECK-NEXT: [[INC:%.*]] = load i64, i64* [[INC_PTR:%.*]], align 8, [[RNG1:!range !.*]] ; CHECK-NEXT: [[OK:%.*]] = icmp sge i64 [[INC]], 0 ; CHECK-NEXT: br i1 [[OK]], label [[LOOP_PREHEADER:%.*]], label [[FOR_END:%.*]] ; CHECK: loop.preheader: @@ -525,7 +525,7 @@ define void @test11(i64* %inc_ptr) { ; CHECK-LABEL: @test11( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[INC:%.*]] = load i64, i64* [[INC_PTR:%.*]], !range !0 +; CHECK-NEXT: [[INC:%.*]] = load i64, i64* [[INC_PTR:%.*]], align 8, [[RNG0]] ; CHECK-NEXT: [[NE_COND:%.*]] = icmp ne i64 [[INC]], 0 ; CHECK-NEXT: br i1 [[NE_COND]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]] ; CHECK: loop.preheader: @@ -576,7 +576,7 @@ define void @test12(i64* %inc_ptr) { ; CHECK-LABEL: @test12( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[INC:%.*]] = load i64, i64* [[INC_PTR:%.*]], !range !0 +; CHECK-NEXT: [[INC:%.*]] = load i64, i64* [[INC_PTR:%.*]], align 8, [[RNG0]] ; CHECK-NEXT: br label [[LOOP:%.*]] ; CHECK: loop: ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[INC]], [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ] Index: llvm/test/Transforms/IndVarSimplify/lftr-reuse.ll =================================================================== --- llvm/test/Transforms/IndVarSimplify/lftr-reuse.ll +++ llvm/test/Transforms/IndVarSimplify/lftr-reuse.ll @@ -27,7 +27,7 @@ ; CHECK-NEXT: [[SUB_PTR_RHS_CAST:%.*]] = ptrtoint i8* [[BASE]] to i64 ; CHECK-NEXT: [[SUB_PTR_SUB:%.*]] = sub i64 [[SUB_PTR_LHS_CAST]], [[SUB_PTR_RHS_CAST]] ; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[SUB_PTR_SUB]] to i8 -; CHECK-NEXT: store i8 [[CONV]], i8* [[P_02]] +; CHECK-NEXT: store i8 [[CONV]], i8* [[P_02]], align 1 ; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i8, i8* [[P_02]], i32 1 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i8* [[INCDEC_PTR]], [[ADD_PTR]] ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]] @@ -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:%.*]] ] @@ -142,10 +142,10 @@ ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[LOOP_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[LOOP]] ] ; CHECK-NEXT: [[TMP1:%.*]] = add nsw i64 [[INDVARS_IV]], [[INDVARS_IV2]] ; CHECK-NEXT: [[MATRIXP:%.*]] = getelementptr inbounds [0 x double], [0 x double]* [[MATRIX:%.*]], i32 0, i64 [[TMP1]] -; CHECK-NEXT: [[V1:%.*]] = load double, double* [[MATRIXP]] +; CHECK-NEXT: [[V1:%.*]] = load double, double* [[MATRIXP]], align 8 ; CHECK-NEXT: call void @use(double [[V1]]) ; CHECK-NEXT: [[VECTORP:%.*]] = getelementptr inbounds [0 x double], [0 x double]* [[VECTOR:%.*]], i32 0, i64 [[INDVARS_IV2]] -; CHECK-NEXT: [[V2:%.*]] = load double, double* [[VECTORP]] +; CHECK-NEXT: [[V2:%.*]] = load double, double* [[VECTORP]], align 8 ; CHECK-NEXT: call void @use(double [[V2]]) ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nsw i64 [[INDVARS_IV]], [[TMP0]] ; CHECK-NEXT: [[INDVARS_IV_NEXT3]] = add nuw nsw i64 [[INDVARS_IV2]], 1 @@ -244,7 +244,7 @@ ; CHECK-NEXT: [[I:%.*]] = phi i32 [ [[INC:%.*]], [[LOOP]] ], [ [[X]], [[LOOP_PREHEADER]] ] ; CHECK-NEXT: [[APTR:%.*]] = phi i8* [ [[INCDEC_PTR:%.*]], [[LOOP]] ], [ [[ADD_PTR10]], [[LOOP_PREHEADER]] ] ; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i8, i8* [[APTR]], i32 1 -; CHECK-NEXT: store i8 3, i8* [[APTR]] +; CHECK-NEXT: store i8 3, i8* [[APTR]], align 1 ; CHECK-NEXT: [[INC]] = add nuw i32 [[I]], 1 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INC]], [[LIM]] ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]] @@ -311,7 +311,7 @@ ; CHECK: loop: ; CHECK-NEXT: [[APTR:%.*]] = phi i8* [ [[INCDEC_PTR:%.*]], [[LOOP]] ], [ [[IVSTART]], [[LOOP_PREHEADER]] ] ; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i8, i8* [[APTR]], i32 1 -; CHECK-NEXT: store i8 3, i8* [[APTR]] +; CHECK-NEXT: store i8 3, i8* [[APTR]], align 1 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i8* [[INCDEC_PTR]], [[SCEVGEP]] ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT_LOOPEXIT:%.*]] ; CHECK: exit.loopexit: Index: llvm/test/Transforms/LoopUnroll/runtime-small-upperbound.ll =================================================================== --- llvm/test/Transforms/LoopUnroll/runtime-small-upperbound.ll +++ llvm/test/Transforms/LoopUnroll/runtime-small-upperbound.ll @@ -1,6 +1,6 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; 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=4 %s -o - | FileCheck %s --check-prefix=UPPER target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" @@ -103,9 +103,9 @@ ; UPPER-NEXT: [[TMP1:%.*]] = sub i32 16, [[X]] ; UPPER-NEXT: [[TMP2:%.*]] = lshr i32 [[TMP1]], 2 ; UPPER-NEXT: [[TMP3:%.*]] = add nuw nsw i32 [[TMP2]], 1 -; UPPER-NEXT: [[TMP4:%.*]] = urem i32 [[TMP2]], 6 +; UPPER-NEXT: [[TMP4:%.*]] = urem i32 [[TMP2]], 5 ; UPPER-NEXT: [[TMP5:%.*]] = add i32 [[TMP4]], 1 -; UPPER-NEXT: [[XTRAITER:%.*]] = urem i32 [[TMP5]], 6 +; UPPER-NEXT: [[XTRAITER:%.*]] = urem i32 [[TMP5]], 5 ; UPPER-NEXT: [[LCMP_MOD:%.*]] = icmp ne i32 [[XTRAITER]], 0 ; UPPER-NEXT: br i1 [[LCMP_MOD]], label [[LOOP_PROL_PREHEADER:%.*]], label [[LOOP_PROL_LOOPEXIT:%.*]] ; UPPER: loop.prol.preheader: @@ -128,13 +128,13 @@ ; UPPER: loop.prol.loopexit: ; UPPER-NEXT: [[IV_UNR:%.*]] = phi i32 [ [[X]], [[LOOP_PREHEADER]] ], [ [[IV_UNR_PH]], [[LOOP_PROL_LOOPEXIT_UNR_LCSSA]] ] ; UPPER-NEXT: [[PTR_UNR:%.*]] = phi i8* [ [[Y]], [[LOOP_PREHEADER]] ], [ [[PTR_UNR_PH]], [[LOOP_PROL_LOOPEXIT_UNR_LCSSA]] ] -; UPPER-NEXT: [[TMP7:%.*]] = icmp ult i32 [[TMP2]], 5 +; UPPER-NEXT: [[TMP7:%.*]] = icmp ult i32 [[TMP2]], 4 ; UPPER-NEXT: br i1 [[TMP7]], label [[EXIT_LOOPEXIT:%.*]], label [[LOOP_PREHEADER_NEW:%.*]] ; UPPER: loop.preheader.new: ; UPPER-NEXT: br label [[LOOP:%.*]] ; UPPER: loop: -; UPPER-NEXT: [[IV:%.*]] = phi i32 [ [[IV_UNR]], [[LOOP_PREHEADER_NEW]] ], [ [[IV_NEXT_5:%.*]], [[LOOP]] ] -; UPPER-NEXT: [[PTR:%.*]] = phi i8* [ [[PTR_UNR]], [[LOOP_PREHEADER_NEW]] ], [ [[PTR_NEXT_5:%.*]], [[LOOP]] ] +; UPPER-NEXT: [[IV:%.*]] = phi i32 [ [[IV_UNR]], [[LOOP_PREHEADER_NEW]] ], [ [[IV_NEXT_4:%.*]], [[LOOP]] ] +; UPPER-NEXT: [[PTR:%.*]] = phi i8* [ [[PTR_UNR]], [[LOOP_PREHEADER_NEW]] ], [ [[PTR_NEXT_4:%.*]], [[LOOP]] ] ; UPPER-NEXT: [[IV_NEXT:%.*]] = add nuw i32 [[IV]], 4 ; UPPER-NEXT: [[PTR_NEXT:%.*]] = getelementptr inbounds i8, i8* [[PTR]], i32 1 ; UPPER-NEXT: store i8 [[ARG]], i8* [[PTR_NEXT]], align 1 @@ -147,13 +147,10 @@ ; UPPER-NEXT: [[IV_NEXT_3:%.*]] = add nuw i32 [[IV_NEXT_2]], 4 ; UPPER-NEXT: [[PTR_NEXT_3:%.*]] = getelementptr inbounds i8, i8* [[PTR_NEXT_2]], i32 1 ; UPPER-NEXT: store i8 [[ARG]], i8* [[PTR_NEXT_3]], align 1 -; UPPER-NEXT: [[IV_NEXT_4:%.*]] = add nuw i32 [[IV_NEXT_3]], 4 -; UPPER-NEXT: [[PTR_NEXT_4:%.*]] = getelementptr inbounds i8, i8* [[PTR_NEXT_3]], i32 1 +; UPPER-NEXT: [[IV_NEXT_4]] = add nuw i32 [[IV_NEXT_3]], 4 +; UPPER-NEXT: [[PTR_NEXT_4]] = getelementptr inbounds i8, i8* [[PTR_NEXT_3]], i32 1 ; UPPER-NEXT: store i8 [[ARG]], i8* [[PTR_NEXT_4]], align 1 -; UPPER-NEXT: [[IV_NEXT_5]] = add nuw i32 [[IV_NEXT_4]], 4 -; UPPER-NEXT: [[PTR_NEXT_5]] = getelementptr inbounds i8, i8* [[PTR_NEXT_4]], i32 1 -; UPPER-NEXT: store i8 [[ARG]], i8* [[PTR_NEXT_5]], align 1 -; UPPER-NEXT: [[TMP8:%.*]] = icmp ult i32 [[IV_NEXT_5]], 17 +; UPPER-NEXT: [[TMP8:%.*]] = icmp ult i32 [[IV_NEXT_4]], 17 ; UPPER-NEXT: br i1 [[TMP8]], label [[LOOP]], label [[EXIT_LOOPEXIT_UNR_LCSSA:%.*]] ; UPPER: exit.loopexit.unr-lcssa: ; UPPER-NEXT: br label [[EXIT_LOOPEXIT]] Index: llvm/test/Transforms/LoopVectorize/X86/small-size.ll =================================================================== --- llvm/test/Transforms/LoopVectorize/X86/small-size.ll +++ 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: Index: llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll =================================================================== --- llvm/test/Transforms/LoopVectorize/consecutive-ptr-uniforms.ll +++ 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 Index: llvm/unittests/Analysis/ValueTrackingTest.cpp =================================================================== --- llvm/unittests/Analysis/ValueTrackingTest.cpp +++ llvm/unittests/Analysis/ValueTrackingTest.cpp @@ -772,6 +772,33 @@ EXPECT_EQ(programUndefinedIfUndefOrPoison(A), false); } +TEST_F(ValueTrackingTest, programUndefinedIfPoison_br) { + parseAssembly("declare i32 @any_num()" + "define void @test(i32 %mask) {\n" + " %A = call i32 @any_num()\n" + " %C = icmp eq i32 %A, 0\n" + " br i1 %C, label %l1, label %l2\n" + "l1:\n" + " ret void\n" + "l2:\n" + " ret void\n" + "}\n"); + EXPECT_EQ(programUndefinedIfPoison(A), true); +} + +TEST_F(ValueTrackingTest, programUndefinedIfPoison_switch) { + parseAssembly("declare i32 @any_num()" + "define void @test(i32 %mask) {\n" + " %A = call i32 @any_num()\n" + " switch i32 %A, label %l1 [ i32 0, label %l2]\n" + "l1:\n" + " ret void\n" + "l2:\n" + " ret void\n" + "}\n"); + EXPECT_EQ(programUndefinedIfPoison(A), true); +} + TEST_F(ValueTrackingTest, isGuaranteedNotToBePoison_exploitBranchCond) { parseAssembly("declare i1 @any_bool()" "define void @test(i1 %y) {\n"