1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 ; Set pointer (and size_t) size to 32 bits. This lets the declarations
5 ; below and calls to them be recognized as special.
7 target datalayout = "p:32:32"
10 %align_val_t = type %size_t
14 ; operator new(size_t = unsigned int)
15 declare ptr @_Znwj(%size_t)
17 ; operator new[](size_t = unsigned int)
18 declare ptr @_Znaj(%size_t)
20 ; operator new(size_t = unsigned int, std::align_val_t)
21 declare ptr @_ZnwjSt11align_val_t(%size_t, %size_t)
23 ; operator new[](size_t = unsigned int, std::align_val_t)
24 declare ptr @_ZnajSt11align_val_t(%size_t, %size_t)
26 ; operator new(size_t = unsigned int, std::align_val_t, const std::nothrow_t&)
27 declare ptr @_ZnwjSt11align_val_tRKSt9nothrow_t(%size_t, %size_t, ptr)
29 ; operator new[](size_t = unsigned int, std::align_val_t, const std::nothrow_t&)
30 declare ptr @_ZnajSt11align_val_tRKSt9nothrow_t(%size_t, %size_t, ptr)
33 ; operator delete(ptr, size_t = unsigned int)
34 declare void @_ZdlPvj(ptr, %size_t)
36 ; operator delete[](ptr, size_t = unsigned int)
37 declare void @_ZdaPvj(ptr, %size_t)
39 ; operator delete(ptr, std::align_val_t)
40 declare void @_ZdlPvSt11align_val_t(ptr, %align_val_t)
42 ; operator delete[](ptr, std::align_val_t)
43 declare void @_ZdaPvSt11align_val_t(ptr, %align_val_t)
45 ; operator delete(ptr, size_t = unsigned int, std::align_val_t)
46 declare void @_ZdlPvjSt11align_val_t(ptr, %size_t, %align_val_t)
48 ; operator delete[](ptr, size_t = unsigned int, std::align_val_t)
49 declare void @_ZdaPvjSt11align_val_t(ptr, %size_t, %align_val_t)
51 ; operator delete(ptr, std::align_val_t, const std::nothrow_t&)
52 declare void @_ZdlPvSt11align_val_tRKSt9nothrow_t(ptr, %align_val_t, ptr)
54 ; operator delete[](ptr, std::align_val_t, const std::nothrow_t&)
55 declare void @_ZdaPvSt11align_val_tRKSt9nothrow_t(ptr, %align_val_t, ptr)
57 declare void @llvm.assume(i1)
60 ; Verify that pairs of matching calls to new/delete are eliminated.
62 define void @elim_new_delete_pairs() {
63 ; CHECK-LABEL: @elim_new_delete_pairs(
64 ; CHECK-NEXT: ret void
66 %nt = alloca %nothrow_t
68 %nwj = call ptr @_Znwj(%size_t 32)
69 call void @_ZdlPvj(ptr %nwj, %size_t 32)
71 %naj = call ptr @_Znaj(%size_t 32)
72 call void @_ZdaPvj(ptr %naj, %size_t 32)
74 %nwja = call ptr @_ZnwjSt11align_val_t(%size_t 32, %size_t 8)
75 call void @_ZdlPvSt11align_val_t(ptr %nwja, %size_t 8)
77 %naja = call ptr @_ZnajSt11align_val_t(%size_t 32, %size_t 8)
78 call void @_ZdaPvSt11align_val_t(ptr %naja, i32 8)
80 %nwjat = call ptr @_ZnwjSt11align_val_tRKSt9nothrow_t(%size_t 32, %size_t 8, ptr %nt)
81 call void @_ZdlPvSt11align_val_tRKSt9nothrow_t(ptr %nwjat, %size_t 8, ptr %nt)
83 %najat = call ptr @_ZnajSt11align_val_tRKSt9nothrow_t(%size_t 32, %size_t 8, ptr %nt)
84 call void @_ZdaPvSt11align_val_tRKSt9nothrow_t(ptr %najat, i32 8, ptr %nt)
86 %nwja2 = call ptr @_ZnwjSt11align_val_t(%size_t 32, %size_t 8)
87 call void @_ZdlPvjSt11align_val_t(ptr %nwja2, %size_t 32, %size_t 8)
89 %naja2 = call ptr @_ZnajSt11align_val_t(%size_t 32, %size_t 8)
90 call void @_ZdaPvjSt11align_val_t(ptr %naja2, %size_t 32, %size_t 8)
92 ; Check that the alignment assume does not prevent the removal.
93 %nwa3 = call ptr @_ZnajSt11align_val_t(%size_t 32, %size_t 16)
95 call void @llvm.assume(i1 true) [ "align"(ptr %nwa3, i32 16) ]
97 call void @_ZdaPvjSt11align_val_t(ptr %nwa3, %size_t 32, %size_t 16)