1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=newgvn -S | FileCheck %s
3 ; RUN: opt < %s -passes=newgvn,jump-threading -S | FileCheck --check-prefix=CHECK-JT %s
5 ; Test with std::pair<bool, int>
6 ; based on the following C++ code
7 ; std::pair<bool, int> callee(int v) {
9 ; if (a) return std::make_pair(true, dummy(a));
10 ; else return std::make_pair(v < 0, v);
13 ; std::pair<bool, int> rc = callee(v);
14 ; if (rc.first) dummy(0);
17 define signext i32 @testBI(i32 signext %v) {
18 ; CHECK-LABEL: @testBI(
20 ; CHECK-NEXT: [[CALL_I:%.*]] = call signext i32 @dummy(i32 signext [[V:%.*]])
21 ; CHECK-NEXT: [[TOBOOL_I:%.*]] = icmp eq i32 [[CALL_I]], 0
22 ; CHECK-NEXT: br i1 [[TOBOOL_I]], label [[IF_ELSE_I:%.*]], label [[IF_THEN_I:%.*]]
24 ; CHECK-NEXT: [[CALL2_I:%.*]] = call signext i32 @dummy(i32 signext [[CALL_I]])
25 ; CHECK-NEXT: [[RETVAL_SROA_22_0_INSERT_EXT_I_I:%.*]] = zext i32 [[CALL2_I]] to i64
26 ; CHECK-NEXT: [[RETVAL_SROA_22_0_INSERT_SHIFT_I_I:%.*]] = shl nuw i64 [[RETVAL_SROA_22_0_INSERT_EXT_I_I]], 32
27 ; CHECK-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I_I:%.*]] = or i64 [[RETVAL_SROA_22_0_INSERT_SHIFT_I_I]], 1
28 ; CHECK-NEXT: br label [[_ZL6CALLEEI_EXIT:%.*]]
30 ; CHECK-NEXT: [[DOTLOBIT_I:%.*]] = lshr i32 [[V]], 31
31 ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[DOTLOBIT_I]] to i64
32 ; CHECK-NEXT: [[RETVAL_SROA_22_0_INSERT_EXT_I8_I:%.*]] = zext i32 [[V]] to i64
33 ; CHECK-NEXT: [[RETVAL_SROA_22_0_INSERT_SHIFT_I9_I:%.*]] = shl nuw i64 [[RETVAL_SROA_22_0_INSERT_EXT_I8_I]], 32
34 ; CHECK-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I11_I:%.*]] = or i64 [[RETVAL_SROA_22_0_INSERT_SHIFT_I9_I]], [[TMP0]]
35 ; CHECK-NEXT: br label [[_ZL6CALLEEI_EXIT]]
36 ; CHECK: _ZL6calleei.exit:
37 ; CHECK-NEXT: [[RETVAL_SROA_0_0_I:%.*]] = phi i64 [ [[RETVAL_SROA_0_0_INSERT_INSERT_I_I]], [[IF_THEN_I]] ], [ [[RETVAL_SROA_0_0_INSERT_INSERT_I11_I]], [[IF_ELSE_I]] ]
38 ; CHECK-NEXT: [[RC_SROA_43_0_EXTRACT_SHIFT:%.*]] = lshr i64 [[RETVAL_SROA_0_0_I]], 32
39 ; CHECK-NEXT: [[RC_SROA_43_0_EXTRACT_TRUNC:%.*]] = trunc i64 [[RC_SROA_43_0_EXTRACT_SHIFT]] to i32
40 ; CHECK-NEXT: [[TMP1:%.*]] = and i64 [[RETVAL_SROA_0_0_I]], 1
41 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[TMP1]], 0
42 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
44 ; CHECK-NEXT: [[CALL1:%.*]] = call signext i32 @dummy(i32 signext 0)
45 ; CHECK-NEXT: br label [[IF_END]]
47 ; CHECK-NEXT: ret i32 [[RC_SROA_43_0_EXTRACT_TRUNC]]
49 ; CHECK-JT-LABEL: @testBI(
50 ; CHECK-JT-NEXT: entry:
51 ; CHECK-JT-NEXT: [[CALL_I:%.*]] = call signext i32 @dummy(i32 signext [[V:%.*]])
52 ; CHECK-JT-NEXT: [[TOBOOL_I:%.*]] = icmp eq i32 [[CALL_I]], 0
53 ; CHECK-JT-NEXT: br i1 [[TOBOOL_I]], label [[IF_ELSE_I:%.*]], label [[IF_THEN_I:%.*]]
54 ; CHECK-JT: if.then.i:
55 ; CHECK-JT-NEXT: [[CALL2_I:%.*]] = call signext i32 @dummy(i32 signext [[CALL_I]])
56 ; CHECK-JT-NEXT: [[RETVAL_SROA_22_0_INSERT_EXT_I_I:%.*]] = zext i32 [[CALL2_I]] to i64
57 ; CHECK-JT-NEXT: [[RETVAL_SROA_22_0_INSERT_SHIFT_I_I:%.*]] = shl nuw i64 [[RETVAL_SROA_22_0_INSERT_EXT_I_I]], 32
58 ; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I_I:%.*]] = or i64 [[RETVAL_SROA_22_0_INSERT_SHIFT_I_I]], 1
59 ; CHECK-JT-NEXT: br label [[_ZL6CALLEEI_EXIT:%.*]]
60 ; CHECK-JT: if.else.i:
61 ; CHECK-JT-NEXT: [[DOTLOBIT_I:%.*]] = lshr i32 [[V]], 31
62 ; CHECK-JT-NEXT: [[TMP0:%.*]] = zext i32 [[DOTLOBIT_I]] to i64
63 ; CHECK-JT-NEXT: [[RETVAL_SROA_22_0_INSERT_EXT_I8_I:%.*]] = zext i32 [[V]] to i64
64 ; CHECK-JT-NEXT: [[RETVAL_SROA_22_0_INSERT_SHIFT_I9_I:%.*]] = shl nuw i64 [[RETVAL_SROA_22_0_INSERT_EXT_I8_I]], 32
65 ; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I11_I:%.*]] = or i64 [[RETVAL_SROA_22_0_INSERT_SHIFT_I9_I]], [[TMP0]]
66 ; CHECK-JT-NEXT: br label [[_ZL6CALLEEI_EXIT]]
67 ; CHECK-JT: _ZL6calleei.exit:
68 ; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_I:%.*]] = phi i64 [ [[RETVAL_SROA_0_0_INSERT_INSERT_I_I]], [[IF_THEN_I]] ], [ [[RETVAL_SROA_0_0_INSERT_INSERT_I11_I]], [[IF_ELSE_I]] ]
69 ; CHECK-JT-NEXT: [[RC_SROA_43_0_EXTRACT_SHIFT:%.*]] = lshr i64 [[RETVAL_SROA_0_0_I]], 32
70 ; CHECK-JT-NEXT: [[RC_SROA_43_0_EXTRACT_TRUNC:%.*]] = trunc i64 [[RC_SROA_43_0_EXTRACT_SHIFT]] to i32
71 ; CHECK-JT-NEXT: [[TMP1:%.*]] = and i64 [[RETVAL_SROA_0_0_I]], 1
72 ; CHECK-JT-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[TMP1]], 0
73 ; CHECK-JT-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
75 ; CHECK-JT-NEXT: [[CALL1:%.*]] = call signext i32 @dummy(i32 signext 0)
76 ; CHECK-JT-NEXT: br label [[IF_END]]
78 ; CHECK-JT-NEXT: ret i32 [[RC_SROA_43_0_EXTRACT_TRUNC]]
82 %call.i = call signext i32 @dummy(i32 signext %v)
83 %tobool.i = icmp eq i32 %call.i, 0
84 br i1 %tobool.i, label %if.else.i, label %if.then.i
86 if.then.i: ; preds = %entry
87 %call2.i = call signext i32 @dummy(i32 signext %call.i)
88 %retval.sroa.22.0.insert.ext.i.i = zext i32 %call2.i to i64
89 %retval.sroa.22.0.insert.shift.i.i = shl nuw i64 %retval.sroa.22.0.insert.ext.i.i, 32
90 %retval.sroa.0.0.insert.insert.i.i = or i64 %retval.sroa.22.0.insert.shift.i.i, 1
91 br label %_ZL6calleei.exit
93 if.else.i: ; preds = %entry
94 %.lobit.i = lshr i32 %v, 31
95 %0 = zext i32 %.lobit.i to i64
96 %retval.sroa.22.0.insert.ext.i8.i = zext i32 %v to i64
97 %retval.sroa.22.0.insert.shift.i9.i = shl nuw i64 %retval.sroa.22.0.insert.ext.i8.i, 32
98 %retval.sroa.0.0.insert.insert.i11.i = or i64 %retval.sroa.22.0.insert.shift.i9.i, %0
99 br label %_ZL6calleei.exit
101 _ZL6calleei.exit: ; preds = %if.then.i, %if.else.i
102 %retval.sroa.0.0.i = phi i64 [ %retval.sroa.0.0.insert.insert.i.i, %if.then.i ], [ %retval.sroa.0.0.insert.insert.i11.i, %if.else.i ]
103 %rc.sroa.43.0.extract.shift = lshr i64 %retval.sroa.0.0.i, 32
104 %rc.sroa.43.0.extract.trunc = trunc i64 %rc.sroa.43.0.extract.shift to i32
105 %1 = and i64 %retval.sroa.0.0.i, 1
106 %tobool = icmp eq i64 %1, 0
107 br i1 %tobool, label %if.end, label %if.then
109 if.then: ; preds = %_ZL6calleei.exit
110 %call1 = call signext i32 @dummy(i32 signext 0)
113 if.end: ; preds = %_ZL6calleei.exit, %if.then
114 ret i32 %rc.sroa.43.0.extract.trunc
118 ; Test with std::pair<int, bool>
119 ; based on the following C++ code
120 ; std::pair<int, bool> callee(int v) {
122 ; if (a) return std::make_pair(dummy(v), true);
123 ; else return std::make_pair(v, v < 0);
126 ; std::pair<int, bool> rc = callee(v);
127 ; if (rc.second) dummy(0);
130 define signext i32 @testIB(i32 signext %v) {
131 ; CHECK-LABEL: @testIB(
133 ; CHECK-NEXT: [[CALL_I:%.*]] = call signext i32 @dummy(i32 signext [[V:%.*]])
134 ; CHECK-NEXT: [[TOBOOL_I:%.*]] = icmp eq i32 [[CALL_I]], 0
135 ; CHECK-NEXT: br i1 [[TOBOOL_I]], label [[IF_ELSE_I:%.*]], label [[IF_THEN_I:%.*]]
137 ; CHECK-NEXT: [[CALL1_I:%.*]] = call signext i32 @dummy(i32 signext [[V]])
138 ; CHECK-NEXT: [[RETVAL_SROA_0_0_INSERT_EXT_I_I:%.*]] = zext i32 [[CALL1_I]] to i64
139 ; CHECK-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I_I:%.*]] = or i64 [[RETVAL_SROA_0_0_INSERT_EXT_I_I]], 4294967296
140 ; CHECK-NEXT: br label [[_ZL6CALLEEI_EXIT:%.*]]
142 ; CHECK-NEXT: [[DOTLOBIT_I:%.*]] = lshr i32 [[V]], 31
143 ; CHECK-NEXT: [[TMP0:%.*]] = zext i32 [[DOTLOBIT_I]] to i64
144 ; CHECK-NEXT: [[RETVAL_SROA_2_0_INSERT_SHIFT_I8_I:%.*]] = shl nuw nsw i64 [[TMP0]], 32
145 ; CHECK-NEXT: [[RETVAL_SROA_0_0_INSERT_EXT_I9_I:%.*]] = zext i32 [[V]] to i64
146 ; CHECK-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I10_I:%.*]] = or i64 [[RETVAL_SROA_2_0_INSERT_SHIFT_I8_I]], [[RETVAL_SROA_0_0_INSERT_EXT_I9_I]]
147 ; CHECK-NEXT: br label [[_ZL6CALLEEI_EXIT]]
148 ; CHECK: _ZL6calleei.exit:
149 ; CHECK-NEXT: [[RETVAL_SROA_0_0_I:%.*]] = phi i64 [ [[RETVAL_SROA_0_0_INSERT_INSERT_I_I]], [[IF_THEN_I]] ], [ [[RETVAL_SROA_0_0_INSERT_INSERT_I10_I]], [[IF_ELSE_I]] ]
150 ; CHECK-NEXT: [[RC_SROA_0_0_EXTRACT_TRUNC:%.*]] = trunc i64 [[RETVAL_SROA_0_0_I]] to i32
151 ; CHECK-NEXT: [[TMP1:%.*]] = and i64 [[RETVAL_SROA_0_0_I]], 4294967296
152 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[TMP1]], 0
153 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
155 ; CHECK-NEXT: [[CALL1:%.*]] = call signext i32 @dummy(i32 signext 0)
156 ; CHECK-NEXT: br label [[IF_END]]
158 ; CHECK-NEXT: ret i32 [[RC_SROA_0_0_EXTRACT_TRUNC]]
160 ; CHECK-JT-LABEL: @testIB(
161 ; CHECK-JT-NEXT: entry:
162 ; CHECK-JT-NEXT: [[CALL_I:%.*]] = call signext i32 @dummy(i32 signext [[V:%.*]])
163 ; CHECK-JT-NEXT: [[TOBOOL_I:%.*]] = icmp eq i32 [[CALL_I]], 0
164 ; CHECK-JT-NEXT: br i1 [[TOBOOL_I]], label [[IF_ELSE_I:%.*]], label [[IF_THEN_I:%.*]]
165 ; CHECK-JT: if.then.i:
166 ; CHECK-JT-NEXT: [[CALL1_I:%.*]] = call signext i32 @dummy(i32 signext [[V]])
167 ; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_INSERT_EXT_I_I:%.*]] = zext i32 [[CALL1_I]] to i64
168 ; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I_I:%.*]] = or i64 [[RETVAL_SROA_0_0_INSERT_EXT_I_I]], 4294967296
169 ; CHECK-JT-NEXT: br label [[_ZL6CALLEEI_EXIT:%.*]]
170 ; CHECK-JT: if.else.i:
171 ; CHECK-JT-NEXT: [[DOTLOBIT_I:%.*]] = lshr i32 [[V]], 31
172 ; CHECK-JT-NEXT: [[TMP0:%.*]] = zext i32 [[DOTLOBIT_I]] to i64
173 ; CHECK-JT-NEXT: [[RETVAL_SROA_2_0_INSERT_SHIFT_I8_I:%.*]] = shl nuw nsw i64 [[TMP0]], 32
174 ; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_INSERT_EXT_I9_I:%.*]] = zext i32 [[V]] to i64
175 ; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_INSERT_INSERT_I10_I:%.*]] = or i64 [[RETVAL_SROA_2_0_INSERT_SHIFT_I8_I]], [[RETVAL_SROA_0_0_INSERT_EXT_I9_I]]
176 ; CHECK-JT-NEXT: br label [[_ZL6CALLEEI_EXIT]]
177 ; CHECK-JT: _ZL6calleei.exit:
178 ; CHECK-JT-NEXT: [[RETVAL_SROA_0_0_I:%.*]] = phi i64 [ [[RETVAL_SROA_0_0_INSERT_INSERT_I_I]], [[IF_THEN_I]] ], [ [[RETVAL_SROA_0_0_INSERT_INSERT_I10_I]], [[IF_ELSE_I]] ]
179 ; CHECK-JT-NEXT: [[RC_SROA_0_0_EXTRACT_TRUNC:%.*]] = trunc i64 [[RETVAL_SROA_0_0_I]] to i32
180 ; CHECK-JT-NEXT: [[TMP1:%.*]] = and i64 [[RETVAL_SROA_0_0_I]], 4294967296
181 ; CHECK-JT-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[TMP1]], 0
182 ; CHECK-JT-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
184 ; CHECK-JT-NEXT: [[CALL1:%.*]] = call signext i32 @dummy(i32 signext 0)
185 ; CHECK-JT-NEXT: br label [[IF_END]]
187 ; CHECK-JT-NEXT: ret i32 [[RC_SROA_0_0_EXTRACT_TRUNC]]
191 %call.i = call signext i32 @dummy(i32 signext %v)
192 %tobool.i = icmp eq i32 %call.i, 0
193 br i1 %tobool.i, label %if.else.i, label %if.then.i
195 if.then.i: ; preds = %entry
196 %call1.i = call signext i32 @dummy(i32 signext %v)
197 %retval.sroa.0.0.insert.ext.i.i = zext i32 %call1.i to i64
198 %retval.sroa.0.0.insert.insert.i.i = or i64 %retval.sroa.0.0.insert.ext.i.i, 4294967296
199 br label %_ZL6calleei.exit
201 if.else.i: ; preds = %entry
202 %.lobit.i = lshr i32 %v, 31
203 %0 = zext i32 %.lobit.i to i64
204 %retval.sroa.2.0.insert.shift.i8.i = shl nuw nsw i64 %0, 32
205 %retval.sroa.0.0.insert.ext.i9.i = zext i32 %v to i64
206 %retval.sroa.0.0.insert.insert.i10.i = or i64 %retval.sroa.2.0.insert.shift.i8.i, %retval.sroa.0.0.insert.ext.i9.i
207 br label %_ZL6calleei.exit
209 _ZL6calleei.exit: ; preds = %if.then.i, %if.else.i
210 %retval.sroa.0.0.i = phi i64 [ %retval.sroa.0.0.insert.insert.i.i, %if.then.i ], [ %retval.sroa.0.0.insert.insert.i10.i, %if.else.i ]
211 %rc.sroa.0.0.extract.trunc = trunc i64 %retval.sroa.0.0.i to i32
212 %1 = and i64 %retval.sroa.0.0.i, 4294967296
213 %tobool = icmp eq i64 %1, 0
214 br i1 %tobool, label %if.end, label %if.then
216 if.then: ; preds = %_ZL6calleei.exit
217 %call1 = call signext i32 @dummy(i32 signext 0)
220 if.end: ; preds = %_ZL6calleei.exit, %if.then
221 ret i32 %rc.sroa.0.0.extract.trunc
224 declare signext i32 @dummy(i32 signext %v)