1 ; RUN: opt -ipsccp -S %s -o -| FileCheck %s
3 define void @caller.1(i8* %arg) {
4 ; CHECK-LABEL: define void @caller.1(i8* %arg) {
5 ; CHECK-NEXT: %r.1 = tail call i32 @callee.1(i32 4)
6 ; CHECK-NEXT: %r.2 = tail call i32 @callee.1(i32 2)
7 ; CHECK-NEXT: call void @use(i32 20)
10 %r.1 = tail call i32 @callee.1(i32 4)
11 %r.2 = tail call i32 @callee.1(i32 2)
12 %r.3 = add i32 %r.1, %r.2
13 call void @use(i32 %r.3)
17 define internal i32 @callee.1(i32 %arg) {
18 ; CHECK-LABEL: define internal i32 @callee.1(i32 %arg) {
19 ; CHECK-NEXT: %sel = select i1 false, i32 16, i32 %arg
20 ; CHECK-NEXT: br label %bb10
23 ; CHECK-NEXT: ret i32 undef
25 %c.1 = icmp slt i32 %arg, 0
26 %sel = select i1 %c.1, i32 16, i32 %arg
27 %c.2 = icmp eq i32 %sel, 0
28 br i1 %c.2, label %bb12, label %bb10
33 bb12: ; preds = %bb8, %bb3, %bb
37 declare void @use(i32)
39 define internal i1 @f1(i32 %x, i32 %y, i1 %cmp) {
40 ; CHECK-LABEL: define internal i1 @f1(i32 %x, i32 %y, i1 %cmp) {
41 ; CHECK-NEXT: %sel.1 = select i1 %cmp, i32 %x, i32 %y
42 ; CHECK-NEXT: %c.2 = icmp sgt i32 %sel.1, 100
43 ; CHECK-NEXT: %c.3 = icmp eq i32 %sel.1, 50
44 ; CHECK-NEXT: %res.1 = add i1 false, %c.2
45 ; CHECK-NEXT: %res.2 = add i1 %res.1, %c.3
46 ; CHECK-NEXT: %res.3 = add i1 %res.2, false
47 ; CHECK-NEXT: ret i1 %res.3
49 %sel.1 = select i1 %cmp, i32 %x, i32 %y
50 %c.1 = icmp sgt i32 %sel.1, 300
51 %c.2 = icmp sgt i32 %sel.1, 100
52 %c.3 = icmp eq i32 %sel.1, 50
53 %c.4 = icmp slt i32 %sel.1, 9
54 %res.1 = add i1 %c.1, %c.2
55 %res.2 = add i1 %res.1, %c.3
56 %res.3 = add i1 %res.2, %c.4
60 define i1 @caller1(i1 %cmp) {
61 ; CHECK-LABEL: define i1 @caller1(i1 %cmp) {
62 ; CHECK-NEXT: %call.1 = tail call i1 @f1(i32 10, i32 100, i1 %cmp)
63 ; CHECK-NEXT: %call.2 = tail call i1 @f1(i32 20, i32 200, i1 %cmp)
64 ; CHECK-NEXT: %res = and i1 %call.1, %call.2
65 ; CHECK-NEXT: ret i1 %res
67 %call.1 = tail call i1 @f1(i32 10, i32 100, i1 %cmp)
68 %call.2 = tail call i1 @f1(i32 20, i32 200, i1 %cmp)
69 %res = and i1 %call.1, %call.2
74 define i1 @f2(i32 %x, i32 %y, i1 %cmp) {
75 ; CHECK-LABEL: define i1 @f2(i32 %x, i32 %y, i1 %cmp) {
76 ; CHECK-NEXT: %sel.1 = select i1 %cmp, i32 %x, i32 %y
77 ; CHECK-NEXT: %c.1 = icmp sgt i32 %sel.1, 300
78 ; CHECK-NEXT: %c.2 = icmp sgt i32 %sel.1, 100
79 ; CHECK-NEXT: %c.3 = icmp eq i32 %sel.1, 50
80 ; CHECK-NEXT: %c.4 = icmp slt i32 %sel.1, 9
81 ; CHECK-NEXT: %res.1 = add i1 %c.1, %c.2
82 ; CHECK-NEXT: %res.2 = add i1 %res.1, %c.3
83 ; CHECK-NEXT: %res.3 = add i1 %res.2, %c.4
84 ; CHECK-NEXT: ret i1 %res.3
86 %sel.1 = select i1 %cmp, i32 %x, i32 %y
87 %c.1 = icmp sgt i32 %sel.1, 300
88 %c.2 = icmp sgt i32 %sel.1, 100
89 %c.3 = icmp eq i32 %sel.1, 50
90 %c.4 = icmp slt i32 %sel.1, 9
91 %res.1 = add i1 %c.1, %c.2
92 %res.2 = add i1 %res.1, %c.3
93 %res.3 = add i1 %res.2, %c.4
97 define i1 @caller2(i32 %y, i1 %cmp) {
98 ; CHECK-LABEL: define i1 @caller2(i32 %y, i1 %cmp) {
99 ; CHECK-NEXT: %call.1 = tail call i1 @f2(i32 10, i32 %y, i1 %cmp)
100 ; CHECK-NEXT: %call.2 = tail call i1 @f2(i32 20, i32 %y, i1 %cmp)
101 ; CHECK-NEXT: %res = and i1 %call.1, %call.2
102 ; CHECK-NEXT: ret i1 %res
104 %call.1 = tail call i1 @f2(i32 10, i32 %y, i1 %cmp)
105 %call.2 = tail call i1 @f2(i32 20, i32 %y, i1 %cmp)
106 %res = and i1 %call.1, %call.2
110 @GV = common global i32 0, align 4
112 define i32 @f3_constantexpr_cond(i32 %x, i32 %y) {
113 ; CHECK-LABEL: define i32 @f3_constantexpr_cond(i32 %x, i32 %y)
114 ; CHECK-NEXT: %sel.1 = select i1 icmp eq (i32* bitcast (i32 (i32, i32)* @f3_constantexpr_cond to i32*), i32* @GV), i32 %x, i32 %y
115 ; CHECK-NEXT: ret i32 %sel.1
117 %sel.1 = select i1 icmp eq (i32* bitcast (i32 (i32, i32)* @f3_constantexpr_cond to i32*), i32* @GV), i32 %x, i32 %y
121 define i32 @caller3(i32 %y) {
122 ; CHECK-LABEL: define i32 @caller3(i32 %y) {
123 ; CHECK-NEXT: %call.1 = tail call i32 @f3_constantexpr_cond(i32 10, i32 %y)
124 ; CHECK-NEXT: %call.2 = tail call i32 @f3_constantexpr_cond(i32 20, i32 %y)
125 ; CHECK-NEXT: %res = and i32 %call.1, %call.2
126 ; CHECK-NEXT: ret i32 %res
128 %call.1 = tail call i32 @f3_constantexpr_cond(i32 10, i32 %y)
129 %call.2 = tail call i32 @f3_constantexpr_cond(i32 20, i32 %y)
130 %res = and i32 %call.1, %call.2