1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
4 declare noalias i8* @malloc(i64)
5 declare noalias i8* @calloc(i64, i64)
6 declare noalias i8* @realloc(i8* nocapture, i64)
7 declare noalias nonnull i8* @_Znam(i64) ; throwing version of 'new'
8 declare noalias nonnull i8* @_Znwm(i64) ; throwing version of 'new'
10 define noalias i8* @malloc_nonconstant_size(i64 %n) {
11 ; CHECK-LABEL: @malloc_nonconstant_size(
12 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @malloc(i64 [[N:%.*]])
13 ; CHECK-NEXT: ret i8* [[CALL]]
15 %call = tail call noalias i8* @malloc(i64 %n)
19 define noalias i8* @malloc_constant_size() {
20 ; CHECK-LABEL: @malloc_constant_size(
21 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias dereferenceable_or_null(40) i8* @malloc(i64 40)
22 ; CHECK-NEXT: ret i8* [[CALL]]
24 %call = tail call noalias i8* @malloc(i64 40)
28 define noalias i8* @malloc_constant_size2() {
29 ; CHECK-LABEL: @malloc_constant_size2(
30 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias dereferenceable_or_null(80) i8* @malloc(i64 40)
31 ; CHECK-NEXT: ret i8* [[CALL]]
33 %call = tail call noalias dereferenceable_or_null(80) i8* @malloc(i64 40)
37 define noalias i8* @malloc_constant_size3() {
38 ; CHECK-LABEL: @malloc_constant_size3(
39 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias dereferenceable(80) dereferenceable_or_null(40) i8* @malloc(i64 40)
40 ; CHECK-NEXT: ret i8* [[CALL]]
42 %call = tail call noalias dereferenceable(80) i8* @malloc(i64 40)
47 define noalias i8* @malloc_constant_zero_size() {
48 ; CHECK-LABEL: @malloc_constant_zero_size(
49 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @malloc(i64 0)
50 ; CHECK-NEXT: ret i8* [[CALL]]
52 %call = tail call noalias i8* @malloc(i64 0)
56 define noalias i8* @realloc_nonconstant_size(i8* %p, i64 %n) {
57 ; CHECK-LABEL: @realloc_nonconstant_size(
58 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @realloc(i8* [[P:%.*]], i64 [[N:%.*]])
59 ; CHECK-NEXT: ret i8* [[CALL]]
61 %call = tail call noalias i8* @realloc(i8* %p, i64 %n)
65 define noalias i8* @realloc_constant_zero_size(i8* %p) {
66 ; CHECK-LABEL: @realloc_constant_zero_size(
67 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @realloc(i8* [[P:%.*]], i64 0)
68 ; CHECK-NEXT: ret i8* [[CALL]]
70 %call = tail call noalias i8* @realloc(i8* %p, i64 0)
74 define noalias i8* @realloc_constant_size(i8* %p) {
75 ; CHECK-LABEL: @realloc_constant_size(
76 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias dereferenceable_or_null(40) i8* @realloc(i8* [[P:%.*]], i64 40)
77 ; CHECK-NEXT: ret i8* [[CALL]]
79 %call = tail call noalias i8* @realloc(i8* %p, i64 40)
83 define noalias i8* @calloc_nonconstant_size(i64 %n) {
84 ; CHECK-LABEL: @calloc_nonconstant_size(
85 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 1, i64 [[N:%.*]])
86 ; CHECK-NEXT: ret i8* [[CALL]]
88 %call = tail call noalias i8* @calloc(i64 1, i64 %n)
92 define noalias i8* @calloc_nonconstant_size2(i64 %n) {
93 ; CHECK-LABEL: @calloc_nonconstant_size2(
94 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 [[N:%.*]], i64 0)
95 ; CHECK-NEXT: ret i8* [[CALL]]
97 %call = tail call noalias i8* @calloc(i64 %n, i64 0)
101 define noalias i8* @calloc_nonconstant_size3(i64 %n) {
102 ; CHECK-LABEL: @calloc_nonconstant_size3(
103 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 [[N:%.*]], i64 [[N]])
104 ; CHECK-NEXT: ret i8* [[CALL]]
106 %call = tail call noalias i8* @calloc(i64 %n, i64 %n)
110 define noalias i8* @calloc_constant_zero_size() {
111 ; CHECK-LABEL: @calloc_constant_zero_size(
112 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 0, i64 0)
113 ; CHECK-NEXT: ret i8* [[CALL]]
115 %call = tail call noalias i8* @calloc(i64 0, i64 0)
119 define noalias i8* @calloc_constant_zero_size2(i64 %n) {
120 ; CHECK-LABEL: @calloc_constant_zero_size2(
121 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 [[N:%.*]], i64 0)
122 ; CHECK-NEXT: ret i8* [[CALL]]
124 %call = tail call noalias i8* @calloc(i64 %n, i64 0)
129 define noalias i8* @calloc_constant_zero_size3(i64 %n) {
130 ; CHECK-LABEL: @calloc_constant_zero_size3(
131 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 0, i64 [[N:%.*]])
132 ; CHECK-NEXT: ret i8* [[CALL]]
134 %call = tail call noalias i8* @calloc(i64 0, i64 %n)
138 define noalias i8* @calloc_constant_zero_size4(i64 %n) {
139 ; CHECK-LABEL: @calloc_constant_zero_size4(
140 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 0, i64 1)
141 ; CHECK-NEXT: ret i8* [[CALL]]
143 %call = tail call noalias i8* @calloc(i64 0, i64 1)
147 define noalias i8* @calloc_constant_zero_size5(i64 %n) {
148 ; CHECK-LABEL: @calloc_constant_zero_size5(
149 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 1, i64 0)
150 ; CHECK-NEXT: ret i8* [[CALL]]
152 %call = tail call noalias i8* @calloc(i64 1, i64 0)
156 define noalias i8* @calloc_constant_size() {
157 ; CHECK-LABEL: @calloc_constant_size(
158 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias dereferenceable_or_null(128) i8* @calloc(i64 16, i64 8)
159 ; CHECK-NEXT: ret i8* [[CALL]]
161 %call = tail call noalias i8* @calloc(i64 16, i64 8)
165 define noalias i8* @calloc_constant_size_overflow() {
166 ; CHECK-LABEL: @calloc_constant_size_overflow(
167 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 2000000000000, i64 80000000000)
168 ; CHECK-NEXT: ret i8* [[CALL]]
170 %call = tail call noalias i8* @calloc(i64 2000000000000, i64 80000000000)
174 define noalias i8* @op_new_nonconstant_size(i64 %n) {
175 ; CHECK-LABEL: @op_new_nonconstant_size(
176 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @_Znam(i64 [[N:%.*]])
177 ; CHECK-NEXT: ret i8* [[CALL]]
179 %call = tail call i8* @_Znam(i64 %n)
183 define noalias i8* @op_new_constant_size() {
184 ; CHECK-LABEL: @op_new_constant_size(
185 ; CHECK-NEXT: [[CALL:%.*]] = tail call dereferenceable(40) i8* @_Znam(i64 40)
186 ; CHECK-NEXT: ret i8* [[CALL]]
188 %call = tail call i8* @_Znam(i64 40)
192 define noalias i8* @op_new_constant_size2() {
193 ; CHECK-LABEL: @op_new_constant_size2(
194 ; CHECK-NEXT: [[CALL:%.*]] = tail call dereferenceable(40) i8* @_Znwm(i64 40)
195 ; CHECK-NEXT: ret i8* [[CALL]]
197 %call = tail call i8* @_Znwm(i64 40)
201 define noalias i8* @op_new_constant_zero_size() {
202 ; CHECK-LABEL: @op_new_constant_zero_size(
203 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @_Znam(i64 0)
204 ; CHECK-NEXT: ret i8* [[CALL]]
206 %call = tail call i8* @_Znam(i64 0)