1 ; RUN: opt -instsimplify -S < %s | FileCheck %s
2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-unknown-linux-gnu"
5 @g1 = global i32 0, align 4
6 @g2 = internal global i32 0, align 4
7 @g3 = unnamed_addr global i32 0, align 4
8 @g4 = hidden global i32 0, align 4
9 @g5 = protected global i32 0, align 4
10 @g6 = thread_local unnamed_addr global i32 0, align 4
12 ; Make sure we can simplify away a pointer comparison between
13 ; dynamically-allocated memory and a local stack allocation.
18 ; mData = new int[12];
19 ; if (mData != mStackData) {
24 define void @_Z2p1v() #0 {
25 %mStackData = alloca [10 x i32], align 16
26 %1 = bitcast [10 x i32]* %mStackData to i8*
27 %2 = tail call noalias i8* @_Znam(i64 48) #4
28 %3 = bitcast i8* %2 to i32*
29 %4 = getelementptr inbounds [10 x i32], [10 x i32]* %mStackData, i64 0, i64 0
30 %5 = icmp eq i32* %3, %4
31 br i1 %5, label %7, label %6
33 ; CHECK-LABEL: @_Z2p1v
37 ; <label>:6 ; preds = %0
38 call void @_ZdaPv(i8* %2) #5
41 ; <label>:7 ; preds = %0, %6
45 ; Also check a more-complicated case with multiple underlying objects.
47 define void @_Z2p2bb(i1 zeroext %b1, i1 zeroext %b2) #0 {
48 %mStackData = alloca [10 x i32], align 16
49 %1 = bitcast [10 x i32]* %mStackData to i8*
50 %2 = getelementptr inbounds [10 x i32], [10 x i32]* %mStackData, i64 0, i64 0
51 %3 = select i1 %b1, i32* %2, i32* @g2
52 %4 = tail call noalias i8* @_Znam(i64 48) #4
53 %5 = tail call noalias i8* @_Znam(i64 48) #4
54 %.v = select i1 %b2, i8* %4, i8* %5
55 %6 = bitcast i8* %.v to i32*
56 %7 = icmp eq i32* %6, %3
57 br i1 %7, label %9, label %8
59 ; CHECK-LABEL: @_Z2p2bb
63 ; <label>:8 ; preds = %0
64 call void @_ZdaPv(i8* %4) #5
65 call void @_ZdaPv(i8* %5) #5
68 ; <label>:9 ; preds = %0, %8
72 define void @_Z2p4bb(i1 zeroext %b1, i1 zeroext %b2) #0 {
73 %mStackData = alloca [10 x i32], align 16
74 %1 = bitcast [10 x i32]* %mStackData to i8*
75 %2 = getelementptr inbounds [10 x i32], [10 x i32]* %mStackData, i64 0, i64 0
76 %3 = select i1 %b1, i32* %2, i32* @g3
77 %4 = tail call noalias i8* @_Znam(i64 48) #4
78 %5 = tail call noalias i8* @_Znam(i64 48) #4
79 %.v = select i1 %b2, i8* %4, i8* %5
80 %6 = bitcast i8* %.v to i32*
81 %7 = icmp eq i32* %6, %3
82 br i1 %7, label %9, label %8
84 ; CHECK-LABEL: @_Z2p4bb
88 ; <label>:8 ; preds = %0
89 call void @_ZdaPv(i8* %4) #5
90 call void @_ZdaPv(i8* %5) #5
93 ; <label>:9 ; preds = %0, %8
97 define void @_Z2p5bb(i1 zeroext %b1, i1 zeroext %b2) #0 {
98 %mStackData = alloca [10 x i32], align 16
99 %1 = bitcast [10 x i32]* %mStackData to i8*
100 %2 = getelementptr inbounds [10 x i32], [10 x i32]* %mStackData, i64 0, i64 0
101 %3 = select i1 %b1, i32* %2, i32* @g4
102 %4 = tail call noalias i8* @_Znam(i64 48) #4
103 %5 = tail call noalias i8* @_Znam(i64 48) #4
104 %.v = select i1 %b2, i8* %4, i8* %5
105 %6 = bitcast i8* %.v to i32*
106 %7 = icmp eq i32* %6, %3
107 br i1 %7, label %9, label %8
109 ; CHECK-LABEL: @_Z2p5bb
113 ; <label>:8 ; preds = %0
114 call void @_ZdaPv(i8* %4) #5
115 call void @_ZdaPv(i8* %5) #5
118 ; <label>:9 ; preds = %0, %8
122 define void @_Z2p6bb(i1 zeroext %b1, i1 zeroext %b2) #0 {
123 %mStackData = alloca [10 x i32], align 16
124 %1 = bitcast [10 x i32]* %mStackData to i8*
125 %2 = getelementptr inbounds [10 x i32], [10 x i32]* %mStackData, i64 0, i64 0
126 %3 = select i1 %b1, i32* %2, i32* @g5
127 %4 = tail call noalias i8* @_Znam(i64 48) #4
128 %5 = tail call noalias i8* @_Znam(i64 48) #4
129 %.v = select i1 %b2, i8* %4, i8* %5
130 %6 = bitcast i8* %.v to i32*
131 %7 = icmp eq i32* %6, %3
132 br i1 %7, label %9, label %8
134 ; CHECK-LABEL: @_Z2p6bb
138 ; <label>:8 ; preds = %0
139 call void @_ZdaPv(i8* %4) #5
140 call void @_ZdaPv(i8* %5) #5
143 ; <label>:9 ; preds = %0, %8
147 ; Here's another case involving multiple underlying objects, but this time we
148 ; must keep the comparison (it might involve a regular pointer-typed function
151 define void @_Z4nopebbPi(i1 zeroext %b1, i1 zeroext %b2, i32* readnone %q) #0 {
152 %mStackData = alloca [10 x i32], align 16
153 %1 = bitcast [10 x i32]* %mStackData to i8*
154 %2 = getelementptr inbounds [10 x i32], [10 x i32]* %mStackData, i64 0, i64 0
155 %3 = select i1 %b1, i32* %2, i32* %q
156 %4 = tail call noalias i8* @_Znam(i64 48) #4
157 %5 = tail call noalias i8* @_Znam(i64 48) #4
158 %.v = select i1 %b2, i8* %4, i8* %5
159 %6 = bitcast i8* %.v to i32*
160 %7 = icmp eq i32* %6, %3
161 br i1 %7, label %9, label %8
163 ; CHECK-LABEL: @_Z4nopebbPi
167 ; <label>:8 ; preds = %0
168 call void @_ZdaPv(i8* %4) #5
169 call void @_ZdaPv(i8* %5) #5
172 ; <label>:9 ; preds = %0, %8
176 define void @_Z2p3bb(i1 zeroext %b1, i1 zeroext %b2) #0 {
177 %mStackData = alloca [10 x i32], align 16
178 %1 = bitcast [10 x i32]* %mStackData to i8*
179 %2 = getelementptr inbounds [10 x i32], [10 x i32]* %mStackData, i64 0, i64 0
180 %3 = select i1 %b1, i32* %2, i32* @g1
181 %4 = tail call noalias i8* @_Znam(i64 48) #4
182 %5 = tail call noalias i8* @_Znam(i64 48) #4
183 %.v = select i1 %b2, i8* %4, i8* %5
184 %6 = bitcast i8* %.v to i32*
185 %7 = icmp eq i32* %6, %3
186 br i1 %7, label %9, label %8
188 ; CHECK-LABEL: @_Z2p3bb
192 ; <label>:8 ; preds = %0
193 call void @_ZdaPv(i8* %4) #5
194 call void @_ZdaPv(i8* %5) #5
197 ; <label>:9 ; preds = %0, %8
201 define void @_Z2p7bb(i1 zeroext %b1, i1 zeroext %b2) #0 {
202 %mStackData = alloca [10 x i32], align 16
203 %1 = bitcast [10 x i32]* %mStackData to i8*
204 %2 = getelementptr inbounds [10 x i32], [10 x i32]* %mStackData, i64 0, i64 0
205 %3 = select i1 %b1, i32* %2, i32* @g6
206 %4 = tail call noalias i8* @_Znam(i64 48) #4
207 %5 = tail call noalias i8* @_Znam(i64 48) #4
208 %.v = select i1 %b2, i8* %4, i8* %5
209 %6 = bitcast i8* %.v to i32*
210 %7 = icmp eq i32* %6, %3
211 br i1 %7, label %9, label %8
213 ; CHECK-LABEL: @_Z2p7bb
217 ; <label>:8 ; preds = %0
218 call void @_ZdaPv(i8* %4) #5
219 call void @_ZdaPv(i8* %5) #5
222 ; <label>:9 ; preds = %0, %8
226 define void @_Z2p2v(i32 %c) #0 {
227 %mStackData = alloca [10 x i32], i32 %c, align 16
228 %1 = bitcast [10 x i32]* %mStackData to i8*
229 %2 = tail call noalias i8* @_Znam(i64 48) #4
230 %3 = bitcast i8* %2 to i32*
231 %4 = getelementptr inbounds [10 x i32], [10 x i32]* %mStackData, i64 0, i64 0
232 %5 = icmp eq i32* %3, %4
233 br i1 %5, label %7, label %6
235 ; CHECK-LABEL: @_Z2p2v
239 ; <label>:6 ; preds = %0
240 call void @_ZdaPv(i8* %2) #5
243 ; <label>:7 ; preds = %0, %6
247 ; Function Attrs: nobuiltin
248 declare noalias i8* @_Znam(i64) #2
250 ; Function Attrs: nobuiltin nounwind
251 declare void @_ZdaPv(i8*) #3
253 attributes #0 = { uwtable }
254 attributes #1 = { nounwind }
255 attributes #2 = { nobuiltin }
256 attributes #3 = { nobuiltin nounwind }
257 attributes #4 = { builtin }
258 attributes #5 = { builtin nounwind }