1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instsimplify -S < %s | FileCheck %s
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-unknown-linux-gnu"
6 @g1 = global i32 0, align 4
7 @g2 = internal global i32 0, align 4
8 @g3 = unnamed_addr global i32 0, align 4
9 @g4 = hidden global i32 0, align 4
10 @g5 = protected global i32 0, align 4
11 @g6 = thread_local unnamed_addr global i32 0, align 4
13 ; Make sure we can simplify away a pointer comparison between
14 ; dynamically-allocated memory and a local stack allocation.
19 ; mData = new int[12];
20 ; if (mData != mStackData) {
25 define void @_Z2p1v() {
26 ; CHECK-LABEL: @_Z2p1v(
28 ; CHECK-NEXT: [[I1:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2:[0-9]+]]
29 ; CHECK-NEXT: br i1 false, label [[BB6:%.*]], label [[BB5:%.*]]
31 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I1]]) #[[ATTR3:[0-9]+]]
32 ; CHECK-NEXT: br label [[BB6]]
34 ; CHECK-NEXT: ret void
37 %mStackData = alloca [10 x i32], align 16
38 %i1 = tail call noalias ptr @_Znam(i64 48) #3
39 %i4 = icmp eq ptr %i1, %mStackData
40 br i1 %i4, label %bb6, label %bb5
43 call void @_ZdaPv(ptr %i1) #4
46 bb6: ; preds = %bb5, %bb
50 define void @_Z2p2bb(i1 zeroext %b1, i1 zeroext %b2) {
51 ; CHECK-LABEL: @_Z2p2bb(
53 ; CHECK-NEXT: [[I3:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
54 ; CHECK-NEXT: [[I4:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
55 ; CHECK-NEXT: br i1 false, label [[BB8:%.*]], label [[BB7:%.*]]
57 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I3]]) #[[ATTR3]]
58 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I4]]) #[[ATTR3]]
59 ; CHECK-NEXT: br label [[BB8]]
61 ; CHECK-NEXT: ret void
64 %mStackData = alloca [10 x i32], align 16
65 %i2 = select i1 %b1, ptr %mStackData, ptr @g2
66 %i3 = tail call noalias ptr @_Znam(i64 48) #3
67 %i4 = tail call noalias ptr @_Znam(i64 48) #3
68 %.v = select i1 %b2, ptr %i3, ptr %i4
69 %i6 = icmp eq ptr %.v, %i2
70 br i1 %i6, label %bb8, label %bb7
73 call void @_ZdaPv(ptr %i3) #4
74 call void @_ZdaPv(ptr %i4) #4
77 bb8: ; preds = %bb7, %bb
81 define void @_Z2p4bb(i1 zeroext %b1, i1 zeroext %b2) {
82 ; CHECK-LABEL: @_Z2p4bb(
84 ; CHECK-NEXT: [[I3:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
85 ; CHECK-NEXT: [[I4:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
86 ; CHECK-NEXT: br i1 false, label [[BB8:%.*]], label [[BB7:%.*]]
88 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I3]]) #[[ATTR3]]
89 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I4]]) #[[ATTR3]]
90 ; CHECK-NEXT: br label [[BB8]]
92 ; CHECK-NEXT: ret void
95 %mStackData = alloca [10 x i32], align 16
96 %i2 = select i1 %b1, ptr %mStackData, ptr @g3
97 %i3 = tail call noalias ptr @_Znam(i64 48) #3
98 %i4 = tail call noalias ptr @_Znam(i64 48) #3
99 %.v = select i1 %b2, ptr %i3, ptr %i4
100 %i6 = icmp eq ptr %.v, %i2
101 br i1 %i6, label %bb8, label %bb7
104 call void @_ZdaPv(ptr %i3) #4
105 call void @_ZdaPv(ptr %i4) #4
108 bb8: ; preds = %bb7, %bb
112 define void @_Z2p5bb(i1 zeroext %b1, i1 zeroext %b2) {
113 ; CHECK-LABEL: @_Z2p5bb(
115 ; CHECK-NEXT: [[I3:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
116 ; CHECK-NEXT: [[I4:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
117 ; CHECK-NEXT: br i1 false, label [[BB8:%.*]], label [[BB7:%.*]]
119 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I3]]) #[[ATTR3]]
120 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I4]]) #[[ATTR3]]
121 ; CHECK-NEXT: br label [[BB8]]
123 ; CHECK-NEXT: ret void
126 %mStackData = alloca [10 x i32], align 16
127 %i2 = select i1 %b1, ptr %mStackData, ptr @g4
128 %i3 = tail call noalias ptr @_Znam(i64 48) #3
129 %i4 = tail call noalias ptr @_Znam(i64 48) #3
130 %.v = select i1 %b2, ptr %i3, ptr %i4
131 %i6 = icmp eq ptr %.v, %i2
132 br i1 %i6, label %bb8, label %bb7
135 call void @_ZdaPv(ptr %i3) #4
136 call void @_ZdaPv(ptr %i4) #4
139 bb8: ; preds = %bb7, %bb
143 define void @_Z2p6bb(i1 zeroext %b1, i1 zeroext %b2) {
144 ; CHECK-LABEL: @_Z2p6bb(
146 ; CHECK-NEXT: [[I3:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
147 ; CHECK-NEXT: [[I4:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
148 ; CHECK-NEXT: br i1 false, label [[BB8:%.*]], label [[BB7:%.*]]
150 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I3]]) #[[ATTR3]]
151 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I4]]) #[[ATTR3]]
152 ; CHECK-NEXT: br label [[BB8]]
154 ; CHECK-NEXT: ret void
157 %mStackData = alloca [10 x i32], align 16
158 %i2 = select i1 %b1, ptr %mStackData, ptr @g5
159 %i3 = tail call noalias ptr @_Znam(i64 48) #3
160 %i4 = tail call noalias ptr @_Znam(i64 48) #3
161 %.v = select i1 %b2, ptr %i3, ptr %i4
162 %i6 = icmp eq ptr %.v, %i2
163 br i1 %i6, label %bb8, label %bb7
166 call void @_ZdaPv(ptr %i3) #4
167 call void @_ZdaPv(ptr %i4) #4
170 bb8: ; preds = %bb7, %bb
174 define void @_Z4nopebbPi(i1 zeroext %b1, i1 zeroext %b2, ptr readnone %q) {
175 ; CHECK-LABEL: @_Z4nopebbPi(
177 ; CHECK-NEXT: [[MSTACKDATA:%.*]] = alloca [10 x i32], align 16
178 ; CHECK-NEXT: [[I2:%.*]] = select i1 [[B1:%.*]], ptr [[MSTACKDATA]], ptr [[Q:%.*]]
179 ; CHECK-NEXT: [[I3:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
180 ; CHECK-NEXT: [[I4:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
181 ; CHECK-NEXT: [[DOTV:%.*]] = select i1 [[B2:%.*]], ptr [[I3]], ptr [[I4]]
182 ; CHECK-NEXT: [[I6:%.*]] = icmp eq ptr [[DOTV]], [[I2]]
183 ; CHECK-NEXT: br i1 [[I6]], label [[BB8:%.*]], label [[BB7:%.*]]
185 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I3]]) #[[ATTR3]]
186 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I4]]) #[[ATTR3]]
187 ; CHECK-NEXT: br label [[BB8]]
189 ; CHECK-NEXT: ret void
192 %mStackData = alloca [10 x i32], align 16
193 %i2 = select i1 %b1, ptr %mStackData, ptr %q
194 %i3 = tail call noalias ptr @_Znam(i64 48) #3
195 %i4 = tail call noalias ptr @_Znam(i64 48) #3
196 %.v = select i1 %b2, ptr %i3, ptr %i4
197 %i6 = icmp eq ptr %.v, %i2
198 br i1 %i6, label %bb8, label %bb7
201 call void @_ZdaPv(ptr %i3) #4
202 call void @_ZdaPv(ptr %i4) #4
205 bb8: ; preds = %bb7, %bb
209 define void @_Z2p3bb(i1 zeroext %b1, i1 zeroext %b2) {
210 ; CHECK-LABEL: @_Z2p3bb(
212 ; CHECK-NEXT: [[MSTACKDATA:%.*]] = alloca [10 x i32], align 16
213 ; CHECK-NEXT: [[I2:%.*]] = select i1 [[B1:%.*]], ptr [[MSTACKDATA]], ptr @g1
214 ; CHECK-NEXT: [[I3:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
215 ; CHECK-NEXT: [[I4:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
216 ; CHECK-NEXT: [[DOTV:%.*]] = select i1 [[B2:%.*]], ptr [[I3]], ptr [[I4]]
217 ; CHECK-NEXT: [[I6:%.*]] = icmp eq ptr [[DOTV]], [[I2]]
218 ; CHECK-NEXT: br i1 [[I6]], label [[BB8:%.*]], label [[BB7:%.*]]
220 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I3]]) #[[ATTR3]]
221 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I4]]) #[[ATTR3]]
222 ; CHECK-NEXT: br label [[BB8]]
224 ; CHECK-NEXT: ret void
227 %mStackData = alloca [10 x i32], align 16
228 %i2 = select i1 %b1, ptr %mStackData, ptr @g1
229 %i3 = tail call noalias ptr @_Znam(i64 48) #3
230 %i4 = tail call noalias ptr @_Znam(i64 48) #3
231 %.v = select i1 %b2, ptr %i3, ptr %i4
232 %i6 = icmp eq ptr %.v, %i2
233 br i1 %i6, label %bb8, label %bb7
236 call void @_ZdaPv(ptr %i3) #4
237 call void @_ZdaPv(ptr %i4) #4
240 bb8: ; preds = %bb7, %bb
244 define void @_Z2p7bb(i1 zeroext %b1, i1 zeroext %b2) {
245 ; CHECK-LABEL: @_Z2p7bb(
247 ; CHECK-NEXT: [[MSTACKDATA:%.*]] = alloca [10 x i32], align 16
248 ; CHECK-NEXT: [[I2:%.*]] = select i1 [[B1:%.*]], ptr [[MSTACKDATA]], ptr @g6
249 ; CHECK-NEXT: [[I3:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
250 ; CHECK-NEXT: [[I4:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
251 ; CHECK-NEXT: [[DOTV:%.*]] = select i1 [[B2:%.*]], ptr [[I3]], ptr [[I4]]
252 ; CHECK-NEXT: [[I6:%.*]] = icmp eq ptr [[DOTV]], [[I2]]
253 ; CHECK-NEXT: br i1 [[I6]], label [[BB8:%.*]], label [[BB7:%.*]]
255 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I3]]) #[[ATTR3]]
256 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I4]]) #[[ATTR3]]
257 ; CHECK-NEXT: br label [[BB8]]
259 ; CHECK-NEXT: ret void
262 %mStackData = alloca [10 x i32], align 16
263 %i2 = select i1 %b1, ptr %mStackData, ptr @g6
264 %i3 = tail call noalias ptr @_Znam(i64 48) #3
265 %i4 = tail call noalias ptr @_Znam(i64 48) #3
266 %.v = select i1 %b2, ptr %i3, ptr %i4
267 %i6 = icmp eq ptr %.v, %i2
268 br i1 %i6, label %bb8, label %bb7
271 call void @_ZdaPv(ptr %i3) #4
272 call void @_ZdaPv(ptr %i4) #4
275 bb8: ; preds = %bb7, %bb
279 define void @_Z2p2v(i32 %c) {
280 ; CHECK-LABEL: @_Z2p2v(
282 ; CHECK-NEXT: [[MSTACKDATA:%.*]] = alloca [10 x i32], i32 [[C:%.*]], align 16
283 ; CHECK-NEXT: [[I1:%.*]] = tail call noalias ptr @_Znam(i64 48) #[[ATTR2]]
284 ; CHECK-NEXT: [[I4:%.*]] = icmp eq ptr [[I1]], [[MSTACKDATA]]
285 ; CHECK-NEXT: br i1 [[I4]], label [[BB6:%.*]], label [[BB5:%.*]]
287 ; CHECK-NEXT: call void @_ZdaPv(ptr [[I1]]) #[[ATTR3]]
288 ; CHECK-NEXT: br label [[BB6]]
290 ; CHECK-NEXT: ret void
293 %mStackData = alloca [10 x i32], i32 %c, align 16
294 %i1 = tail call noalias ptr @_Znam(i64 48) #3
295 %i4 = icmp eq ptr %i1, %mStackData
296 br i1 %i4, label %bb6, label %bb5
299 call void @_ZdaPv(ptr %i1) #4
302 bb6: ; preds = %bb5, %bb
306 ; Function Attrs: nobuiltin
307 declare noalias ptr @_Znam(i64) #1
309 ; Function Attrs: nobuiltin nounwind
310 declare void @_ZdaPv(ptr) #2
312 attributes #1 = { nobuiltin }
313 attributes #2 = { nobuiltin nounwind }
314 attributes #3 = { builtin }
315 attributes #4 = { builtin nounwind }