11cfe3e6dSNikita Popov; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2cee313d2SEric Christopher; RUN: opt -S -jump-threading < %s | FileCheck %s
3cee313d2SEric Christopher
4cee313d2SEric Christopherdefine i8 @test(i32 %a, i32 %length) {
5*98245d08SNikita Popov; CHECK-LABEL: @test(
61cfe3e6dSNikita Popov; CHECK-NEXT:  entry:
71cfe3e6dSNikita Popov; CHECK-NEXT:    br label [[BACKEDGE:%.*]]
81cfe3e6dSNikita Popov; CHECK:       backedge:
91cfe3e6dSNikita Popov; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE]] ]
101cfe3e6dSNikita Popov; CHECK-NEXT:    [[IV_NEXT]] = add nsw i32 [[IV]], 1
111cfe3e6dSNikita Popov; CHECK-NEXT:    [[CONT:%.*]] = icmp slt i32 [[IV_NEXT]], 400
121cfe3e6dSNikita Popov; CHECK-NEXT:    br i1 [[CONT]], label [[BACKEDGE]], label [[EXIT:%.*]]
131cfe3e6dSNikita Popov; CHECK:       exit:
141cfe3e6dSNikita Popov; CHECK-NEXT:    ret i8 0
151cfe3e6dSNikita Popov;
16cee313d2SEric Christopherentry:
17cee313d2SEric Christopher  br label %loop
18cee313d2SEric Christopher
19cee313d2SEric Christopherloop:
20cee313d2SEric Christopher  %iv = phi i32 [0, %entry], [%iv.next, %backedge]
21cee313d2SEric Christopher  ;; We can use an inductive argument to prove %iv is always positive
22cee313d2SEric Christopher  %cnd = icmp sge i32 %iv, 0
23cee313d2SEric Christopher  br i1 %cnd, label %backedge, label %exit
24cee313d2SEric Christopher
25cee313d2SEric Christopherbackedge:
26cee313d2SEric Christopher  %iv.next = add nsw i32 %iv, 1
27cee313d2SEric Christopher  %cont = icmp slt i32 %iv.next, 400
28cee313d2SEric Christopher  br i1 %cont, label %loop, label %exit
29cee313d2SEric Christopherexit:
30cee313d2SEric Christopher  ret i8 0
31cee313d2SEric Christopher}
32cee313d2SEric Christopher
33