1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt < %s -passes=jump-threading -S -jump-threading-across-loop-headers | FileCheck %s
4 ; Make sure we correctly distinguish between %tmp15 and %tmp16 when we clone
7 define i32 @test(i1 %ARG1, i1 %ARG2, i32 %n) {
8 ; CHECK-LABEL: define i32 @test(
9 ; CHECK-SAME: i1 [[ARG1:%.*]], i1 [[ARG2:%.*]], i32 [[N:%.*]]) {
11 ; CHECK-NEXT: br i1 [[ARG1]], label [[EXIT:%.*]], label [[BODY2:%.*]]
12 ; CHECK: head1.thread:
13 ; CHECK-NEXT: br i1 [[ARG1]], label [[EXIT]], label [[BODY2_THREAD9:%.*]]
14 ; CHECK: body2.thread9:
15 ; CHECK-NEXT: [[TMP1612:%.*]] = add i32 [[TMP165:%.*]], 1
16 ; CHECK-NEXT: br label [[LATCH1:%.*]]
18 ; CHECK-NEXT: [[TMP12:%.*]] = icmp sgt i32 [[TMP165]], 1
19 ; CHECK-NEXT: br i1 [[TMP12]], label [[BODY2_THREAD:%.*]], label [[HEAD1_THREAD:%.*]]
20 ; CHECK: body2.thread:
21 ; CHECK-NEXT: [[TMP163:%.*]] = add i32 [[TMP165]], 1
22 ; CHECK-NEXT: br label [[LATCH1]]
24 ; CHECK-NEXT: [[TMP14:%.*]] = phi i32 [ 0, [[HEAD1:%.*]] ]
25 ; CHECK-NEXT: [[TMP15:%.*]] = phi i32 [ 0, [[HEAD1]] ]
26 ; CHECK-NEXT: [[TMP16:%.*]] = add i32 [[TMP14]], 1
27 ; CHECK-NEXT: br i1 [[ARG2]], label [[EXIT]], label [[LATCH1]]
29 ; CHECK-NEXT: [[TMP165]] = phi i32 [ [[TMP163]], [[BODY2_THREAD]] ], [ [[TMP16]], [[BODY2]] ], [ [[TMP1612]], [[BODY2_THREAD9]] ]
30 ; CHECK-NEXT: [[TMP154:%.*]] = phi i32 [ [[TMP165]], [[BODY2_THREAD]] ], [ [[TMP15]], [[BODY2]] ], [ [[TMP165]], [[BODY2_THREAD9]] ]
31 ; CHECK-NEXT: [[TMP18:%.*]] = icmp sgt i32 [[TMP165]], [[N]]
32 ; CHECK-NEXT: br i1 [[TMP18]], label [[EXIT]], label [[BODY1:%.*]]
34 ; CHECK-NEXT: [[RC:%.*]] = phi i32 [ [[TMP15]], [[BODY2]] ], [ [[TMP154]], [[LATCH1]] ], [ -1, [[HEAD1]] ], [ -1, [[HEAD1_THREAD]] ]
35 ; CHECK-NEXT: ret i32 [[RC]]
40 head1: ; preds = %entry, %body1
41 %tmp = phi i32 [ 0, %entry ], [ %tmp16, %body1 ]
42 %tmp3 = phi i32 [ 0, %entry ], [ %tmp16, %body1 ]
43 %tmp4 = phi i32 [ 0, %entry ], [ %tmp16, %body1 ]
44 br i1 %ARG1, label %exit, label %body2
46 body1: ; preds = %latch1
47 %tmp12 = icmp sgt i32 %tmp16, 1
48 br i1 %tmp12, label %body2, label %head1
50 body2: ; preds = %head1, %body1
51 %tmp14 = phi i32 [ %tmp16, %body1 ], [ %tmp, %head1 ]
52 %tmp15 = phi i32 [ %tmp16, %body1 ], [ %tmp3, %head1 ]
53 %tmp16 = add i32 %tmp14, 1
54 br i1 %ARG2, label %exit, label %latch1
56 latch1: ; preds = %body2
57 %tmp18 = icmp sgt i32 %tmp16, %n
58 br i1 %tmp18, label %exit, label %body1
60 exit: ; preds = %latch1, %body2, %head1
61 %rc = phi i32 [ %tmp15, %body2 ], [ %tmp15, %latch1 ], [ -1, %head1 ]