1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -mtriple x86_64--linux -instcombine -S | FileCheck %s
3 ; REQUIRES: x86-registered-target
6 ; 'if (p) delete p;' cannot result in a call to 'operator delete(0)'.
7 define void @test6a(i8* %foo) minsize {
8 ; CHECK-LABEL: @test6a(
10 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i8* [[FOO:%.*]], null
11 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
13 ; CHECK-NEXT: tail call void @_ZdlPv(i8* [[FOO]]) #[[ATTR5:[0-9]+]]
14 ; CHECK-NEXT: br label [[IF_END]]
16 ; CHECK-NEXT: ret void
19 %tobool = icmp eq i8* %foo, null
20 br i1 %tobool, label %if.end, label %if.then
22 if.then: ; preds = %entry
23 tail call void @_ZdlPv(i8* %foo) builtin
26 if.end: ; preds = %entry, %if.then
30 declare i8* @_ZnwmRKSt9nothrow_t(i64, i8*) nobuiltin
31 declare void @_ZdlPvRKSt9nothrow_t(i8*, i8*) nobuiltin
32 declare i32 @__gxx_personality_v0(...)
33 declare void @_ZN1AC2Ev(i8* %this)
35 define void @test7() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
36 ; CHECK-LABEL: @test7(
38 ; CHECK-NEXT: invoke void @_ZN1AC2Ev(i8* undef)
39 ; CHECK-NEXT: to label [[DOTNOEXC_I:%.*]] unwind label [[LPAD_I:%.*]]
41 ; CHECK-NEXT: unreachable
43 ; CHECK-NEXT: [[TMP0:%.*]] = landingpad { i8*, i32 }
45 ; CHECK-NEXT: resume { i8*, i32 } [[TMP0]]
49 %call.i = tail call i8* @_ZnwmRKSt9nothrow_t(i64 1, i8* %nt) builtin nounwind
50 invoke void @_ZN1AC2Ev(i8* undef)
51 to label %.noexc.i unwind label %lpad.i
53 .noexc.i: ; preds = %entry
56 lpad.i: ; preds = %entry
57 %0 = landingpad { i8*, i32 } cleanup
58 call void @_ZdlPvRKSt9nothrow_t(i8* %call.i, i8* %nt) builtin nounwind
59 resume { i8*, i32 } %0
62 declare i8* @_Znwm(i64) nobuiltin
63 define i8* @_Znwj(i32 %n) nobuiltin {
64 ; CHECK-LABEL: @_Znwj(
65 ; CHECK-NEXT: [[Z:%.*]] = zext i32 [[N:%.*]] to i64
66 ; CHECK-NEXT: [[M:%.*]] = call i8* @_Znwm(i64 [[Z]])
67 ; CHECK-NEXT: ret i8* [[M]]
69 %z = zext i32 %n to i64
70 %m = call i8* @_Znwm(i64 %z)
73 declare i8* @_Znam(i64) nobuiltin
74 declare i8* @_Znaj(i32) nobuiltin
75 declare void @_ZdlPv(i8*) nobuiltin
76 declare void @_ZdaPv(i8*) nobuiltin
78 define linkonce void @_ZdlPvm(i8* %p, i64) nobuiltin {
79 ; CHECK-LABEL: @_ZdlPvm(
80 ; CHECK-NEXT: call void @_ZdlPv(i8* [[P:%.*]])
81 ; CHECK-NEXT: ret void
83 call void @_ZdlPv(i8* %p)
86 define linkonce void @_ZdlPvj(i8* %p, i32) nobuiltin {
87 ; CHECK-LABEL: @_ZdlPvj(
88 ; CHECK-NEXT: call void @_ZdlPv(i8* [[P:%.*]])
89 ; CHECK-NEXT: ret void
91 call void @_ZdlPv(i8* %p)
94 define linkonce void @_ZdaPvm(i8* %p, i64) nobuiltin {
95 ; CHECK-LABEL: @_ZdaPvm(
96 ; CHECK-NEXT: call void @_ZdaPv(i8* [[P:%.*]])
97 ; CHECK-NEXT: ret void
99 call void @_ZdaPv(i8* %p)
102 define linkonce void @_ZdaPvj(i8* %p, i32) nobuiltin {
103 ; CHECK-LABEL: @_ZdaPvj(
104 ; CHECK-NEXT: call void @_ZdaPv(i8* [[P:%.*]])
105 ; CHECK-NEXT: ret void
107 call void @_ZdaPv(i8* %p)
112 ; new(size_t, align_val_t)
113 declare i8* @_ZnwmSt11align_val_t(i64, i64) nobuiltin
114 declare i8* @_ZnwjSt11align_val_t(i32, i32) nobuiltin
115 ; new[](size_t, align_val_t)
116 declare i8* @_ZnamSt11align_val_t(i64, i64) nobuiltin
117 declare i8* @_ZnajSt11align_val_t(i32, i32) nobuiltin
118 ; new(size_t, align_val_t, nothrow)
119 declare i8* @_ZnwmSt11align_val_tRKSt9nothrow_t(i64, i64, i8*) nobuiltin
120 declare i8* @_ZnwjSt11align_val_tRKSt9nothrow_t(i32, i32, i8*) nobuiltin
121 ; new[](size_t, align_val_t, nothrow)
122 declare i8* @_ZnamSt11align_val_tRKSt9nothrow_t(i64, i64, i8*) nobuiltin
123 declare i8* @_ZnajSt11align_val_tRKSt9nothrow_t(i32, i32, i8*) nobuiltin
124 ; delete(void*, align_val_t)
125 declare void @_ZdlPvSt11align_val_t(i8*, i64) nobuiltin
126 ; delete[](void*, align_val_t)
127 declare void @_ZdaPvSt11align_val_t(i8*, i64) nobuiltin
128 ; delete(void*, align_val_t, nothrow)
129 declare void @_ZdlPvSt11align_val_tRKSt9nothrow_t(i8*, i64, i8*) nobuiltin
130 ; delete[](void*, align_val_t, nothrow)
131 declare void @_ZdaPvSt11align_val_tRKSt9nothrow_t(i8*, i64, i8*) nobuiltin
132 ; delete(void*, unsigned int, align_val_t)
133 declare void @_ZdlPvjSt11align_val_t(i8*, i32, i32) nobuiltin
134 ; delete(void*, unsigned long, align_val_t)
135 declare void @_ZdlPvmSt11align_val_t(i8*, i64, i64) nobuiltin
136 ; delete[](void*, unsigned int, align_val_t)
137 declare void @_ZdaPvjSt11align_val_t(i8*, i32, i32) nobuiltin
138 ; delete[](void*, unsigned long, align_val_t)
139 declare void @_ZdaPvmSt11align_val_t(i8*, i64, i64) nobuiltin
141 declare void @llvm.assume(i1)
143 define void @test8() {
144 ; CHECK-LABEL: @test8(
145 ; CHECK-NEXT: ret void
148 %nw = call i8* @_Znwm(i64 32) builtin
149 call void @_ZdlPv(i8* %nw) builtin
150 %na = call i8* @_Znam(i64 32) builtin
151 call void @_ZdaPv(i8* %na) builtin
152 %nwm = call i8* @_Znwm(i64 32) builtin
153 call void @_ZdlPvm(i8* %nwm, i64 32) builtin
154 %nwj = call i8* @_Znwj(i32 32) builtin
155 call void @_ZdlPvj(i8* %nwj, i32 32) builtin
156 %nam = call i8* @_Znam(i64 32) builtin
157 call void @_ZdaPvm(i8* %nam, i64 32) builtin
158 %naj = call i8* @_Znaj(i32 32) builtin
159 call void @_ZdaPvj(i8* %naj, i32 32) builtin
160 %nwa = call i8* @_ZnwmSt11align_val_t(i64 32, i64 8) builtin
161 call void @_ZdlPvSt11align_val_t(i8* %nwa, i64 8) builtin
162 %naa = call i8* @_ZnamSt11align_val_t(i64 32, i64 8) builtin
163 call void @_ZdaPvSt11align_val_t(i8* %naa, i64 8) builtin
164 %nwja = call i8* @_ZnwjSt11align_val_t(i32 32, i32 8) builtin
165 call void @_ZdlPvSt11align_val_t(i8* %nwja, i64 8) builtin
166 %naja = call i8* @_ZnajSt11align_val_t(i32 32, i32 8) builtin
167 call void @_ZdaPvSt11align_val_t(i8* %naja, i64 8) builtin
168 %nwat = call i8* @_ZnwmSt11align_val_tRKSt9nothrow_t(i64 32, i64 8, i8* %nt) builtin
169 call void @_ZdlPvSt11align_val_tRKSt9nothrow_t(i8* %nwat, i64 8, i8* %nt) builtin
170 %naat = call i8* @_ZnamSt11align_val_tRKSt9nothrow_t(i64 32, i64 8, i8* %nt) builtin
171 call void @_ZdaPvSt11align_val_tRKSt9nothrow_t(i8* %naat, i64 8, i8* %nt) builtin
172 %nwjat = call i8* @_ZnwjSt11align_val_tRKSt9nothrow_t(i32 32, i32 8, i8* %nt) builtin
173 call void @_ZdlPvSt11align_val_tRKSt9nothrow_t(i8* %nwjat, i64 8, i8* %nt) builtin
174 %najat = call i8* @_ZnajSt11align_val_tRKSt9nothrow_t(i32 32, i32 8, i8* %nt) builtin
175 call void @_ZdaPvSt11align_val_tRKSt9nothrow_t(i8* %najat, i64 8, i8* %nt) builtin
176 %nwa2 = call i8* @_ZnwmSt11align_val_t(i64 32, i64 8) builtin
177 call void @_ZdlPvmSt11align_val_t(i8* %nwa2, i64 32, i64 8) builtin
178 %nwja2 = call i8* @_ZnwjSt11align_val_t(i32 32, i32 8) builtin
179 call void @_ZdlPvjSt11align_val_t(i8* %nwa2, i32 32, i32 8) builtin
180 %naa2 = call i8* @_ZnamSt11align_val_t(i64 32, i64 8) builtin
181 call void @_ZdaPvmSt11align_val_t(i8* %naa2, i64 32, i64 8) builtin
182 %naja2 = call i8* @_ZnajSt11align_val_t(i32 32, i32 8) builtin
183 call void @_ZdaPvjSt11align_val_t(i8* %naja2, i32 32, i32 8) builtin
185 ; Check that the alignment assume does not prevent the removal.
186 %nwa3 = call i8* @_ZnwmSt11align_val_t(i64 32, i64 16) builtin
187 call void @llvm.assume(i1 true) [ "align"(i8* %nwa3, i64 16) ]
188 call void @_ZdlPvmSt11align_val_t(i8* %nwa3, i64 32, i64 16) builtin
193 define void @test10() {
194 ; CHECK-LABEL: @test10(
195 ; CHECK-NEXT: call void @_ZdlPv(i8* null)
196 ; CHECK-NEXT: ret void
198 call void @_ZdlPv(i8* null)
202 define void @test11() {
203 ; CHECK-LABEL: @test11(
204 ; CHECK-NEXT: [[CALL:%.*]] = call dereferenceable_or_null(8) i8* @_Znwm(i64 8) #[[ATTR5]]
205 ; CHECK-NEXT: call void @_ZdlPv(i8* [[CALL]])
206 ; CHECK-NEXT: ret void
208 %call = call i8* @_Znwm(i64 8) builtin
209 call void @_ZdlPv(i8* %call)
213 declare i8* @llvm.launder.invariant.group(i8*)
214 declare i8* @llvm.strip.invariant.group(i8*)
216 define void @test17() {
217 ; CHECK-LABEL: @test17(
218 ; CHECK-NEXT: ret void
220 %nw1 = call i8* @_Znwm(i64 32) builtin
221 %nw2 = call i8* @llvm.launder.invariant.group(i8* %nw1)
222 %nw3 = call i8* @llvm.strip.invariant.group(i8* %nw2)
224 call void @_ZdlPv(i8* %nw2) builtin