uint64_t Align = U->getValue()->getPointerAlignment(DL).value();
uint64_t Rem = MaxVal.urem(Align);
MaxVal -= APInt(BitWidth, Rem);
+ APInt MinVal = APInt::getZero(BitWidth);
+ if (llvm::isKnownNonZero(V, DL))
+ MinVal = Align;
ConservativeResult = ConservativeResult.intersectWith(
- {ConservativeResult.getUnsignedMin(), MaxVal + 1}, RangeType);
+ {MinVal, MaxVal + 1}, RangeType);
}
}
; CHECK-LABEL: 'alloca_non_null'
; CHECK-NEXT: Classifying expressions for: @alloca_non_null
; CHECK-NEXT: %alloca = alloca i32, align 4
-; CHECK-NEXT: --> %alloca U: [0,-7) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT: --> %alloca U: [4,-7) S: [-9223372036854775808,9223372036854775805)
; CHECK-NEXT: %int = ptrtoint ptr %alloca to i64
-; CHECK-NEXT: --> (ptrtoint ptr %alloca to i64) U: [0,-7) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT: --> (ptrtoint ptr %alloca to i64) U: [4,-7) S: [-9223372036854775808,9223372036854775805)
; CHECK-NEXT: Determining loop execution counts for: @alloca_non_null
;
%alloca = alloca i32, align 4
; CHECK-LABEL: 'alloca_icmp_null_exit_count'
; CHECK-NEXT: Classifying expressions for: @alloca_icmp_null_exit_count
; CHECK-NEXT: %alloca = alloca [3 x i32], align 4
-; CHECK-NEXT: --> %alloca U: [0,-15) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT: --> %alloca U: [4,-15) S: [-9223372036854775808,9223372036854775805)
; CHECK-NEXT: %alloca.end = getelementptr inbounds i32, ptr %alloca, i64 3
-; CHECK-NEXT: --> (12 + %alloca)<nuw> U: [12,-3) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT: --> (12 + %alloca)<nuw> U: [16,-3) S: [-9223372036854775808,9223372036854775805)
; CHECK-NEXT: %ptr = phi ptr [ %ptr.next, %loop ], [ %alloca, %entry ]
-; CHECK-NEXT: --> {%alloca,+,4}<nuw><%loop> U: [0,-7) S: [-9223372036854775808,9223372036854775805) Exits: ((4 * (2 umin ((-4 + (-1 * (ptrtoint ptr %alloca to i64))) /u 4)))<nuw><nsw> + %alloca) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: --> {%alloca,+,4}<nuw><%loop> U: [4,-7) S: [-9223372036854775808,9223372036854775805) Exits: (8 + %alloca)<nuw> LoopDispositions: { %loop: Computable }
; CHECK-NEXT: %ptr.next = getelementptr i32, ptr %ptr, i64 1
-; CHECK-NEXT: --> {(4 + %alloca)<nuw>,+,4}<nuw><%loop> U: [4,-3) S: [-9223372036854775808,9223372036854775805) Exits: (4 + (4 * (2 umin ((-4 + (-1 * (ptrtoint ptr %alloca to i64))) /u 4)))<nuw><nsw> + %alloca) LoopDispositions: { %loop: Computable }
+; CHECK-NEXT: --> {(4 + %alloca)<nuw>,+,4}<nuw><%loop> U: [8,-3) S: [-9223372036854775808,9223372036854775805) Exits: (12 + %alloca)<nuw> LoopDispositions: { %loop: Computable }
; CHECK-NEXT: %and = and i1 %cmp1, %cmp2
; CHECK-NEXT: --> (%cmp2 umin %cmp1) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
; CHECK-NEXT: Determining loop execution counts for: @alloca_icmp_null_exit_count
-; CHECK-NEXT: Loop %loop: backedge-taken count is (2 umin ((-4 + (-1 * (ptrtoint ptr %alloca to i64))) /u 4))
+; CHECK-NEXT: Loop %loop: backedge-taken count is 2
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is 2
-; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is (2 umin ((-4 + (-1 * (ptrtoint ptr %alloca to i64))) /u 4))
-; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is (2 umin ((-4 + (-1 * (ptrtoint ptr %alloca to i64))) /u 4))
+; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is 2
+; CHECK-NEXT: Loop %loop: Predicated backedge-taken count is 2
; CHECK-NEXT: Predicates:
-; CHECK: Loop %loop: Trip multiple is 1
+; CHECK: Loop %loop: Trip multiple is 3
;
entry:
%alloca = alloca [3 x i32], align 4
; CHECK-NEXT: %idxprom20 = zext i32 %storemerge1921 to i64
; CHECK-NEXT: --> (zext i32 {3,+,-1}<nsw><%for.cond6> to i64) U: [3,4) S: [3,4) Exits: <<Unknown>> LoopDispositions: { %for.cond6: Computable, %outer.loop: Variant }
; CHECK-NEXT: %arrayidx7 = getelementptr inbounds [1 x [4 x i16]], ptr @__const.f.g, i64 0, i64 0, i64 %idxprom20
-; CHECK-NEXT: --> ((2 * (zext i32 {3,+,-1}<nsw><%for.cond6> to i64))<nuw><nsw> + @__const.f.g)<nuw> U: [6,-3) S: [-9223372036854775808,9223372036854775807) Exits: <<Unknown>> LoopDispositions: { %for.cond6: Computable, %outer.loop: Variant }
+; CHECK-NEXT: --> ((2 * (zext i32 {3,+,-1}<nsw><%for.cond6> to i64))<nuw><nsw> + @__const.f.g)<nuw> U: [8,-3) S: [-9223372036854775808,9223372036854775807) Exits: <<Unknown>> LoopDispositions: { %for.cond6: Computable, %outer.loop: Variant }
; CHECK-NEXT: %i = load i16, ptr %arrayidx7, align 2
; CHECK-NEXT: --> %i U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.cond6: Variant, %outer.loop: Variant }
; CHECK-NEXT: %storemerge1822.lcssa.ph = phi i32 [ 0, %for.cond6 ]
; CHECK-NEXT: %idxprom20.3 = zext i32 %storemerge1921.3 to i64
; CHECK-NEXT: --> (zext i32 {3,+,-1}<nsw><%inner.loop> to i64) U: [3,4) S: [3,4) Exits: <<Unknown>> LoopDispositions: { %inner.loop: Computable, %outer.loop: Variant }
; CHECK-NEXT: %arrayidx7.3 = getelementptr inbounds [1 x [4 x i16]], ptr @__const.f.g, i64 0, i64 0, i64 %idxprom20.3
-; CHECK-NEXT: --> ((2 * (zext i32 {3,+,-1}<nsw><%inner.loop> to i64))<nuw><nsw> + @__const.f.g)<nuw> U: [6,-3) S: [-9223372036854775808,9223372036854775807) Exits: <<Unknown>> LoopDispositions: { %inner.loop: Computable, %outer.loop: Variant }
+; CHECK-NEXT: --> ((2 * (zext i32 {3,+,-1}<nsw><%inner.loop> to i64))<nuw><nsw> + @__const.f.g)<nuw> U: [8,-3) S: [-9223372036854775808,9223372036854775807) Exits: <<Unknown>> LoopDispositions: { %inner.loop: Computable, %outer.loop: Variant }
; CHECK-NEXT: %i7 = load i16, ptr %arrayidx7.3, align 2
; CHECK-NEXT: --> %i7 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %inner.loop: Variant, %outer.loop: Variant }
; CHECK-NEXT: %i8 = load volatile i32, ptr @b, align 4
; CHECK-NEXT: %i.03 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.body> U: [0,50) S: [0,50) Exits: 49 LoopDispositions: { %for.body: Computable }
; CHECK-NEXT: %arrayidx = getelementptr inbounds [50 x i32], ptr @arr1, i32 0, i32 %i.03
-; CHECK-NEXT: --> {@arr1,+,4}<nuw><%for.body> U: [0,-7) S: [-2147483648,2147483645) Exits: (196 + @arr1)<nuw> LoopDispositions: { %for.body: Computable }
+; CHECK-NEXT: --> {@arr1,+,4}<nuw><%for.body> U: [4,-7) S: [-2147483648,2147483645) Exits: (196 + @arr1)<nuw> LoopDispositions: { %for.body: Computable }
; CHECK-NEXT: %0 = load i32, ptr %arrayidx, align 4
; CHECK-NEXT: --> %0 U: full-set S: full-set Exits: 50 LoopDispositions: { %for.body: Variant }
; CHECK-NEXT: %arrayidx1 = getelementptr inbounds [50 x i32], ptr @arr2, i32 0, i32 %i.03
-; CHECK-NEXT: --> {@arr2,+,4}<nuw><%for.body> U: [0,-7) S: [-2147483648,2147483645) Exits: (196 + @arr2)<nuw> LoopDispositions: { %for.body: Computable }
+; CHECK-NEXT: --> {@arr2,+,4}<nuw><%for.body> U: [4,-7) S: [-2147483648,2147483645) Exits: (196 + @arr2)<nuw> LoopDispositions: { %for.body: Computable }
; CHECK-NEXT: %1 = load i32, ptr %arrayidx1, align 4
; CHECK-NEXT: --> %1 U: full-set S: full-set Exits: 0 LoopDispositions: { %for.body: Variant }
; CHECK-NEXT: %add = add i32 %0, %sum.04
; CHECK-LABEL: 'test4'
; CHECK-NEXT: Classifying expressions for: @test4
; CHECK-NEXT: %array = alloca [10 x i32], align 4
-; CHECK-NEXT: --> %array U: [0,-43) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT: --> %array U: [4,-43) S: [-9223372036854775808,9223372036854775805)
; CHECK-NEXT: %index = phi i32 [ %inc5, %for.body ], [ %arg, %entry ]
; CHECK-NEXT: --> {%arg,+,1}<nsw><%for.body> U: full-set S: full-set Exits: (-1 + (10 smax (1 + %arg)<nsw>))<nsw> LoopDispositions: { %for.body: Computable }
; CHECK-NEXT: %sub = add nsw i32 %index, -2
; CHECK-LABEL: 'ptrtoint_align_2_size_4_add_5'
; CHECK-NEXT: Classifying expressions for: @ptrtoint_align_2_size_4_add_5
; CHECK-NEXT: %add = add i64 ptrtoint (ptr @glob.i32.align2 to i64), 5
-; CHECK-NEXT: --> (5 + (ptrtoint ptr @glob.i32.align2 to i64))<nuw> U: [5,0) S: [5,0)
+; CHECK-NEXT: --> (5 + (ptrtoint ptr @glob.i32.align2 to i64))<nuw> U: [7,0) S: [5,0)
; CHECK-NEXT: Determining loop execution counts for: @ptrtoint_align_2_size_4_add_5
;
entry:
; CHECK-LABEL: 'ptrtoint_align_8_size_4_add_7'
; CHECK-NEXT: Classifying expressions for: @ptrtoint_align_8_size_4_add_7
; CHECK-NEXT: %add = add i64 ptrtoint (ptr @glob.i32.align8 to i64), 7
-; CHECK-NEXT: --> (7 + (ptrtoint ptr @glob.i32.align8 to i64))<nuw><nsw> U: [7,0) S: [-9223372036854775801,-9223372036854775808)
+; CHECK-NEXT: --> (7 + (ptrtoint ptr @glob.i32.align8 to i64))<nuw><nsw> U: [15,0) S: [-9223372036854775801,-9223372036854775808)
; CHECK-NEXT: Determining loop execution counts for: @ptrtoint_align_8_size_4_add_7
;
entry:
; CHECK-LABEL: 'ptrtoint_align_16_size_4_add_15'
; CHECK-NEXT: Classifying expressions for: @ptrtoint_align_16_size_4_add_15
; CHECK-NEXT: %add = add i64 ptrtoint (ptr @glob.i32.align16 to i64), 15
-; CHECK-NEXT: --> (15 + (ptrtoint ptr @glob.i32.align16 to i64))<nuw><nsw> U: [15,0) S: [-9223372036854775793,-9223372036854775808)
+; CHECK-NEXT: --> (15 + (ptrtoint ptr @glob.i32.align16 to i64))<nuw><nsw> U: [31,0) S: [-9223372036854775793,-9223372036854775808)
; CHECK-NEXT: Determining loop execution counts for: @ptrtoint_align_16_size_4_add_15
;
entry:
; CHECK-LABEL: 'ptrtoint_align_16_size_16_add_16'
; CHECK-NEXT: Classifying expressions for: @ptrtoint_align_16_size_16_add_16
; CHECK-NEXT: %add = add i64 ptrtoint (ptr @array4xi32 to i64), 16
-; CHECK-NEXT: --> (16 + (ptrtoint ptr @array4xi32 to i64))<nuw> U: [16,-15) S: [-9223372036854775808,9223372036854775793)
+; CHECK-NEXT: --> (16 + (ptrtoint ptr @array4xi32 to i64))<nuw> U: [32,-15) S: [-9223372036854775808,9223372036854775793)
; CHECK-NEXT: Determining loop execution counts for: @ptrtoint_align_16_size_16_add_16
;
entry:
; CHECK-LABEL: 'ptrtoint_align_16_size_16_add_31'
; CHECK-NEXT: Classifying expressions for: @ptrtoint_align_16_size_16_add_31
; CHECK-NEXT: %add = add i64 ptrtoint (ptr @array4xi32 to i64), 31
-; CHECK-NEXT: --> (31 + (ptrtoint ptr @array4xi32 to i64))<nuw> U: [31,0) S: [31,0)
+; CHECK-NEXT: --> (31 + (ptrtoint ptr @array4xi32 to i64))<nuw> U: [47,0) S: [31,0)
; CHECK-NEXT: Determining loop execution counts for: @ptrtoint_align_16_size_16_add_31
;
entry:
; CHECK-LABEL: 'ptrtoint_align_16_size_16_add_33'
; CHECK-NEXT: Classifying expressions for: @ptrtoint_align_16_size_16_add_33
; CHECK-NEXT: %add = add i64 ptrtoint (ptr @array4xi32 to i64), 33
-; CHECK-NEXT: --> (33 + (ptrtoint ptr @array4xi32 to i64)) U: [33,2) S: [-9223372036854775775,-9223372036854775790)
+; CHECK-NEXT: --> (33 + (ptrtoint ptr @array4xi32 to i64)) U: [49,2) S: [-9223372036854775775,-9223372036854775790)
; CHECK-NEXT: Determining loop execution counts for: @ptrtoint_align_16_size_16_add_33
;
entry:
; CHECK-LABEL: 'ptrtoint_align_16_size_16_add_16_umax_sub'
; CHECK-NEXT: Classifying expressions for: @ptrtoint_align_16_size_16_add_16_umax_sub
; CHECK-NEXT: %add.16 = add i64 ptrtoint (ptr @array4xi32 to i64), 16
-; CHECK-NEXT: --> (16 + (ptrtoint ptr @array4xi32 to i64))<nuw> U: [16,-15) S: [-9223372036854775808,9223372036854775793)
+; CHECK-NEXT: --> (16 + (ptrtoint ptr @array4xi32 to i64))<nuw> U: [32,-15) S: [-9223372036854775808,9223372036854775793)
; CHECK-NEXT: %umax = call i64 @llvm.umax.i64(i64 ptrtoint (ptr @array4xi32 to i64), i64 %add.16)
-; CHECK-NEXT: --> (16 + (ptrtoint ptr @array4xi32 to i64))<nuw> U: [16,-15) S: [-9223372036854775808,9223372036854775793)
+; CHECK-NEXT: --> (16 + (ptrtoint ptr @array4xi32 to i64))<nuw> U: [32,-15) S: [-9223372036854775808,9223372036854775793)
; CHECK-NEXT: %add = add i64 %umax, 16
; CHECK-NEXT: --> (32 + (ptrtoint ptr @array4xi32 to i64)) U: [0,-15) S: [-9223372036854775808,9223372036854775793)
; CHECK-NEXT: %sub = sub i64 %add, ptrtoint (ptr @array4xi32 to i64)
; CHECK-LABEL: 'ptrtoint_align_16_size_16_add_31_umax_sub'
; CHECK-NEXT: Classifying expressions for: @ptrtoint_align_16_size_16_add_31_umax_sub
; CHECK-NEXT: %add.31 = add i64 ptrtoint (ptr @array4xi32 to i64), 31
-; CHECK-NEXT: --> (31 + (ptrtoint ptr @array4xi32 to i64))<nuw> U: [31,0) S: [31,0)
+; CHECK-NEXT: --> (31 + (ptrtoint ptr @array4xi32 to i64))<nuw> U: [47,0) S: [31,0)
; CHECK-NEXT: %umax = call i64 @llvm.umax.i64(i64 ptrtoint (ptr @array4xi32 to i64), i64 %add.31)
-; CHECK-NEXT: --> (31 + (ptrtoint ptr @array4xi32 to i64))<nuw> U: [31,0) S: [31,0)
+; CHECK-NEXT: --> (31 + (ptrtoint ptr @array4xi32 to i64))<nuw> U: [47,0) S: [31,0)
; CHECK-NEXT: %add = add i64 %umax, 16
-; CHECK-NEXT: --> (47 + (ptrtoint ptr @array4xi32 to i64)) U: [47,16) S: [-9223372036854775761,-9223372036854775776)
+; CHECK-NEXT: --> (47 + (ptrtoint ptr @array4xi32 to i64)) U: [63,16) S: [-9223372036854775761,-9223372036854775776)
; CHECK-NEXT: %sub = sub i64 %add, ptrtoint (ptr @array4xi32 to i64)
; CHECK-NEXT: --> 47 U: [47,48) S: [47,48)
; CHECK-NEXT: Determining loop execution counts for: @ptrtoint_align_16_size_16_add_31_umax_sub
; CHECK-NEXT: %add.32 = add i64 ptrtoint (ptr @array4xi32 to i64), 32
; CHECK-NEXT: --> (32 + (ptrtoint ptr @array4xi32 to i64)) U: [0,-15) S: [-9223372036854775808,9223372036854775793)
; CHECK-NEXT: %umax = call i64 @llvm.umax.i64(i64 ptrtoint (ptr @array4xi32 to i64), i64 %add.32)
-; CHECK-NEXT: --> ((32 + (ptrtoint ptr @array4xi32 to i64)) umax (ptrtoint ptr @array4xi32 to i64)) U: [0,-15) S: [-9223372036854775808,9223372036854775793)
+; CHECK-NEXT: --> ((32 + (ptrtoint ptr @array4xi32 to i64)) umax (ptrtoint ptr @array4xi32 to i64)) U: [16,-15) S: [-9223372036854775808,9223372036854775793)
; CHECK-NEXT: %add = add i64 %umax, 16
; CHECK-NEXT: --> (16 + ((32 + (ptrtoint ptr @array4xi32 to i64)) umax (ptrtoint ptr @array4xi32 to i64))) U: [0,-15) S: [-9223372036854775808,9223372036854775793)
; CHECK-NEXT: %sub = sub i64 %add, ptrtoint (ptr @array4xi32 to i64)
; CHECK-LABEL: '_Z4loopi'
; CHECK-NEXT: Classifying expressions for: @_Z4loopi
; CHECK-NEXT: %storage = alloca [2 x i32], align 4
-; CHECK-NEXT: --> %storage U: [0,-11) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT: --> %storage U: [4,-11) S: [-9223372036854775808,9223372036854775805)
; CHECK-NEXT: %0 = bitcast ptr %storage to ptr
-; CHECK-NEXT: --> %storage U: [0,-11) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT: --> %storage U: [4,-11) S: [-9223372036854775808,9223372036854775805)
; CHECK-NEXT: %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.cond> U: [0,-2147483648) S: [0,-2147483648) Exits: %width LoopDispositions: { %for.cond: Computable }
; CHECK-NEXT: %rem = sdiv i32 %i.0, 2
; CHECK-LABEL: '_Z4loopi'
; CHECK-NEXT: Classifying expressions for: @_Z4loopi
; CHECK-NEXT: %storage = alloca [2 x i32], align 4
-; CHECK-NEXT: --> %storage U: [0,-11) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT: --> %storage U: [4,-11) S: [-9223372036854775808,9223372036854775805)
; CHECK-NEXT: %0 = bitcast ptr %storage to ptr
-; CHECK-NEXT: --> %storage U: [0,-11) S: [-9223372036854775808,9223372036854775805)
+; CHECK-NEXT: --> %storage U: [4,-11) S: [-9223372036854775808,9223372036854775805)
; CHECK-NEXT: %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%for.cond> U: [0,-2147483648) S: [0,-2147483648) Exits: %width LoopDispositions: { %for.cond: Computable }
; CHECK-NEXT: %rem = srem i32 %i.0, 2
; CHECK-NEXT: %idxprom = sext i32 %rem to i64
; CHECK-NEXT: --> (zext i1 {false,+,true}<%for.cond> to i64) U: [0,2) S: [0,2) Exits: (zext i1 (trunc i32 %width to i1) to i64) LoopDispositions: { %for.cond: Computable }
; CHECK-NEXT: %arrayidx = getelementptr inbounds [2 x i32], ptr %storage, i64 0, i64 %idxprom
-; CHECK-NEXT: --> ((4 * (zext i1 {false,+,true}<%for.cond> to i64))<nuw><nsw> + %storage) U: [0,-7) S: [-9223372036854775808,9223372036854775805) Exits: ((4 * (zext i1 (trunc i32 %width to i1) to i64))<nuw><nsw> + %storage) LoopDispositions: { %for.cond: Computable }
+; CHECK-NEXT: --> ((4 * (zext i1 {false,+,true}<%for.cond> to i64))<nuw><nsw> + %storage) U: [4,-7) S: [-9223372036854775808,9223372036854775805) Exits: ((4 * (zext i1 (trunc i32 %width to i1) to i64))<nuw><nsw> + %storage) LoopDispositions: { %for.cond: Computable }
; CHECK-NEXT: %1 = load i32, ptr %arrayidx, align 4
; CHECK-NEXT: --> %1 U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %for.cond: Variant }
; CHECK-NEXT: %call = call i32 @_Z3adji(i32 %1)