• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -ipsccp -S %s -o -| FileCheck %s
2
3define 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)
8; CHECK-NEXT:    ret void
9;
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)
14  ret void
15}
16
17define 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
21;
22; CHECK-LABEL: bb10:
23; CHECK-NEXT:    ret i32 undef
24;
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
29
30bb10:                                             ; preds = %bb8
31  ret i32 10
32
33bb12:                                             ; preds = %bb8, %bb3, %bb
34  ret i32 12
35}
36
37declare void @use(i32)
38
39define 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
48;
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
57  ret i1 %res.3
58}
59
60define 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
66;
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
70  ret i1 %res
71}
72
73
74define 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
85;
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
94  ret i1 %res.3
95}
96
97define 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
103;
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
107  ret i1 %res
108}
109
110@GV = common global i32 0, align 4
111
112define 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
116;
117  %sel.1 = select i1 icmp eq (i32* bitcast (i32 (i32, i32)* @f3_constantexpr_cond to i32*), i32* @GV), i32 %x, i32 %y
118  ret i32 %sel.1
119}
120
121define 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
127;
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
131  ret i32 %res
132}
133