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'
9 define noalias i8* @malloc_nonconstant_size(i64 %n) {
10 ; CHECK-LABEL: @malloc_nonconstant_size(
11 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @malloc(i64 [[N:%.*]])
12 ; CHECK-NEXT: ret i8* [[CALL]]
14 %call = tail call noalias i8* @malloc(i64 %n)
18 define noalias i8* @malloc_constant_size() {
19 ; CHECK-LABEL: @malloc_constant_size(
20 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias dereferenceable_or_null(40) i8* @malloc(i64 40)
21 ; CHECK-NEXT: ret i8* [[CALL]]
23 %call = tail call noalias i8* @malloc(i64 40)
27 define noalias i8* @malloc_constant_size2() {
28 ; CHECK-LABEL: @malloc_constant_size2(
29 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias dereferenceable_or_null(80) i8* @malloc(i64 40)
30 ; CHECK-NEXT: ret i8* [[CALL]]
32 %call = tail call noalias dereferenceable_or_null(80) i8* @malloc(i64 40)
36 define noalias i8* @malloc_constant_size3() {
37 ; CHECK-LABEL: @malloc_constant_size3(
38 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias dereferenceable(80) dereferenceable_or_null(40) i8* @malloc(i64 40)
39 ; CHECK-NEXT: ret i8* [[CALL]]
41 %call = tail call noalias dereferenceable(80) i8* @malloc(i64 40)
46 define noalias i8* @malloc_constant_zero_size() {
47 ; CHECK-LABEL: @malloc_constant_zero_size(
48 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @malloc(i64 0)
49 ; CHECK-NEXT: ret i8* [[CALL]]
51 %call = tail call noalias i8* @malloc(i64 0)
55 define noalias i8* @realloc_nonconstant_size(i8* %p, i64 %n) {
56 ; CHECK-LABEL: @realloc_nonconstant_size(
57 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @realloc(i8* [[P:%.*]], i64 [[N:%.*]])
58 ; CHECK-NEXT: ret i8* [[CALL]]
60 %call = tail call noalias i8* @realloc(i8* %p, i64 %n)
64 define noalias i8* @realloc_constant_zero_size(i8* %p) {
65 ; CHECK-LABEL: @realloc_constant_zero_size(
66 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @realloc(i8* [[P:%.*]], i64 0)
67 ; CHECK-NEXT: ret i8* [[CALL]]
69 %call = tail call noalias i8* @realloc(i8* %p, i64 0)
73 define noalias i8* @realloc_constant_size(i8* %p) {
74 ; CHECK-LABEL: @realloc_constant_size(
75 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias dereferenceable_or_null(40) i8* @realloc(i8* [[P:%.*]], i64 40)
76 ; CHECK-NEXT: ret i8* [[CALL]]
78 %call = tail call noalias i8* @realloc(i8* %p, i64 40)
82 define noalias i8* @calloc_nonconstant_size(i64 %n) {
83 ; CHECK-LABEL: @calloc_nonconstant_size(
84 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 1, i64 [[N:%.*]])
85 ; CHECK-NEXT: ret i8* [[CALL]]
87 %call = tail call noalias i8* @calloc(i64 1, i64 %n)
91 define noalias i8* @calloc_nonconstant_size2(i64 %n) {
92 ; CHECK-LABEL: @calloc_nonconstant_size2(
93 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 [[N:%.*]], i64 0)
94 ; CHECK-NEXT: ret i8* [[CALL]]
96 %call = tail call noalias i8* @calloc(i64 %n, i64 0)
100 define noalias i8* @calloc_nonconstant_size3(i64 %n) {
101 ; CHECK-LABEL: @calloc_nonconstant_size3(
102 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 [[N:%.*]], i64 [[N]])
103 ; CHECK-NEXT: ret i8* [[CALL]]
105 %call = tail call noalias i8* @calloc(i64 %n, i64 %n)
109 define noalias i8* @calloc_constant_zero_size() {
110 ; CHECK-LABEL: @calloc_constant_zero_size(
111 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 0, i64 0)
112 ; CHECK-NEXT: ret i8* [[CALL]]
114 %call = tail call noalias i8* @calloc(i64 0, i64 0)
118 define noalias i8* @calloc_constant_zero_size2(i64 %n) {
119 ; CHECK-LABEL: @calloc_constant_zero_size2(
120 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 [[N:%.*]], i64 0)
121 ; CHECK-NEXT: ret i8* [[CALL]]
123 %call = tail call noalias i8* @calloc(i64 %n, i64 0)
128 define noalias i8* @calloc_constant_zero_size3(i64 %n) {
129 ; CHECK-LABEL: @calloc_constant_zero_size3(
130 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 0, i64 [[N:%.*]])
131 ; CHECK-NEXT: ret i8* [[CALL]]
133 %call = tail call noalias i8* @calloc(i64 0, i64 %n)
137 define noalias i8* @calloc_constant_zero_size4(i64 %n) {
138 ; CHECK-LABEL: @calloc_constant_zero_size4(
139 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 0, i64 1)
140 ; CHECK-NEXT: ret i8* [[CALL]]
142 %call = tail call noalias i8* @calloc(i64 0, i64 1)
146 define noalias i8* @calloc_constant_zero_size5(i64 %n) {
147 ; CHECK-LABEL: @calloc_constant_zero_size5(
148 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 1, i64 0)
149 ; CHECK-NEXT: ret i8* [[CALL]]
151 %call = tail call noalias i8* @calloc(i64 1, i64 0)
155 define noalias i8* @calloc_constant_size() {
156 ; CHECK-LABEL: @calloc_constant_size(
157 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias dereferenceable_or_null(128) i8* @calloc(i64 16, i64 8)
158 ; CHECK-NEXT: ret i8* [[CALL]]
160 %call = tail call noalias i8* @calloc(i64 16, i64 8)
164 define noalias i8* @calloc_constant_size_overflow() {
165 ; CHECK-LABEL: @calloc_constant_size_overflow(
166 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @calloc(i64 2000000000000, i64 80000000000)
167 ; CHECK-NEXT: ret i8* [[CALL]]
169 %call = tail call noalias i8* @calloc(i64 2000000000000, i64 80000000000)
173 define noalias i8* @op_new_nonconstant_size(i64 %n) {
174 ; CHECK-LABEL: @op_new_nonconstant_size(
175 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @_Znam(i64 [[N:%.*]])
176 ; CHECK-NEXT: ret i8* [[CALL]]
178 %call = tail call i8* @_Znam(i64 %n)
182 define noalias i8* @op_new_constant_size() {
183 ; CHECK-LABEL: @op_new_constant_size(
184 ; CHECK-NEXT: [[CALL:%.*]] = tail call dereferenceable_or_null(40) i8* @_Znam(i64 40)
185 ; CHECK-NEXT: ret i8* [[CALL]]
187 %call = tail call i8* @_Znam(i64 40)
191 define noalias i8* @op_new_constant_zero_size() {
192 ; CHECK-LABEL: @op_new_constant_zero_size(
193 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @_Znam(i64 0)
194 ; CHECK-NEXT: ret i8* [[CALL]]
196 %call = tail call i8* @_Znam(i64 0)