aboutsummaryrefslogtreecommitdiffstats
path: root/test/Analysis/ScalarEvolution
diff options
context:
space:
mode:
Diffstat (limited to 'test/Analysis/ScalarEvolution')
-rw-r--r--test/Analysis/ScalarEvolution/incorrect-nsw.ll26
-rw-r--r--test/Analysis/ScalarEvolution/infer-prestart-no-wrap.ll101
-rw-r--r--test/Analysis/ScalarEvolution/load-with-range-metadata.ll2
-rw-r--r--test/Analysis/ScalarEvolution/min-max-exprs.ll53
-rw-r--r--test/Analysis/ScalarEvolution/nw-sub-is-not-nw-add.ll41
-rw-r--r--test/Analysis/ScalarEvolution/pr22179.ll28
-rw-r--r--test/Analysis/ScalarEvolution/pr22641.ll25
-rw-r--r--test/Analysis/ScalarEvolution/pr22674.ll101
-rw-r--r--test/Analysis/ScalarEvolution/scev-expander-incorrect-nowrap.ll30
-rw-r--r--test/Analysis/ScalarEvolution/scev-prestart-nowrap.ll82
-rw-r--r--test/Analysis/ScalarEvolution/zext-signed-addrec.ll2
11 files changed, 489 insertions, 2 deletions
diff --git a/test/Analysis/ScalarEvolution/incorrect-nsw.ll b/test/Analysis/ScalarEvolution/incorrect-nsw.ll
new file mode 100644
index 0000000..dd981c4
--- /dev/null
+++ b/test/Analysis/ScalarEvolution/incorrect-nsw.ll
@@ -0,0 +1,26 @@
+; RUN: opt -analyze -scalar-evolution -scalar-evolution < %s | FileCheck %s
+
+define void @bad.nsw() {
+; CHECK-LABEL: Classifying expressions for: @bad.nsw
+; CHECK-LABEL: Classifying expressions for: @bad.nsw
+ entry:
+ br label %loop
+
+ loop:
+ %i = phi i8 [ -1, %entry ], [ %i.inc, %loop ]
+; CHECK: %i = phi i8 [ -1, %entry ], [ %i.inc, %loop ]
+; CHECK-NEXT: --> {-1,+,-128}<nw><%loop>
+; CHECK-NOT: --> {-1,+,-128}<nsw><%loop>
+
+ %counter = phi i8 [ 0, %entry ], [ %counter.inc, %loop ]
+
+ %i.inc = add i8 %i, -128
+ %i.sext = sext i8 %i to i16
+
+ %counter.inc = add i8 %counter, 1
+ %continue = icmp eq i8 %counter, 1
+ br i1 %continue, label %exit, label %loop
+
+ exit:
+ ret void
+}
diff --git a/test/Analysis/ScalarEvolution/infer-prestart-no-wrap.ll b/test/Analysis/ScalarEvolution/infer-prestart-no-wrap.ll
new file mode 100644
index 0000000..c9689f7
--- /dev/null
+++ b/test/Analysis/ScalarEvolution/infer-prestart-no-wrap.ll
@@ -0,0 +1,101 @@
+; ; RUN: opt -analyze -scalar-evolution < %s | FileCheck %s
+
+define void @infer.sext.0(i1* %c, i32 %start) {
+; CHECK-LABEL: Classifying expressions for: @infer.sext.0
+ entry:
+ br label %loop
+
+ loop:
+ %counter = phi i32 [ 0, %entry ], [ %counter.inc, %loop ]
+ %idx = phi i32 [ %start, %entry ], [ %idx.inc, %loop ]
+ %idx.inc = add nsw i32 %idx, 1
+ %idx.inc.sext = sext i32 %idx.inc to i64
+; CHECK: %idx.inc.sext = sext i32 %idx.inc to i64
+; CHECK-NEXT: --> {(1 + (sext i32 %start to i64)),+,1}<nsw><%loop>
+ %condition = icmp eq i32 %counter, 1
+ %counter.inc = add i32 %counter, 1
+ br i1 %condition, label %exit, label %loop
+
+ exit:
+ ret void
+}
+
+define void @infer.zext.0(i1* %c, i32 %start) {
+; CHECK-LABEL: Classifying expressions for: @infer.zext.0
+ entry:
+ br label %loop
+
+ loop:
+ %counter = phi i32 [ 0, %entry ], [ %counter.inc, %loop ]
+ %idx = phi i32 [ %start, %entry ], [ %idx.inc, %loop ]
+ %idx.inc = add nuw i32 %idx, 1
+ %idx.inc.sext = zext i32 %idx.inc to i64
+; CHECK: %idx.inc.sext = zext i32 %idx.inc to i64
+; CHECK-NEXT: --> {(1 + (zext i32 %start to i64)),+,1}<nuw><%loop>
+ %condition = icmp eq i32 %counter, 1
+ %counter.inc = add i32 %counter, 1
+ br i1 %condition, label %exit, label %loop
+
+ exit:
+ ret void
+}
+
+define void @infer.sext.1(i32 %start, i1* %c) {
+; CHECK-LABEL: Classifying expressions for: @infer.sext.1
+ entry:
+ %start.mul = mul i32 %start, 4
+ %start.real = add i32 %start.mul, 2
+ br label %loop
+
+ loop:
+ %idx = phi i32 [ %start.real, %entry ], [ %idx.inc, %loop ]
+ %idx.sext = sext i32 %idx to i64
+; CHECK: %idx.sext = sext i32 %idx to i64
+; CHECK-NEXT: --> {(2 + (sext i32 (4 * %start) to i64)),+,2}<nsw><%loop>
+ %idx.inc = add nsw i32 %idx, 2
+ %condition = load i1* %c
+ br i1 %condition, label %exit, label %loop
+
+ exit:
+ ret void
+}
+
+define void @infer.sext.2(i1* %c, i8 %start) {
+; CHECK-LABEL: Classifying expressions for: @infer.sext.2
+ entry:
+ %start.inc = add i8 %start, 1
+ %entry.condition = icmp slt i8 %start, 127
+ br i1 %entry.condition, label %loop, label %exit
+
+ loop:
+ %idx = phi i8 [ %start.inc, %entry ], [ %idx.inc, %loop ]
+ %idx.sext = sext i8 %idx to i16
+; CHECK: %idx.sext = sext i8 %idx to i16
+; CHECK-NEXT: --> {(1 + (sext i8 %start to i16)),+,1}<nsw><%loop>
+ %idx.inc = add nsw i8 %idx, 1
+ %condition = load volatile i1* %c
+ br i1 %condition, label %exit, label %loop
+
+ exit:
+ ret void
+}
+
+define void @infer.zext.1(i1* %c, i8 %start) {
+; CHECK-LABEL: Classifying expressions for: @infer.zext.1
+ entry:
+ %start.inc = add i8 %start, 1
+ %entry.condition = icmp ult i8 %start, 255
+ br i1 %entry.condition, label %loop, label %exit
+
+ loop:
+ %idx = phi i8 [ %start.inc, %entry ], [ %idx.inc, %loop ]
+ %idx.zext = zext i8 %idx to i16
+; CHECK: %idx.zext = zext i8 %idx to i16
+; CHECK-NEXT: --> {(1 + (zext i8 %start to i16)),+,1}<nuw><%loop>
+ %idx.inc = add nuw i8 %idx, 1
+ %condition = load volatile i1* %c
+ br i1 %condition, label %exit, label %loop
+
+ exit:
+ ret void
+}
diff --git a/test/Analysis/ScalarEvolution/load-with-range-metadata.ll b/test/Analysis/ScalarEvolution/load-with-range-metadata.ll
index 2f6dcd0..32c1074 100644
--- a/test/Analysis/ScalarEvolution/load-with-range-metadata.ll
+++ b/test/Analysis/ScalarEvolution/load-with-range-metadata.ll
@@ -34,4 +34,4 @@ define i32 @ult_trip_count_with_range(i32 *%ptr0, i32 *%ptr1) {
ret i32 0
}
-!0 = metadata !{i32 1, i32 100}
+!0 = !{i32 1, i32 100}
diff --git a/test/Analysis/ScalarEvolution/min-max-exprs.ll b/test/Analysis/ScalarEvolution/min-max-exprs.ll
new file mode 100644
index 0000000..3e0a35d
--- /dev/null
+++ b/test/Analysis/ScalarEvolution/min-max-exprs.ll
@@ -0,0 +1,53 @@
+; RUN: opt -scalar-evolution -analyze < %s | FileCheck %s
+;
+; This checks if the min and max expressions are properly recognized by
+; ScalarEvolution even though they the ICmpInst and SelectInst have different
+; types.
+;
+; #define max(a, b) (a > b ? a : b)
+; #define min(a, b) (a < b ? a : b)
+;
+; void f(int *A, int N) {
+; for (int i = 0; i < N; i++) {
+; A[max(0, i - 3)] = A[min(N, i + 3)] * 2;
+; }
+; }
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @f(i32* %A, i32 %N) {
+bb:
+ br label %bb1
+
+bb1: ; preds = %bb2, %bb
+ %i.0 = phi i32 [ 0, %bb ], [ %tmp23, %bb2 ]
+ %i.0.1 = sext i32 %i.0 to i64
+ %tmp = icmp slt i32 %i.0, %N
+ br i1 %tmp, label %bb2, label %bb24
+
+bb2: ; preds = %bb1
+ %tmp3 = add nuw nsw i32 %i.0, 3
+ %tmp4 = icmp slt i32 %tmp3, %N
+ %tmp5 = sext i32 %tmp3 to i64
+ %tmp6 = sext i32 %N to i64
+ %tmp9 = select i1 %tmp4, i64 %tmp5, i64 %tmp6
+; min(N, i+3)
+; CHECK: select i1 %tmp4, i64 %tmp5, i64 %tmp6
+; CHECK-NEXT: --> (-1 + (-1 * ((-1 + (-1 * (sext i32 {3,+,1}<nw><%bb1> to i64))) smax (-1 + (-1 * (sext i32 %N to i64))))))
+ %tmp11 = getelementptr inbounds i32* %A, i64 %tmp9
+ %tmp12 = load i32* %tmp11, align 4
+ %tmp13 = shl nsw i32 %tmp12, 1
+ %tmp14 = icmp sge i32 3, %i.0
+ %tmp17 = add nsw i64 %i.0.1, -3
+ %tmp19 = select i1 %tmp14, i64 0, i64 %tmp17
+; max(0, i - 3)
+; CHECK: select i1 %tmp14, i64 0, i64 %tmp17
+; CHECK-NEXT: --> (-3 + (3 smax {0,+,1}<nuw><nsw><%bb1>))
+ %tmp21 = getelementptr inbounds i32* %A, i64 %tmp19
+ store i32 %tmp13, i32* %tmp21, align 4
+ %tmp23 = add nuw nsw i32 %i.0, 1
+ br label %bb1
+
+bb24: ; preds = %bb1
+ ret void
+}
diff --git a/test/Analysis/ScalarEvolution/nw-sub-is-not-nw-add.ll b/test/Analysis/ScalarEvolution/nw-sub-is-not-nw-add.ll
new file mode 100644
index 0000000..41b07d5
--- /dev/null
+++ b/test/Analysis/ScalarEvolution/nw-sub-is-not-nw-add.ll
@@ -0,0 +1,41 @@
+; RUN: opt -S -indvars < %s | FileCheck %s
+
+; Check that SCEV does not assume sub nuw X Y == add nuw X, -Y
+define void @f(i32* %loc) {
+; CHECK-LABEL: @f
+ entry:
+ br label %loop
+
+ loop:
+ %idx = phi i32 [ 6, %entry ], [ %idx.dec, %loop ]
+ store i32 %idx, i32* %loc
+ %idx.dec = sub nuw i32 %idx, 1
+ %cond = icmp uge i32 %idx.dec, 5
+ br i1 %cond, label %loop, label %exit
+; CHECK-NOT: br i1 true, label %loop, label %exit
+
+ exit:
+ ret void
+}
+
+declare void @use_i1(i1)
+
+; Check that SCEV does not assume sub nsw X Y == add nsw X, -Y
+define void @g(i32 %lim) {
+; CHECK-LABEL: @g
+ entry:
+ br label %loop
+
+ loop:
+ %idx = phi i32 [ -1, %entry ], [ %idx.dec, %loop ]
+ %t = icmp sgt i32 %idx, 0
+; CHECK-NOT: call void @use_i1(i1 false)
+; CHECK: call void @use_i1(i1 %t)
+ call void @use_i1(i1 %t)
+ %idx.dec = sub nsw i32 %idx, -2147483648
+ %cond = icmp eq i32 %idx.dec, %lim
+ br i1 %cond, label %loop, label %exit
+
+ exit:
+ ret void
+}
diff --git a/test/Analysis/ScalarEvolution/pr22179.ll b/test/Analysis/ScalarEvolution/pr22179.ll
new file mode 100644
index 0000000..d9fb510
--- /dev/null
+++ b/test/Analysis/ScalarEvolution/pr22179.ll
@@ -0,0 +1,28 @@
+; RUN: opt -analyze -scalar-evolution < %s | FileCheck %s
+
+%struct.anon = type { i8 }
+%struct.S = type { i32 }
+
+@a = common global %struct.anon zeroinitializer, align 1
+@b = common global %struct.S zeroinitializer, align 4
+
+; Function Attrs: nounwind ssp uwtable
+define i32 @main() {
+; CHECK-LABEL: Classifying expressions for: @main
+ store i8 0, i8* getelementptr inbounds (%struct.anon* @a, i64 0, i32 0), align 1
+ br label %loop
+
+loop:
+ %storemerge1 = phi i8 [ 0, %0 ], [ %inc, %loop ]
+ %m = load volatile i32* getelementptr inbounds (%struct.S* @b, i64 0, i32 0), align 4
+ %inc = add nuw i8 %storemerge1, 1
+; CHECK: %inc = add nuw i8 %storemerge1, 1
+; CHECK-NEXT: --> {1,+,1}<nuw><%loop>
+; CHECK-NOT: --> {1,+,1}<nuw><nsw><%loop>
+ %exitcond = icmp eq i8 %inc, -128
+ br i1 %exitcond, label %exit, label %loop
+
+exit:
+ store i8 -128, i8* getelementptr inbounds (%struct.anon* @a, i64 0, i32 0), align 1
+ ret i32 0
+}
diff --git a/test/Analysis/ScalarEvolution/pr22641.ll b/test/Analysis/ScalarEvolution/pr22641.ll
new file mode 100644
index 0000000..3b55afe
--- /dev/null
+++ b/test/Analysis/ScalarEvolution/pr22641.ll
@@ -0,0 +1,25 @@
+; RUN: opt -analyze -scalar-evolution < %s | FileCheck %s
+
+define i1 @main(i16 %a) {
+; CHECK-LABEL: Classifying expressions for: @main
+entry:
+ br label %body
+
+body:
+ %dec2 = phi i16 [ %a, %entry ], [ %dec, %cond ]
+ %dec = add i16 %dec2, -1
+ %conv2 = zext i16 %dec2 to i32
+ %conv = zext i16 %dec to i32
+; CHECK: %conv = zext i16 %dec to i32
+; CHECK-NEXT: --> {(zext i16 (-1 + %a) to i32),+,65535}<nuw><%body>
+; CHECK-NOT: --> {(65535 + (zext i16 %a to i32)),+,65535}<nuw><%body>
+
+ br label %cond
+
+cond:
+ br i1 false, label %body, label %exit
+
+exit:
+ %ret = icmp ne i32 %conv, 0
+ ret i1 %ret
+}
diff --git a/test/Analysis/ScalarEvolution/pr22674.ll b/test/Analysis/ScalarEvolution/pr22674.ll
new file mode 100644
index 0000000..7defcb9
--- /dev/null
+++ b/test/Analysis/ScalarEvolution/pr22674.ll
@@ -0,0 +1,101 @@
+; RUN: opt -loop-reduce -S %s
+
+
+target datalayout = "e-m:e-p:32:32-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-linux-gnux32"
+
+%"class.llvm::AttributeSetNode.230.2029.3828.6141.6912.7683.8454.9482.9996.10253.18506" = type { %"class.llvm::FoldingSetImpl::Node.1.1801.3600.5913.6684.7455.8226.9254.9768.10025.18505", i32 }
+%"class.llvm::FoldingSetImpl::Node.1.1801.3600.5913.6684.7455.8226.9254.9768.10025.18505" = type { i8* }
+%"struct.std::pair.241.2040.3839.6152.6923.7694.8465.9493.10007.10264.18507" = type { i32, %"class.llvm::AttributeSetNode.230.2029.3828.6141.6912.7683.8454.9482.9996.10253.18506"* }
+%"class.llvm::Attribute.222.2021.3820.6133.6904.7675.8446.9474.9988.10245.18509" = type { %"class.llvm::AttributeImpl.2.1802.3601.5914.6685.7456.8227.9255.9769.10026.18508"* }
+%"class.llvm::AttributeImpl.2.1802.3601.5914.6685.7456.8227.9255.9769.10026.18508" = type <{ i32 (...)**, %"class.llvm::FoldingSetImpl::Node.1.1801.3600.5913.6684.7455.8226.9254.9768.10025.18505", i8, [3 x i8] }>
+
+; Function Attrs: nounwind uwtable
+define void @_ZNK4llvm11AttrBuilder13hasAttributesENS_12AttributeSetEy() #0 align 2 {
+entry:
+ br i1 undef, label %cond.false, label %_ZNK4llvm12AttributeSet11getNumSlotsEv.exit
+
+_ZNK4llvm12AttributeSet11getNumSlotsEv.exit: ; preds = %entry
+ br i1 undef, label %cond.false, label %for.body.lr.ph.for.body.lr.ph.split_crit_edge
+
+for.body.lr.ph.for.body.lr.ph.split_crit_edge: ; preds = %_ZNK4llvm12AttributeSet11getNumSlotsEv.exit
+ br label %land.lhs.true.i
+
+land.lhs.true.i: ; preds = %for.inc, %for.body.lr.ph.for.body.lr.ph.split_crit_edge
+ %I.099 = phi i32 [ 0, %for.body.lr.ph.for.body.lr.ph.split_crit_edge ], [ %inc, %for.inc ]
+ %cmp.i = icmp ugt i32 undef, %I.099
+ br i1 %cmp.i, label %_ZNK4llvm12AttributeSet12getSlotIndexEj.exit, label %cond.false.i.split
+
+cond.false.i.split: ; preds = %land.lhs.true.i
+ unreachable
+
+_ZNK4llvm12AttributeSet12getSlotIndexEj.exit: ; preds = %land.lhs.true.i
+ br i1 undef, label %for.end, label %for.inc
+
+for.inc: ; preds = %_ZNK4llvm12AttributeSet12getSlotIndexEj.exit
+ %inc = add i32 %I.099, 1
+ br i1 undef, label %cond.false, label %land.lhs.true.i
+
+for.end: ; preds = %_ZNK4llvm12AttributeSet12getSlotIndexEj.exit
+ %I.099.lcssa129 = phi i32 [ %I.099, %_ZNK4llvm12AttributeSet12getSlotIndexEj.exit ]
+ br i1 undef, label %cond.false, label %_ZNK4llvm12AttributeSet3endEj.exit
+
+cond.false: ; preds = %for.end, %for.inc, %_ZNK4llvm12AttributeSet11getNumSlotsEv.exit, %entry
+ unreachable
+
+_ZNK4llvm12AttributeSet3endEj.exit: ; preds = %for.end
+ %second.i.i.i = getelementptr inbounds %"struct.std::pair.241.2040.3839.6152.6923.7694.8465.9493.10007.10264.18507"* undef, i32 %I.099.lcssa129, i32 1
+ %0 = load %"class.llvm::AttributeSetNode.230.2029.3828.6141.6912.7683.8454.9482.9996.10253.18506"** %second.i.i.i, align 4, !tbaa !2
+ %NumAttrs.i.i.i = getelementptr inbounds %"class.llvm::AttributeSetNode.230.2029.3828.6141.6912.7683.8454.9482.9996.10253.18506"* %0, i32 0, i32 1
+ %1 = load i32* %NumAttrs.i.i.i, align 4, !tbaa !8
+ %add.ptr.i.i.i55 = getelementptr inbounds %"class.llvm::Attribute.222.2021.3820.6133.6904.7675.8446.9474.9988.10245.18509"* undef, i32 %1
+ br i1 undef, label %return, label %for.body11
+
+for.cond9: ; preds = %_ZNK4llvm9Attribute13getKindAsEnumEv.exit
+ %cmp10 = icmp eq %"class.llvm::Attribute.222.2021.3820.6133.6904.7675.8446.9474.9988.10245.18509"* %incdec.ptr, %add.ptr.i.i.i55
+ br i1 %cmp10, label %return, label %for.body11
+
+for.body11: ; preds = %for.cond9, %_ZNK4llvm12AttributeSet3endEj.exit
+ %I5.096 = phi %"class.llvm::Attribute.222.2021.3820.6133.6904.7675.8446.9474.9988.10245.18509"* [ %incdec.ptr, %for.cond9 ], [ undef, %_ZNK4llvm12AttributeSet3endEj.exit ]
+ %2 = bitcast %"class.llvm::Attribute.222.2021.3820.6133.6904.7675.8446.9474.9988.10245.18509"* %I5.096 to i32*
+ %3 = load i32* %2, align 4, !tbaa !10
+ %tobool.i59 = icmp eq i32 %3, 0
+ br i1 %tobool.i59, label %cond.false21, label %_ZNK4llvm9Attribute15isEnumAttributeEv.exit
+
+_ZNK4llvm9Attribute15isEnumAttributeEv.exit: ; preds = %for.body11
+ switch i8 undef, label %cond.false21 [
+ i8 0, label %_ZNK4llvm9Attribute13getKindAsEnumEv.exit
+ i8 1, label %_ZNK4llvm9Attribute13getKindAsEnumEv.exit
+ i8 2, label %_ZNK4llvm9Attribute15getKindAsStringEv.exit
+ ]
+
+_ZNK4llvm9Attribute13getKindAsEnumEv.exit: ; preds = %_ZNK4llvm9Attribute15isEnumAttributeEv.exit, %_ZNK4llvm9Attribute15isEnumAttributeEv.exit
+ %incdec.ptr = getelementptr inbounds %"class.llvm::Attribute.222.2021.3820.6133.6904.7675.8446.9474.9988.10245.18509"* %I5.096, i32 1
+ br i1 undef, label %for.cond9, label %return
+
+cond.false21: ; preds = %_ZNK4llvm9Attribute15isEnumAttributeEv.exit, %for.body11
+ unreachable
+
+_ZNK4llvm9Attribute15getKindAsStringEv.exit: ; preds = %_ZNK4llvm9Attribute15isEnumAttributeEv.exit
+ unreachable
+
+return: ; preds = %_ZNK4llvm9Attribute13getKindAsEnumEv.exit, %for.cond9, %_ZNK4llvm12AttributeSet3endEj.exit
+ ret void
+}
+
+attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+
+!llvm.module.flags = !{!0}
+!llvm.ident = !{!1}
+
+!0 = !{i32 1, !"PIC Level", i32 2}
+!1 = !{!"clang version 3.7.0 (ssh://llvm@gnu-4.sc.intel.com/export/server/git/llvm/clang 4c31740d4f81614b6d278c7825cfdae5a1c78799) (llvm/llvm.git b693958bd09144aed90312709a7e2ccf7124eb53)"}
+!2 = !{!3, !7, i64 4}
+!3 = !{!"_ZTSSt4pairIjPN4llvm16AttributeSetNodeEE", !4, i64 0, !7, i64 4}
+!4 = !{!"int", !5, i64 0}
+!5 = !{!"omnipotent char", !6, i64 0}
+!6 = !{!"Simple C/C++ TBAA"}
+!7 = !{!"any pointer", !5, i64 0}
+!8 = !{!9, !4, i64 4}
+!9 = !{!"_ZTSN4llvm16AttributeSetNodeE", !4, i64 4}
+!10 = !{!7, !7, i64 0}
diff --git a/test/Analysis/ScalarEvolution/scev-expander-incorrect-nowrap.ll b/test/Analysis/ScalarEvolution/scev-expander-incorrect-nowrap.ll
new file mode 100644
index 0000000..012cad7
--- /dev/null
+++ b/test/Analysis/ScalarEvolution/scev-expander-incorrect-nowrap.ll
@@ -0,0 +1,30 @@
+; RUN: opt -indvars -S < %s | FileCheck %s
+
+declare void @use(i32)
+declare void @use.i8(i8)
+
+define void @f() {
+; CHECK-LABEL: @f
+ entry:
+ br label %loop
+
+ loop:
+; The only use for idx.mirror is to induce an nuw for %idx. It does
+; not induce an nuw for %idx.inc
+ %idx.mirror = phi i8 [ -6, %entry ], [ %idx.mirror.inc, %loop ]
+ %idx = phi i8 [ -5, %entry ], [ %idx.inc, %loop ]
+
+ %idx.sext = sext i8 %idx to i32
+ call void @use(i32 %idx.sext)
+
+ %idx.mirror.inc = add nuw i8 %idx.mirror, 1
+ call void @use.i8(i8 %idx.mirror.inc)
+
+ %idx.inc = add i8 %idx, 1
+; CHECK-NOT: %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
+ %cmp = icmp ugt i8 %idx.inc, 0
+ br i1 %cmp, label %loop, label %exit
+
+ exit:
+ ret void
+}
diff --git a/test/Analysis/ScalarEvolution/scev-prestart-nowrap.ll b/test/Analysis/ScalarEvolution/scev-prestart-nowrap.ll
new file mode 100644
index 0000000..3ca32bd
--- /dev/null
+++ b/test/Analysis/ScalarEvolution/scev-prestart-nowrap.ll
@@ -0,0 +1,82 @@
+; RUN: opt -analyze -scalar-evolution < %s | FileCheck %s
+
+; An example run where SCEV(%postinc)->getStart() may overflow:
+;
+; %start = INT_SMAX
+; %low.limit = INT_SMIN
+; %high.limit = < not used >
+;
+; >> entry:
+; %postinc.start = INT_SMIN
+;
+; >> loop:
+; %idx = %start
+; %postinc = INT_SMIN
+; %postinc.inc = INT_SMIN + 1
+; %postinc.sext = sext(INT_SMIN) = i64 INT32_SMIN
+; %break.early = INT_SMIN `slt` INT_SMIN = false
+; br i1 false, ___, %early.exit
+;
+; >> early.exit:
+; ret i64 INT32_SMIN
+
+
+define i64 @bad.0(i32 %start, i32 %low.limit, i32 %high.limit) {
+; CHECK-LABEL: Classifying expressions for: @bad.0
+ entry:
+ %postinc.start = add i32 %start, 1
+ br label %loop
+
+ loop:
+ %idx = phi i32 [ %start, %entry ], [ %idx.inc, %continue ]
+ %postinc = phi i32 [ %postinc.start, %entry ], [ %postinc.inc, %continue ]
+ %postinc.inc = add nsw i32 %postinc, 1
+ %postinc.sext = sext i32 %postinc to i64
+; CHECK: %postinc.sext = sext i32 %postinc to i64
+; CHECK-NEXT: --> {(sext i32 (1 + %start) to i64),+,1}<nsw><%loop>
+ %break.early = icmp slt i32 %postinc, %low.limit
+ br i1 %break.early, label %continue, label %early.exit
+
+ continue:
+ %idx.inc = add nsw i32 %idx, 1
+ %cmp = icmp slt i32 %idx.inc, %high.limit
+ br i1 %cmp, label %loop, label %exit
+
+ exit:
+ ret i64 0
+
+ early.exit:
+ ret i64 %postinc.sext
+}
+
+define i64 @bad.1(i32 %start, i32 %low.limit, i32 %high.limit, i1* %unknown) {
+; CHECK-LABEL: Classifying expressions for: @bad.1
+ entry:
+ %postinc.start = add i32 %start, 1
+ br label %loop
+
+ loop:
+ %idx = phi i32 [ %start, %entry ], [ %idx.inc, %continue ], [ %idx.inc, %continue.1 ]
+ %postinc = phi i32 [ %postinc.start, %entry ], [ %postinc.inc, %continue ], [ %postinc.inc, %continue.1 ]
+ %postinc.inc = add nsw i32 %postinc, 1
+ %postinc.sext = sext i32 %postinc to i64
+; CHECK: %postinc.sext = sext i32 %postinc to i64
+; CHECK-NEXT: --> {(sext i32 (1 + %start) to i64),+,1}<nsw><%loop>
+ %break.early = icmp slt i32 %postinc, %low.limit
+ br i1 %break.early, label %continue.1, label %early.exit
+
+ continue.1:
+ %cond = load volatile i1* %unknown
+ %idx.inc = add nsw i32 %idx, 1
+ br i1 %cond, label %loop, label %continue
+
+ continue:
+ %cmp = icmp slt i32 %idx.inc, %high.limit
+ br i1 %cmp, label %loop, label %exit
+
+ exit:
+ ret i64 0
+
+ early.exit:
+ ret i64 %postinc.sext
+}
diff --git a/test/Analysis/ScalarEvolution/zext-signed-addrec.ll b/test/Analysis/ScalarEvolution/zext-signed-addrec.ll
index 27aed3b..4369820 100644
--- a/test/Analysis/ScalarEvolution/zext-signed-addrec.ll
+++ b/test/Analysis/ScalarEvolution/zext-signed-addrec.ll
@@ -43,7 +43,7 @@ if.end: ; preds = %if.end, %for.cond1.
%shl = and i32 %conv7, 510
store i32 %shl, i32* @c, align 4
-; CHECK: %lsr.iv.next = add i32 %lsr.iv, -258
+; CHECK: %lsr.iv.next = add nsw i32 %lsr.iv, -258
%dec = add i8 %2, -1
%cmp2 = icmp sgt i8 %dec, -1