1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ;RUN: opt < %s -jump-threading -S | FileCheck %s
8 ; Make sure we thread the end of the bar block to the end of the function.
9 define void @test1(i32 %x) {
10 ; CHECK-LABEL: @test1(
12 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 9
13 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_END_THREAD:%.*]], label [[IF_END:%.*]]
14 ; CHECK: if.end.thread:
15 ; CHECK-NEXT: call void (...) @bar()
16 ; CHECK-NEXT: br label [[IF_END4:%.*]]
18 ; CHECK-NEXT: [[X_OFF:%.*]] = add i32 [[X]], -3
19 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i32 [[X_OFF]], 5
20 ; CHECK-NEXT: br i1 [[TMP0]], label [[IF_THEN3:%.*]], label [[IF_END4]]
22 ; CHECK-NEXT: call void (...) @baz()
23 ; CHECK-NEXT: br label [[IF_END4]]
25 ; CHECK-NEXT: ret void
28 %cmp = icmp sgt i32 %x, 9
29 br i1 %cmp, label %if.then, label %if.end
31 if.then: ; preds = %entry
32 call void (...) @bar()
35 if.end: ; preds = %if.then, %entry
36 %x.off = add i32 %x, -3
37 %0 = icmp ult i32 %x.off, 5
38 br i1 %0, label %if.then3, label %if.end4
40 if.then3: ; preds = %if.end
41 call void (...) @baz()
44 if.end4: ; preds = %if.then3, %if.end
48 ; Make sure we thread the false side of the first if to the end of the function.
49 define void @test2(i32 %x) {
50 ; CHECK-LABEL: @test2(
52 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 9
53 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_END:%.*]], label [[IF_END4:%.*]]
55 ; CHECK-NEXT: call void (...) @bar()
56 ; CHECK-NEXT: [[X_OFF:%.*]] = add i32 [[X]], -3
57 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i32 [[X_OFF]], 5
58 ; CHECK-NEXT: br i1 [[TMP0]], label [[IF_THEN3:%.*]], label [[IF_END4]]
60 ; CHECK-NEXT: call void (...) @baz()
61 ; CHECK-NEXT: br label [[IF_END4]]
63 ; CHECK-NEXT: ret void
66 %cmp = icmp slt i32 %x, 9
67 br i1 %cmp, label %if.then, label %if.end
69 if.then: ; preds = %entry
70 call void (...) @bar()
73 if.end: ; preds = %if.then, %entry
74 %x.off = add i32 %x, -3
75 %0 = icmp ult i32 %x.off, 5
76 br i1 %0, label %if.then3, label %if.end4
78 if.then3: ; preds = %if.end
79 call void (...) @baz()
82 if.end4: ; preds = %if.then3, %if.end
86 ; Negative test to make sure we don't thread when the ranges overlap.
87 define void @test3(i32 %x) {
88 ; CHECK-LABEL: @test3(
90 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], 6
91 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
93 ; CHECK-NEXT: call void (...) @bar()
94 ; CHECK-NEXT: br label [[IF_END]]
96 ; CHECK-NEXT: [[X_OFF:%.*]] = add i32 [[X]], -3
97 ; CHECK-NEXT: [[TMP0:%.*]] = icmp ult i32 [[X_OFF]], 5
98 ; CHECK-NEXT: br i1 [[TMP0]], label [[IF_THEN3:%.*]], label [[IF_END4:%.*]]
100 ; CHECK-NEXT: call void (...) @baz()
101 ; CHECK-NEXT: br label [[IF_END4]]
103 ; CHECK-NEXT: ret void
106 %cmp = icmp sgt i32 %x, 6
107 br i1 %cmp, label %if.then, label %if.end
109 if.then: ; preds = %entry
110 call void (...) @bar()
113 if.end: ; preds = %if.then, %entry
114 %x.off = add i32 %x, -3
115 %0 = icmp ult i32 %x.off, 5
116 br i1 %0, label %if.then3, label %if.end4
118 if.then3: ; preds = %if.end
119 call void (...) @baz()
122 if.end4: ; preds = %if.then3, %if.end