Index: llvm/include/llvm/Analysis/ValueTracking.h =================================================================== --- llvm/include/llvm/Analysis/ValueTracking.h +++ llvm/include/llvm/Analysis/ValueTracking.h @@ -809,7 +809,8 @@ /// assume intrinsic, I, at the point in the control-flow identified by the /// context instruction, CxtI. bool isValidAssumeForContext(const Instruction *I, const Instruction *CxtI, - const DominatorTree *DT = nullptr); + const DominatorTree *DT = nullptr, + bool AllowEphemeral = false); enum class OverflowResult { /// Always overflows in the direction of signed/unsigned min value. Index: llvm/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -6865,6 +6865,13 @@ ConservativeResult = ConservativeResult.difference(Disallowed); } + if (U->getType()->isIntOrIntVectorTy()) { + ConstantRange Range = computeConstantRange( + U->getValue(), SignHint == ScalarEvolution::HINT_RANGE_SIGNED, true, + &AC, nullptr, &DT); + ConservativeResult = ConservativeResult.intersectWith(Range, RangeType); + } + return setRange(U, SignHint, std::move(ConservativeResult)); } case scCouldNotCompute: Index: llvm/lib/Analysis/ValueTracking.cpp =================================================================== --- llvm/lib/Analysis/ValueTracking.cpp +++ llvm/lib/Analysis/ValueTracking.cpp @@ -95,6 +95,14 @@ return DL.getPointerTypeSizeInBits(Ty); } +static const Instruction *getArgCxtI(const Argument *A) { + if (!A) + return nullptr; + + const BasicBlock &B = A->getParent()->getEntryBlock(); + return B.empty() ? nullptr : &B.front(); +} + // Given the provided Value and, potentially, a context instruction, return // the preferred context instruction (if any). static const Instruction *safeCxtI(const Value *V, const Instruction *CxtI) { @@ -108,6 +116,10 @@ if (CxtI && CxtI->getParent()) return CxtI; + CxtI = getArgCxtI(dyn_cast(V)); + if (CxtI && CxtI->getParent()) + return CxtI; + return nullptr; } @@ -126,6 +138,14 @@ if (CxtI && CxtI->getParent()) return CxtI; + CxtI = getArgCxtI(dyn_cast(V1)); + if (CxtI && CxtI->getParent()) + return CxtI; + + CxtI = getArgCxtI(dyn_cast(V2)); + if (CxtI && CxtI->getParent()) + return CxtI; + return nullptr; } @@ -511,7 +531,8 @@ bool llvm::isValidAssumeForContext(const Instruction *Inv, const Instruction *CxtI, - const DominatorTree *DT) { + const DominatorTree *DT, + bool AllowEphemeral) { // There are two restrictions on the use of an assume: // 1. The assume must dominate the context (or the control flow must // reach the assume whenever it reaches the context). @@ -542,7 +563,7 @@ if (!isGuaranteedToTransferExecutionToSuccessor(Range, 15)) return false; - return !isEphemeralValueOf(Inv, CxtI); + return AllowEphemeral || !isEphemeralValueOf(Inv, CxtI); } // Inv and CxtI are in different blocks. @@ -8667,6 +8688,8 @@ if (match(V, m_APInt(C))) return ConstantRange(*C); + CtxI = safeCxtI(V, CtxI); + InstrInfoQuery IIQ(UseInstrInfo); unsigned BitWidth = V->getType()->getScalarSizeInBits(); ConstantRange CR = ConstantRange::getFull(BitWidth); @@ -8707,7 +8730,7 @@ assert(I->getCalledFunction()->getIntrinsicID() == Intrinsic::assume && "must be an assume intrinsic"); - if (!isValidAssumeForContext(I, CtxI, DT)) + if (!isValidAssumeForContext(I, CtxI, DT, isa(V))) continue; Value *Arg = I->getArgOperand(0); ICmpInst *Cmp = dyn_cast(Arg); 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 @@ -809,16 +809,16 @@ ; CHECK-LABEL: 'test_guard_and_assume' ; CHECK-NEXT: Classifying expressions for: @test_guard_and_assume ; CHECK-NEXT: %iv = phi i64 [ %iv.next, %loop ], [ 0, %entry ] -; CHECK-NEXT: --> {0,+,1}<%loop> U: [0,4) S: [0,4) Exits: (-1 + %count) LoopDispositions: { %loop: Computable } +; CHECK-NEXT: --> {0,+,1}<%loop> U: [0,4) S: [0,4) Exits: (-1 + %count) LoopDispositions: { %loop: Computable } ; CHECK-NEXT: %idx = getelementptr inbounds i32, ptr %data, i64 %iv -; CHECK-NEXT: --> {%data,+,4}<%loop> U: full-set S: full-set Exits: (-4 + (4 * %count) + %data) LoopDispositions: { %loop: Computable } +; CHECK-NEXT: --> {%data,+,4}<%loop> U: full-set S: full-set Exits: (-4 + (4 * %count) + %data) LoopDispositions: { %loop: Computable } ; CHECK-NEXT: %iv.next = add nuw i64 %iv, 1 ; CHECK-NEXT: --> {1,+,1}<%loop> U: [1,5) S: [1,5) Exits: %count LoopDispositions: { %loop: Computable } ; CHECK-NEXT: Determining loop execution counts for: @test_guard_and_assume -; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + %count) +; CHECK-NEXT: Loop %loop: backedge-taken count is (-1 + %count) ; CHECK-NEXT: Loop %loop: constant max backedge-taken count is 3 -; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (-1 + %count) -; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + %count) +; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (-1 + %count) +; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (-1 + %count) ; CHECK-NEXT: Predicates: ; CHECK: Loop %loop: Trip multiple is 1 ; Index: llvm/test/Analysis/ScalarEvolution/ptrtoint-constantexpr-loop.ll =================================================================== --- llvm/test/Analysis/ScalarEvolution/ptrtoint-constantexpr-loop.ll +++ llvm/test/Analysis/ScalarEvolution/ptrtoint-constantexpr-loop.ll @@ -414,7 +414,7 @@ ; PTR64_IDX64-NEXT: %ii = sext i32 %i to i64 ; PTR64_IDX64-NEXT: --> (sext i32 {1,+,1}<%for.body> to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648) --> (sext i32 (-1 + (trunc i64 (ptrtoint ptr @sext_like_noop to i64) to i32)) to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648) ; PTR64_IDX64-NEXT: %div = sdiv i64 55555, %ii -; PTR64_IDX64-NEXT: --> %div U: full-set S: full-set +; PTR64_IDX64-NEXT: --> %div U: [-55555,55556) S: [-55555,55556) ; PTR64_IDX64-NEXT: %i = phi i32 [ %inc, %for.body ], [ 1, %entry ] ; PTR64_IDX64-NEXT: --> {1,+,1}<%for.body> U: [1,0) S: [1,0) Exits: (-1 + (trunc i64 (ptrtoint ptr @sext_like_noop to i64) to i32)) LoopDispositions: { %for.body: Computable } ; PTR64_IDX64-NEXT: %inc = add nuw i32 %i, 1 @@ -432,7 +432,7 @@ ; PTR64_IDX32-NEXT: %ii = sext i32 %i to i64 ; PTR64_IDX32-NEXT: --> (sext i32 {1,+,1}<%for.body> to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648) --> (sext i32 (-1 + ptrtoint (ptr @sext_like_noop to i32)) to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648) ; PTR64_IDX32-NEXT: %div = sdiv i64 55555, %ii -; PTR64_IDX32-NEXT: --> %div U: full-set S: full-set +; PTR64_IDX32-NEXT: --> %div U: [-55555,55556) S: [-55555,55556) ; PTR64_IDX32-NEXT: %i = phi i32 [ %inc, %for.body ], [ 1, %entry ] ; PTR64_IDX32-NEXT: --> {1,+,1}<%for.body> U: [1,0) S: [1,0) Exits: (-1 + ptrtoint (ptr @sext_like_noop to i32)) LoopDispositions: { %for.body: Computable } ; PTR64_IDX32-NEXT: %inc = add nuw i32 %i, 1 @@ -450,7 +450,7 @@ ; PTR16_IDX16-NEXT: %ii = sext i32 %i to i64 ; PTR16_IDX16-NEXT: --> (sext i32 {1,+,1}<%for.body> to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648) --> (-1 + (zext i16 (ptrtoint ptr @sext_like_noop to i16) to i64)) U: [-1,65535) S: [-1,65535) ; PTR16_IDX16-NEXT: %div = sdiv i64 55555, %ii -; PTR16_IDX16-NEXT: --> %div U: full-set S: full-set +; PTR16_IDX16-NEXT: --> %div U: [-55555,55556) S: [-55555,55556) ; PTR16_IDX16-NEXT: %i = phi i32 [ %inc, %for.body ], [ 1, %entry ] ; PTR16_IDX16-NEXT: --> {1,+,1}<%for.body> U: [1,0) S: [1,0) Exits: (-1 + (zext i16 (ptrtoint ptr @sext_like_noop to i16) to i32)) LoopDispositions: { %for.body: Computable } ; PTR16_IDX16-NEXT: %inc = add nuw i32 %i, 1 @@ -468,7 +468,7 @@ ; PTR16_IDX32-NEXT: %ii = sext i32 %i to i64 ; PTR16_IDX32-NEXT: --> (sext i32 {1,+,1}<%for.body> to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648) --> (-1 + (zext i32 ptrtoint (ptr @sext_like_noop to i32) to i64)) U: [-1,65535) S: [-1,65535) ; PTR16_IDX32-NEXT: %div = sdiv i64 55555, %ii -; PTR16_IDX32-NEXT: --> %div U: full-set S: full-set +; PTR16_IDX32-NEXT: --> %div U: [-55555,55556) S: [-55555,55556) ; PTR16_IDX32-NEXT: %i = phi i32 [ %inc, %for.body ], [ 1, %entry ] ; PTR16_IDX32-NEXT: --> {1,+,1}<%for.body> U: [1,0) S: [1,0) Exits: (-1 + ptrtoint (ptr @sext_like_noop to i32)) LoopDispositions: { %for.body: Computable } ; PTR16_IDX32-NEXT: %inc = add nuw i32 %i, 1 Index: llvm/test/Analysis/ScalarEvolution/ranges.ll =================================================================== --- llvm/test/Analysis/ScalarEvolution/ranges.ll +++ llvm/test/Analysis/ScalarEvolution/ranges.ll @@ -43,7 +43,7 @@ ; CHECK-LABEL: 'shl' ; CHECK-NEXT: Classifying expressions for: @shl ; CHECK-NEXT: %res = shl i32 %a, 2 -; CHECK-NEXT: --> (4 * %a) U: [0,-3) S: [-2147483648,2147483645) +; CHECK-NEXT: --> (4 * %a) U: [0,4093) S: [0,4093) ; CHECK-NEXT: Determining loop execution counts for: @shl ; %res = shl i32 %a, 2 @@ -56,7 +56,7 @@ ; CHECK-LABEL: 'lshr' ; CHECK-NEXT: Classifying expressions for: @lshr ; CHECK-NEXT: %res = lshr i32 %a, 31 -; CHECK-NEXT: --> (%a /u -2147483648) U: [0,2) S: [0,2) +; CHECK-NEXT: --> (%a /u -2147483648) U: [0,1) S: [0,1) ; CHECK-NEXT: Determining loop execution counts for: @lshr ; %res = lshr i32 %a, 31 @@ -70,7 +70,7 @@ ; CHECK-LABEL: 'udiv' ; CHECK-NEXT: Classifying expressions for: @udiv ; CHECK-NEXT: %res = udiv i32 %a, -2147483648 -; CHECK-NEXT: --> (%a /u -2147483648) U: [0,2) S: [0,2) +; CHECK-NEXT: --> (%a /u -2147483648) U: [0,1) S: [0,1) ; CHECK-NEXT: Determining loop execution counts for: @udiv ; %res = udiv i32 %a, 2147483648 @@ -83,7 +83,7 @@ ; CHECK-LABEL: 'sext' ; CHECK-NEXT: Classifying expressions for: @sext ; CHECK-NEXT: %res = sext i8 %a to i64 -; CHECK-NEXT: --> (sext i8 %a to i64) U: [-128,128) S: [-128,128) +; CHECK-NEXT: --> (zext i8 %a to i64) U: [0,128) S: [0,128) ; CHECK-NEXT: Determining loop execution counts for: @sext ; %res = sext i8 %a to i64 @@ -96,7 +96,7 @@ ; CHECK-LABEL: 'zext' ; CHECK-NEXT: Classifying expressions for: @zext ; CHECK-NEXT: %res = zext i8 %a to i64 -; CHECK-NEXT: --> (zext i8 %a to i64) U: [0,256) S: [0,256) +; CHECK-NEXT: --> (zext i8 %a to i64) U: [0,128) S: [0,128) ; CHECK-NEXT: Determining loop execution counts for: @zext ; %res = zext i8 %a to i64 Index: llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll =================================================================== --- llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll +++ llvm/test/Analysis/ScalarEvolution/trip-multiple-guard-info.ll @@ -151,14 +151,14 @@ ; CHECK-NEXT: %u = urem i32 %num, 4 ; CHECK-NEXT: --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4) ; CHECK-NEXT: %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ] -; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable } +; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable } ; CHECK-NEXT: %inc = add nuw nsw i32 %i.010, 1 ; CHECK-NEXT: --> {1,+,1}<%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable } ; CHECK-NEXT: Determining loop execution counts for: @test_trip_multiple_4_sgt_5 -; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + %num) ; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is 2147483646 -; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + %num) -; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num) ; CHECK-NEXT: Predicates: ; CHECK: Loop %for.body: Trip multiple is 4 ; @@ -187,14 +187,14 @@ ; CHECK-NEXT: %u = urem i32 %num, 4 ; CHECK-NEXT: --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4) ; CHECK-NEXT: %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ] -; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable } +; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable } ; CHECK-NEXT: %inc = add nuw nsw i32 %i.010, 1 ; CHECK-NEXT: --> {1,+,1}<%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable } ; CHECK-NEXT: Determining loop execution counts for: @test_trip_multiple_4_sgt_5_order_swapped -; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + %num) ; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is 2147483646 -; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + %num) -; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num) ; CHECK-NEXT: Predicates: ; CHECK: Loop %for.body: Trip multiple is 4 ; @@ -294,14 +294,14 @@ ; CHECK-NEXT: %u = urem i32 %num, 4 ; CHECK-NEXT: --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4) ; CHECK-NEXT: %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ] -; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable } +; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable } ; CHECK-NEXT: %inc = add nuw nsw i32 %i.010, 1 ; CHECK-NEXT: --> {1,+,1}<%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable } ; CHECK-NEXT: Determining loop execution counts for: @test_trip_multiple_4_sge_5 -; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + %num) ; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is 2147483646 -; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + %num) -; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num) ; CHECK-NEXT: Predicates: ; CHECK: Loop %for.body: Trip multiple is 4 ; @@ -329,14 +329,14 @@ ; CHECK-NEXT: %u = urem i32 %num, 4 ; CHECK-NEXT: --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4) ; CHECK-NEXT: %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ] -; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable } +; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,2147483647) S: [0,2147483647) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable } ; CHECK-NEXT: %inc = add nuw nsw i32 %i.010, 1 ; CHECK-NEXT: --> {1,+,1}<%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable } ; CHECK-NEXT: Determining loop execution counts for: @test_trip_multiple_4_sge_5_order_swapped -; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + %num) ; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is 2147483646 -; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + %num) -; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num) ; CHECK-NEXT: Predicates: ; CHECK: Loop %for.body: Trip multiple is 4 ; @@ -400,14 +400,14 @@ ; CHECK-NEXT: %u = urem i32 %num, 4 ; CHECK-NEXT: --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4) ; CHECK-NEXT: %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ] -; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable } +; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,58999) S: [0,58999) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable } ; CHECK-NEXT: %inc = add nuw nsw i32 %i.010, 1 -; CHECK-NEXT: --> {1,+,1}<%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable } +; CHECK-NEXT: --> {1,+,1}<%for.body> U: [1,59000) S: [1,59000) Exits: %num LoopDispositions: { %for.body: Computable } ; CHECK-NEXT: Determining loop execution counts for: @test_trip_multiple_4_upper_lower_bounds -; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + %num) -; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is -2 -; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + %num) -; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is 58998 +; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num) ; CHECK-NEXT: Predicates: ; CHECK: Loop %for.body: Trip multiple is 4 ; @@ -437,14 +437,14 @@ ; CHECK-NEXT: %u = urem i32 %num, 4 ; CHECK-NEXT: --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4) ; CHECK-NEXT: %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ] -; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable } +; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,58999) S: [0,58999) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable } ; CHECK-NEXT: %inc = add nuw nsw i32 %i.010, 1 -; CHECK-NEXT: --> {1,+,1}<%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable } +; CHECK-NEXT: --> {1,+,1}<%for.body> U: [1,59000) S: [1,59000) Exits: %num LoopDispositions: { %for.body: Computable } ; CHECK-NEXT: Determining loop execution counts for: @test_trip_multiple_4_upper_lower_bounds_swapped1 -; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + %num) -; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is -2 -; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + %num) -; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is 58998 +; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num) ; CHECK-NEXT: Predicates: ; CHECK: Loop %for.body: Trip multiple is 4 ; @@ -474,14 +474,14 @@ ; CHECK-NEXT: %u = urem i32 %num, 4 ; CHECK-NEXT: --> (zext i2 (trunc i32 %num to i2) to i32) U: [0,4) S: [0,4) ; CHECK-NEXT: %i.010 = phi i32 [ 0, %entry ], [ %inc, %for.body ] -; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,-2147483648) S: [0,-2147483648) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable } +; CHECK-NEXT: --> {0,+,1}<%for.body> U: [0,58999) S: [0,58999) Exits: (-1 + %num) LoopDispositions: { %for.body: Computable } ; CHECK-NEXT: %inc = add nuw nsw i32 %i.010, 1 -; CHECK-NEXT: --> {1,+,1}<%for.body> U: [1,-2147483648) S: [1,-2147483648) Exits: %num LoopDispositions: { %for.body: Computable } +; CHECK-NEXT: --> {1,+,1}<%for.body> U: [1,59000) S: [1,59000) Exits: %num LoopDispositions: { %for.body: Computable } ; CHECK-NEXT: Determining loop execution counts for: @test_trip_multiple_4_upper_lower_bounds_swapped2 -; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + %num) -; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is -2 -; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + %num) -; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is 58998 +; CHECK-NEXT: Loop %for.body: symbolic max backedge-taken count is (-1 + %num) +; CHECK-NEXT: Loop %for.body: Predicated backedge-taken count is (-1 + %num) ; CHECK-NEXT: Predicates: ; CHECK: Loop %for.body: Trip multiple is 4 ; Index: llvm/test/Transforms/IndVarSimplify/invalidate-modified-lcssa-phi.ll =================================================================== --- llvm/test/Transforms/IndVarSimplify/invalidate-modified-lcssa-phi.ll +++ llvm/test/Transforms/IndVarSimplify/invalidate-modified-lcssa-phi.ll @@ -169,7 +169,7 @@ ; CHECK-NEXT: br label [[INNER:%.*]] ; CHECK: inner: ; CHECK-NEXT: store i16 0, ptr [[DST:%.*]], align 1 -; CHECK-NEXT: br i1 false, label [[INNER]], label [[OUTER_LATCH]] +; CHECK-NEXT: br label [[OUTER_LATCH]] ; CHECK: outer.latch: ; CHECK-NEXT: [[LCSSA]] = phi i32 [ [[XOR]], [[INNER]] ] ; CHECK-NEXT: br i1 [[C_0:%.*]], label [[OUTER_HEADER]], label [[EXIT:%.*]] Index: llvm/unittests/Analysis/ScalarEvolutionTest.cpp =================================================================== --- llvm/unittests/Analysis/ScalarEvolutionTest.cpp +++ llvm/unittests/Analysis/ScalarEvolutionTest.cpp @@ -1581,11 +1581,10 @@ runWithSE(*M, "test", [](Function &F, LoopInfo &LI, ScalarEvolution &SE) { auto *TCScev = SE.getSCEV(getArgByName(F, "num")); auto *ApplyLoopGuardsTC = SE.applyLoopGuards(TCScev, *LI.begin()); - // Assert that the new TC is (4 * ((4 umax %num) /u 4)) + // Assert that the new TC is (4 * (%num /u 4)), We can deduce %num >= 4 with llvm.assume APInt Four(32, 4); auto *Constant4 = SE.getConstant(Four); - auto *Max = SE.getUMaxExpr(TCScev, Constant4); - auto *Mul = SE.getMulExpr(SE.getUDivExpr(Max, Constant4), Constant4); + auto *Mul = SE.getMulExpr(SE.getUDivExpr(TCScev, Constant4), Constant4); ASSERT_TRUE(Mul == ApplyLoopGuardsTC); }); } Index: llvm/unittests/Analysis/ValueTrackingTest.cpp =================================================================== --- llvm/unittests/Analysis/ValueTrackingTest.cpp +++ llvm/unittests/Analysis/ValueTrackingTest.cpp @@ -2889,7 +2889,8 @@ AssumptionCache AC(*F); Value *Stride = &*F->arg_begin(); ConstantRange CR1 = computeConstantRange(Stride, false, true, &AC, nullptr); - EXPECT_TRUE(CR1.isFullSet()); + EXPECT_EQ(5, CR1.getLower()); + EXPECT_EQ(10, CR1.getUpper()); Instruction *I = &findInstructionByName(F, "stride.plus.one"); ConstantRange CR2 = computeConstantRange(Stride, false, true, &AC, I); @@ -2961,7 +2962,7 @@ Value *Stride = &*F->arg_begin(); Instruction *GT2 = &findInstructionByName(F, "gt.2"); ConstantRange CR = computeConstantRange(Stride, false, true, &AC, GT2); - EXPECT_EQ(5, CR.getLower()); + EXPECT_EQ(50, CR.getLower()); EXPECT_EQ(0, CR.getUpper()); Instruction *I = &findInstructionByName(F, "stride.plus.one");