1 ;; RUN: opt -S < %s -passes=indvars | FileCheck %s
2 ; RUN: opt -passes=lcssa,loop-simplify -S < %s | opt -S -passes='require<target-ir>,require<scalar-evolution>,require<domtree>,loop(indvars)'
4 ;; Check if llvm can narrow !range metadata based on loop entry
9 define i1 @bounded_below_slt(ptr nocapture readonly %buffer) {
10 ; CHECK-LABEL: bounded_below_slt
12 %length = load i32, ptr %buffer, !range !0
13 %entry.pred = icmp eq i32 %length, 0
14 br i1 %entry.pred, label %abort, label %loop.preheader
21 %idx = phi i32 [ %idx.inc, %loop.next ], [ 0, %loop.preheader ]
22 %oob.pred = icmp slt i32 %idx, %length
23 br i1 %oob.pred, label %loop.next, label %oob
24 ; CHECK: br i1 true, label %loop.next, label %oob
28 %idx.inc = add i32 %idx, 1
29 %exit.pred = icmp slt i32 %idx.inc, %length
30 br i1 %exit.pred, label %loop, label %abort.loopexit
39 tail call void @abort()
43 define i1 @bounded_below_sle(ptr nocapture readonly %buffer) {
44 ; CHECK-LABEL: bounded_below_sle
46 %length = load i32, ptr %buffer, !range !0
47 %entry.pred = icmp eq i32 %length, 0
48 br i1 %entry.pred, label %abort, label %loop.preheader
55 %idx = phi i32 [ %idx.inc, %loop.next ], [ 0, %loop.preheader ]
56 %oob.pred = icmp sle i32 %idx, %length
57 br i1 %oob.pred, label %loop.next, label %oob
58 ; CHECK: br i1 true, label %loop.next, label %oob
62 %idx.inc = add i32 %idx, 1
63 %exit.pred = icmp sle i32 %idx.inc, %length
64 br i1 %exit.pred, label %loop, label %abort.loopexit
73 tail call void @abort()
77 ;; Assert that we're not making an incorrect transform.
79 declare i32 @check(ptr)
81 define void @NoChange() {
82 ; CHECK-LABEL: NoChange
88 %i.01 = phi i64 [ 2, %entry ], [ %add, %loop.end ]
89 %cmp = icmp ugt i64 %i.01, 1
90 ; CHECK: %cmp = icmp ugt i64 %i.01, 1
91 br i1 %cmp, label %loop, label %loop.end
95 %.sum = add i64 %i.01, -2
96 %v = getelementptr inbounds i8, ptr null, i64 %.sum
97 %r = tail call i32 @check(ptr %v)
98 %c = icmp eq i32 %r, 0
99 br i1 %c, label %loop.end, label %abort.now
102 tail call void @abort()
106 %add = add i64 %i.01, -1
107 %eq = icmp eq i64 %add, 0
108 br i1 %eq, label %exit, label %loop.begin
114 !0 = !{i32 0, i32 100}