[InstCombine] Signed saturation patterns
[llvm-core.git] / test / Transforms / InstCombine / deref-alloc-fns.ll
blobefaf1cd1604d5eb29946c51e6ae4bf3acd4ec477
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'
9 declare noalias i8* @strdup(i8*)
11 @.str = private unnamed_addr constant [6 x i8] c"hello\00", align 1
13 define noalias i8* @malloc_nonconstant_size(i64 %n) {
14 ; CHECK-LABEL: @malloc_nonconstant_size(
15 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias i8* @malloc(i64 [[N:%.*]])
16 ; CHECK-NEXT:    ret i8* [[CALL]]
18   %call = tail call noalias i8* @malloc(i64 %n)
19   ret i8* %call
22 define noalias i8* @malloc_constant_size() {
23 ; CHECK-LABEL: @malloc_constant_size(
24 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias dereferenceable_or_null(40) i8* @malloc(i64 40)
25 ; CHECK-NEXT:    ret i8* [[CALL]]
27   %call = tail call noalias i8* @malloc(i64 40)
28   ret i8* %call
31 define noalias i8* @malloc_constant_size2() {
32 ; CHECK-LABEL: @malloc_constant_size2(
33 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias dereferenceable_or_null(80) i8* @malloc(i64 40)
34 ; CHECK-NEXT:    ret i8* [[CALL]]
36   %call = tail call noalias dereferenceable_or_null(80) i8* @malloc(i64 40)
37   ret i8* %call
40 define noalias i8* @malloc_constant_size3() {
41 ; CHECK-LABEL: @malloc_constant_size3(
42 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias dereferenceable(80) dereferenceable_or_null(40) i8* @malloc(i64 40)
43 ; CHECK-NEXT:    ret i8* [[CALL]]
45   %call = tail call noalias dereferenceable(80) i8* @malloc(i64 40)
46   ret i8* %call
50 define noalias i8* @malloc_constant_zero_size() {
51 ; CHECK-LABEL: @malloc_constant_zero_size(
52 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias i8* @malloc(i64 0)
53 ; CHECK-NEXT:    ret i8* [[CALL]]
55   %call = tail call noalias i8* @malloc(i64 0)
56   ret i8* %call
59 define noalias i8* @realloc_nonconstant_size(i8* %p, i64 %n) {
60 ; CHECK-LABEL: @realloc_nonconstant_size(
61 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias i8* @realloc(i8* [[P:%.*]], i64 [[N:%.*]])
62 ; CHECK-NEXT:    ret i8* [[CALL]]
64   %call = tail call noalias i8* @realloc(i8* %p, i64 %n)
65   ret i8* %call
68 define noalias i8* @realloc_constant_zero_size(i8* %p) {
69 ; CHECK-LABEL: @realloc_constant_zero_size(
70 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias i8* @realloc(i8* [[P:%.*]], i64 0)
71 ; CHECK-NEXT:    ret i8* [[CALL]]
73   %call = tail call noalias i8* @realloc(i8* %p, i64 0)
74   ret i8* %call
77 define noalias i8* @realloc_constant_size(i8* %p) {
78 ; CHECK-LABEL: @realloc_constant_size(
79 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias dereferenceable_or_null(40) i8* @realloc(i8* [[P:%.*]], i64 40)
80 ; CHECK-NEXT:    ret i8* [[CALL]]
82   %call = tail call noalias i8* @realloc(i8* %p, i64 40)
83   ret i8* %call
86 define noalias i8* @calloc_nonconstant_size(i64 %n) {
87 ; CHECK-LABEL: @calloc_nonconstant_size(
88 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias i8* @calloc(i64 1, i64 [[N:%.*]])
89 ; CHECK-NEXT:    ret i8* [[CALL]]
91   %call = tail call noalias i8* @calloc(i64 1, i64 %n)
92   ret i8* %call
95 define noalias i8* @calloc_nonconstant_size2(i64 %n) {
96 ; CHECK-LABEL: @calloc_nonconstant_size2(
97 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias i8* @calloc(i64 [[N:%.*]], i64 0)
98 ; CHECK-NEXT:    ret i8* [[CALL]]
100   %call = tail call noalias i8* @calloc(i64 %n, i64 0)
101   ret i8* %call
104 define noalias i8* @calloc_nonconstant_size3(i64 %n) {
105 ; CHECK-LABEL: @calloc_nonconstant_size3(
106 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias i8* @calloc(i64 [[N:%.*]], i64 [[N]])
107 ; CHECK-NEXT:    ret i8* [[CALL]]
109   %call = tail call noalias i8* @calloc(i64 %n, i64 %n)
110   ret i8* %call
113 define noalias i8* @calloc_constant_zero_size() {
114 ; CHECK-LABEL: @calloc_constant_zero_size(
115 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias i8* @calloc(i64 0, i64 0)
116 ; CHECK-NEXT:    ret i8* [[CALL]]
118   %call = tail call noalias i8* @calloc(i64 0, i64 0)
119   ret i8* %call
122 define noalias i8* @calloc_constant_zero_size2(i64 %n) {
123 ; CHECK-LABEL: @calloc_constant_zero_size2(
124 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias i8* @calloc(i64 [[N:%.*]], i64 0)
125 ; CHECK-NEXT:    ret i8* [[CALL]]
127   %call = tail call noalias i8* @calloc(i64 %n, i64 0)
128   ret i8* %call
132 define noalias i8* @calloc_constant_zero_size3(i64 %n) {
133 ; CHECK-LABEL: @calloc_constant_zero_size3(
134 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias i8* @calloc(i64 0, i64 [[N:%.*]])
135 ; CHECK-NEXT:    ret i8* [[CALL]]
137   %call = tail call noalias i8* @calloc(i64 0, i64 %n)
138   ret i8* %call
141 define noalias i8* @calloc_constant_zero_size4(i64 %n) {
142 ; CHECK-LABEL: @calloc_constant_zero_size4(
143 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias i8* @calloc(i64 0, i64 1)
144 ; CHECK-NEXT:    ret i8* [[CALL]]
146   %call = tail call noalias i8* @calloc(i64 0, i64 1)
147   ret i8* %call
150 define noalias i8* @calloc_constant_zero_size5(i64 %n) {
151 ; CHECK-LABEL: @calloc_constant_zero_size5(
152 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias i8* @calloc(i64 1, i64 0)
153 ; CHECK-NEXT:    ret i8* [[CALL]]
155   %call = tail call noalias i8* @calloc(i64 1, i64 0)
156   ret i8* %call
159 define noalias i8* @calloc_constant_size() {
160 ; CHECK-LABEL: @calloc_constant_size(
161 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias dereferenceable_or_null(128) i8* @calloc(i64 16, i64 8)
162 ; CHECK-NEXT:    ret i8* [[CALL]]
164   %call = tail call noalias i8* @calloc(i64 16, i64 8)
165   ret i8* %call
168 define noalias i8* @calloc_constant_size_overflow() {
169 ; CHECK-LABEL: @calloc_constant_size_overflow(
170 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias i8* @calloc(i64 2000000000000, i64 80000000000)
171 ; CHECK-NEXT:    ret i8* [[CALL]]
173   %call = tail call noalias i8* @calloc(i64 2000000000000, i64 80000000000)
174   ret i8* %call
177 define noalias i8* @op_new_nonconstant_size(i64 %n) {
178 ; CHECK-LABEL: @op_new_nonconstant_size(
179 ; CHECK-NEXT:    [[CALL:%.*]] = tail call i8* @_Znam(i64 [[N:%.*]])
180 ; CHECK-NEXT:    ret i8* [[CALL]]
182   %call = tail call i8* @_Znam(i64 %n)
183   ret i8* %call
186 define noalias i8* @op_new_constant_size() {
187 ; CHECK-LABEL: @op_new_constant_size(
188 ; CHECK-NEXT:    [[CALL:%.*]] = tail call dereferenceable(40) i8* @_Znam(i64 40)
189 ; CHECK-NEXT:    ret i8* [[CALL]]
191   %call = tail call i8* @_Znam(i64 40)
192   ret i8* %call
195 define noalias i8* @op_new_constant_size2() {
196 ; CHECK-LABEL: @op_new_constant_size2(
197 ; CHECK-NEXT:    [[CALL:%.*]] = tail call dereferenceable(40) i8* @_Znwm(i64 40)
198 ; CHECK-NEXT:    ret i8* [[CALL]]
200   %call = tail call i8* @_Znwm(i64 40)
201   ret i8* %call
204 define noalias i8* @op_new_constant_zero_size() {
205 ; CHECK-LABEL: @op_new_constant_zero_size(
206 ; CHECK-NEXT:    [[CALL:%.*]] = tail call i8* @_Znam(i64 0)
207 ; CHECK-NEXT:    ret i8* [[CALL]]
209   %call = tail call i8* @_Znam(i64 0)
210   ret i8* %call
213 define noalias i8* @strdup_constant_str() {
214 ; CHECK-LABEL: @strdup_constant_str(
215 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias dereferenceable_or_null(6) i8* @strdup(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
216 ; CHECK-NEXT:    ret i8* [[CALL]]
218   %call = tail call noalias i8* @strdup(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
219   ret i8* %call
222 define noalias i8* @strdup_notconstant_str(i8 * %str) {
223 ; CHECK-LABEL: @strdup_notconstant_str(
224 ; CHECK-NEXT:    [[CALL:%.*]] = tail call noalias i8* @strdup(i8* [[STR:%.*]])
225 ; CHECK-NEXT:    ret i8* [[CALL]]
227   %call = tail call noalias i8* @strdup(i8* %str)
228   ret i8* %call