Skip to content

Commit 635f93d

Browse files
committed
[SimplifyLibCalls] Place deref attr even if nonnull already set
If nonnull is already set, we currently skip setting both nonnull and dereferenceable. Make these independent, to avoid regressions when additional nonnull attributes are inferred earlier.
1 parent 0f32f0e commit 635f93d

File tree

21 files changed

+100
-99
lines changed

21 files changed

+100
-99
lines changed

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,14 @@ static void annotateNonNullNoUndefBasedOnAccess(CallInst *CI,
247247
if (!CI->paramHasAttr(ArgNo, Attribute::NoUndef))
248248
CI->addParamAttr(ArgNo, Attribute::NoUndef);
249249

250-
if (CI->paramHasAttr(ArgNo, Attribute::NonNull))
251-
continue;
252-
unsigned AS = CI->getArgOperand(ArgNo)->getType()->getPointerAddressSpace();
253-
if (llvm::NullPointerIsDefined(F, AS))
254-
continue;
250+
if (!CI->paramHasAttr(ArgNo, Attribute::NonNull)) {
251+
unsigned AS =
252+
CI->getArgOperand(ArgNo)->getType()->getPointerAddressSpace();
253+
if (llvm::NullPointerIsDefined(F, AS))
254+
continue;
255+
CI->addParamAttr(ArgNo, Attribute::NonNull);
256+
}
255257

256-
CI->addParamAttr(ArgNo, Attribute::NonNull);
257258
annotateDereferenceableBytes(CI, ArgNo, 1);
258259
}
259260
}

llvm/test/Transforms/InstCombine/memchr-4.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ declare ptr @memchr(ptr, i32, i64)
1616

1717
define ptr @call_memchr_ax_2_uimax_p1() {
1818
; CHECK-LABEL: @call_memchr_ax_2_uimax_p1(
19-
; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull @ax, i32 1, i64 4294967296)
19+
; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @ax, i32 1, i64 4294967296)
2020
; CHECK-NEXT: ret ptr [[RES]]
2121
;
2222

@@ -30,7 +30,7 @@ define ptr @call_memchr_ax_2_uimax_p1() {
3030

3131
define ptr @call_memchr_ax_2_uimax_p2() {
3232
; CHECK-LABEL: @call_memchr_ax_2_uimax_p2(
33-
; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull @ax, i32 1, i64 4294967296)
33+
; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @ax, i32 1, i64 4294967296)
3434
; CHECK-NEXT: ret ptr [[RES]]
3535
;
3636

@@ -56,7 +56,7 @@ define ptr @fold_memchr_a12345_3_uimax_p2() {
5656

5757
define ptr @fold_memchr_a12345_c_uimax_p2(i32 %0) {
5858
; CHECK-LABEL: @fold_memchr_a12345_c_uimax_p2(
59-
; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull @a12345, i32 [[TMP0:%.*]], i64 4294967297)
59+
; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @a12345, i32 [[TMP0:%.*]], i64 4294967297)
6060
; CHECK-NEXT: ret ptr [[RES]]
6161
;
6262

llvm/test/Transforms/InstCombine/memchr-6.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ declare ptr @memchr(ptr, i32, i64)
1818

1919
define ptr @fold_memchr_a00000_c_5(i32 %C) {
2020
; CHECK-LABEL: @fold_memchr_a00000_c_5(
21-
; CHECK-NEXT: [[RET:%.*]] = call ptr @memchr(ptr noundef nonnull @a00000, i32 [[C:%.*]], i64 5)
21+
; CHECK-NEXT: [[RET:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @a00000, i32 [[C:%.*]], i64 5)
2222
; CHECK-NEXT: ret ptr [[RET]]
2323
;
2424

@@ -118,7 +118,7 @@ define ptr @call_memchr_a1110111_c_4(i32 %C) {
118118

119119
define ptr @call_memchr_a1110111_c_7(i32 %C) {
120120
; CHECK-LABEL: @call_memchr_a1110111_c_7(
121-
; CHECK-NEXT: [[RET:%.*]] = call ptr @memchr(ptr noundef nonnull @a1110111, i32 [[C:%.*]], i64 7)
121+
; CHECK-NEXT: [[RET:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @a1110111, i32 [[C:%.*]], i64 7)
122122
; CHECK-NEXT: ret ptr [[RET]]
123123
;
124124

llvm/test/Transforms/InstCombine/memchr-7.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ declare ptr @memchr(ptr, i32, i64)
99

1010
define zeroext i1 @strchr_to_memchr_n_equals_len(i32 %c) {
1111
; CHECK-LABEL: @strchr_to_memchr_n_equals_len(
12-
; CHECK-NEXT: [[MEMCHR:%.*]] = tail call ptr @memchr(ptr noundef nonnull @.str, i32 [[C:%.*]], i64 27)
12+
; CHECK-NEXT: [[MEMCHR:%.*]] = tail call ptr @memchr(ptr noundef nonnull dereferenceable(1) @.str, i32 [[C:%.*]], i64 27)
1313
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[MEMCHR]], null
1414
; CHECK-NEXT: ret i1 [[CMP]]
1515
;
@@ -33,7 +33,7 @@ define zeroext i1 @memchr_n_equals_len(i32 %c) {
3333

3434
define zeroext i1 @memchr_n_less_than_len(i32 %c) {
3535
; CHECK-LABEL: @memchr_n_less_than_len(
36-
; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @memchr(ptr noundef nonnull @.str, i32 [[C:%.*]], i64 15)
36+
; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @memchr(ptr noundef nonnull dereferenceable(1) @.str, i32 [[C:%.*]], i64 15)
3737
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[CALL]], null
3838
; CHECK-NEXT: ret i1 [[CMP]]
3939
;
@@ -45,7 +45,7 @@ define zeroext i1 @memchr_n_less_than_len(i32 %c) {
4545

4646
define zeroext i1 @memchr_n_more_than_len(i32 %c) {
4747
; CHECK-LABEL: @memchr_n_more_than_len(
48-
; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @memchr(ptr noundef nonnull @.str, i32 [[C:%.*]], i64 30)
48+
; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @memchr(ptr noundef nonnull dereferenceable(1) @.str, i32 [[C:%.*]], i64 30)
4949
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[CALL]], null
5050
; CHECK-NEXT: ret i1 [[CMP]]
5151
;
@@ -58,7 +58,7 @@ define zeroext i1 @memchr_n_more_than_len(i32 %c) {
5858

5959
define ptr @memchr_no_zero_cmp(i32 %c) {
6060
; CHECK-LABEL: @memchr_no_zero_cmp(
61-
; CHECK-NEXT: [[MEMCHR:%.*]] = tail call ptr @memchr(ptr noundef nonnull @.str, i32 [[C:%.*]], i64 27)
61+
; CHECK-NEXT: [[MEMCHR:%.*]] = tail call ptr @memchr(ptr noundef nonnull dereferenceable(1) @.str, i32 [[C:%.*]], i64 27)
6262
; CHECK-NEXT: ret ptr [[MEMCHR]]
6363
;
6464
%call = tail call ptr @strchr(ptr nonnull dereferenceable(27) @.str, i32 %c)
@@ -82,7 +82,7 @@ define ptr @memchr_no_zero_cmp2(i32 %c) {
8282

8383
define zeroext i1 @memchr_n_equals_len_minsize(i32 %c) minsize {
8484
; CHECK-LABEL: @memchr_n_equals_len_minsize(
85-
; CHECK-NEXT: [[MEMCHR:%.*]] = tail call ptr @memchr(ptr noundef nonnull @.str, i32 [[C:%.*]], i64 27)
85+
; CHECK-NEXT: [[MEMCHR:%.*]] = tail call ptr @memchr(ptr noundef nonnull dereferenceable(1) @.str, i32 [[C:%.*]], i64 27)
8686
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[MEMCHR]], null
8787
; CHECK-NEXT: ret i1 [[CMP]]
8888
;

llvm/test/Transforms/InstCombine/memchr.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ define void @test3() {
4747

4848
define void @test4(i32 %chr) {
4949
; CHECK-LABEL: @test4(
50-
; CHECK-NEXT: [[DST:%.*]] = call ptr @memchr(ptr noundef nonnull @hello, i32 [[CHR:%.*]], i32 14)
50+
; CHECK-NEXT: [[DST:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @hello, i32 [[CHR:%.*]], i32 14)
5151
; CHECK-NEXT: store ptr [[DST]], ptr @chp, align 4
5252
; CHECK-NEXT: ret void
5353
;
@@ -139,7 +139,7 @@ define i1 @test11(i32 %C) {
139139
; No 64 bits here
140140
define i1 @test12(i32 %C) {
141141
; CHECK-LABEL: @test12(
142-
; CHECK-NEXT: [[DST:%.*]] = call ptr @memchr(ptr noundef nonnull @spaces, i32 [[C:%.*]], i32 3)
142+
; CHECK-NEXT: [[DST:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @spaces, i32 [[C:%.*]], i32 3)
143143
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[DST]], null
144144
; CHECK-NEXT: ret i1 [[CMP]]
145145
;
@@ -174,7 +174,7 @@ define i1 @test14(i32 %C) {
174174

175175
define i1 @test15(i32 %C) {
176176
; CHECK-LABEL: @test15(
177-
; CHECK-NEXT: [[DST:%.*]] = call ptr @memchr(ptr noundef nonnull @negative, i32 [[C:%.*]], i32 3)
177+
; CHECK-NEXT: [[DST:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @negative, i32 [[C:%.*]], i32 3)
178178
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[DST]], null
179179
; CHECK-NEXT: ret i1 [[CMP]]
180180
;

llvm/test/Transforms/InstCombine/memset-1.ll

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ define ptr @test_simplify1_tail(ptr %mem, i32 %val, i32 %size) {
3333

3434
define ptr @test_simplify1_musttail(ptr %mem, i32 %val, i32 %size) {
3535
; CHECK-LABEL: @test_simplify1_musttail(
36-
; CHECK-NEXT: %ret = musttail call ptr @memset(ptr %mem, i32 %val, i32 %size)
37-
; CHECK-NEXT: ret ptr %ret
36+
; CHECK-NEXT: [[RET:%.*]] = musttail call ptr @memset(ptr [[MEM:%.*]], i32 [[VAL:%.*]], i32 [[SIZE:%.*]])
37+
; CHECK-NEXT: ret ptr [[RET]]
3838
;
3939
%ret = musttail call ptr @memset(ptr %mem, i32 %val, i32 %size)
4040
ret ptr %ret
@@ -44,8 +44,9 @@ define ptr @test_simplify1_musttail(ptr %mem, i32 %val, i32 %size) {
4444

4545
define ptr @pr25892_lite(i32 %size) #0 {
4646
; CHECK-LABEL: @pr25892_lite(
47-
; CHECK-NEXT: [[CALL:%.*]] = call ptr @malloc(i32 [[SIZE:%.*]])
48-
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 1 [[CALL]], i8 0, i32 [[SIZE]], i1 false)
47+
; CHECK-NEXT: [[CALL1:%.*]] = call ptr @malloc(i32 [[SIZE:%.*]]) #[[ATTR0:[0-9]+]]
48+
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 1 [[CALL1]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
49+
; CHECK-NEXT: ret ptr [[CALL1]]
4950
;
5051
%call1 = call ptr @malloc(i32 %size) #1
5152
%call2 = call ptr @memset(ptr %call1, i32 0, i32 %size) #1
@@ -71,8 +72,8 @@ define ptr @malloc_and_memset_intrinsic(i32 %n) #0 {
7172

7273
define ptr @notmalloc_memset(i32 %size, ptr %notmalloc) {
7374
; CHECK-LABEL: @notmalloc_memset(
74-
; CHECK-NEXT: [[CALL1:%.*]] = call ptr [[NOTMALLOC:%.*]](i32 [[SIZE:%.*]]) [[ATTR0:#.*]]
75-
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 1 [[CALL1]], i8 0, i32 [[SIZE]], i1 false) [[ATTR0]]
75+
; CHECK-NEXT: [[CALL1:%.*]] = call ptr [[NOTMALLOC:%.*]](i32 [[SIZE:%.*]]) #[[ATTR0]]
76+
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 1 [[CALL1]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
7677
; CHECK-NEXT: ret ptr [[CALL1]]
7778
;
7879
%call1 = call ptr %notmalloc(i32 %size) #1
@@ -86,11 +87,11 @@ define ptr @notmalloc_memset(i32 %size, ptr %notmalloc) {
8687
define ptr @pr25892(i32 %size) #0 {
8788
; CHECK-LABEL: @pr25892(
8889
; CHECK-NEXT: entry:
89-
; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @malloc(i32 [[SIZE:%.*]]) [[ATTR0]]
90+
; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @malloc(i32 [[SIZE:%.*]]) #[[ATTR0]]
9091
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[CALL]], null
9192
; CHECK-NEXT: br i1 [[CMP]], label [[CLEANUP:%.*]], label [[IF_END:%.*]]
9293
; CHECK: if.end:
93-
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr nonnull align 1 [[CALL]], i8 0, i32 [[SIZE]], i1 false) [[ATTR0]]
94+
; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr nonnull align 1 [[CALL]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
9495
; CHECK-NEXT: br label [[CLEANUP]]
9596
; CHECK: cleanup:
9697
; CHECK-NEXT: [[RETVAL_0:%.*]] = phi ptr [ [[CALL]], [[IF_END]] ], [ null, [[ENTRY:%.*]] ]
@@ -112,9 +113,9 @@ cleanup:
112113

113114
define ptr @buffer_is_modified_then_memset(i32 %size) {
114115
; CHECK-LABEL: @buffer_is_modified_then_memset(
115-
; CHECK-NEXT: [[PTR:%.*]] = tail call ptr @malloc(i32 [[SIZE:%.*]]) [[ATTR0]]
116+
; CHECK-NEXT: [[PTR:%.*]] = tail call ptr @malloc(i32 [[SIZE:%.*]]) #[[ATTR0]]
116117
; CHECK-NEXT: store i8 1, ptr [[PTR]], align 1
117-
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr nonnull align 1 [[PTR]], i8 0, i32 [[SIZE]], i1 false) [[ATTR0]]
118+
; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr nonnull align 1 [[PTR]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
118119
; CHECK-NEXT: ret ptr [[PTR]]
119120
;
120121
%ptr = tail call ptr @malloc(i32 %size) #1
@@ -126,7 +127,7 @@ define ptr @buffer_is_modified_then_memset(i32 %size) {
126127
define ptr @memset_size_select(i1 %b, ptr %ptr) {
127128
; CHECK-LABEL: @memset_size_select(
128129
; CHECK-NEXT: [[SIZE:%.*]] = select i1 [[B:%.*]], i32 10, i32 50
129-
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(10) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) [[ATTR0]]
130+
; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(10) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
130131
; CHECK-NEXT: ret ptr [[PTR]]
131132
;
132133
%size = select i1 %b, i32 10, i32 50
@@ -138,7 +139,7 @@ define ptr @memset_size_select(i1 %b, ptr %ptr) {
138139
define ptr @memset_size_select2(i1 %b, ptr %ptr) {
139140
; CHECK-LABEL: @memset_size_select2(
140141
; CHECK-NEXT: [[SIZE:%.*]] = select i1 [[B:%.*]], i32 10, i32 50
141-
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(80) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) [[ATTR0]]
142+
; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(80) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
142143
; CHECK-NEXT: ret ptr [[PTR]]
143144
;
144145
%size = select i1 %b, i32 10, i32 50
@@ -149,7 +150,7 @@ define ptr @memset_size_select2(i1 %b, ptr %ptr) {
149150
define ptr @memset_size_select3(i1 %b, ptr %ptr) {
150151
; CHECK-LABEL: @memset_size_select3(
151152
; CHECK-NEXT: [[SIZE:%.*]] = select i1 [[B:%.*]], i32 10, i32 50
152-
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(40) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false)
153+
; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(40) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false)
153154
; CHECK-NEXT: ret ptr [[PTR]]
154155
;
155156
%size = select i1 %b, i32 10, i32 50
@@ -160,7 +161,7 @@ define ptr @memset_size_select3(i1 %b, ptr %ptr) {
160161
define ptr @memset_size_select4(i1 %b, ptr %ptr) {
161162
; CHECK-LABEL: @memset_size_select4(
162163
; CHECK-NEXT: [[SIZE:%.*]] = select i1 [[B:%.*]], i32 10, i32 50
163-
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(40) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) [[ATTR0]]
164+
; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(40) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
164165
; CHECK-NEXT: ret ptr [[PTR]]
165166
;
166167
%size = select i1 %b, i32 10, i32 50
@@ -171,7 +172,7 @@ define ptr @memset_size_select4(i1 %b, ptr %ptr) {
171172
define ptr @memset_size_ashr(i1 %b, ptr %ptr, i32 %v) {
172173
; CHECK-LABEL: @memset_size_ashr(
173174
; CHECK-NEXT: [[SIZE:%.*]] = ashr i32 -2, [[V:%.*]]
174-
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) [[ATTR0]]
175+
; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(1) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
175176
; CHECK-NEXT: ret ptr [[PTR]]
176177
;
177178
%size = ashr i32 -2, %v
@@ -181,7 +182,7 @@ define ptr @memset_size_ashr(i1 %b, ptr %ptr, i32 %v) {
181182

182183
define ptr @memset_attrs1(i1 %b, ptr %ptr, i32 %size) {
183184
; CHECK-LABEL: @memset_attrs1(
184-
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 1 dereferenceable_or_null(40) [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) [[ATTR0]]
185+
; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr align 1 dereferenceable_or_null(40) [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) #[[ATTR0]]
185186
; CHECK-NEXT: ret ptr [[PTR]]
186187
;
187188
%memset = tail call ptr @memset(ptr dereferenceable_or_null(40) %ptr, i32 0, i32 %size) #1
@@ -192,7 +193,7 @@ define ptr @memset_attrs1(i1 %b, ptr %ptr, i32 %size) {
192193
; do not change dereferenceable attribute
193194
define ptr @memset_attrs2(i1 %b, ptr %ptr, i32 %size) {
194195
; CHECK-LABEL: @memset_attrs2(
195-
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr nonnull align 1 dereferenceable(40) [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) [[ATTR0]]
196+
; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr nonnull align 1 dereferenceable(40) [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) #[[ATTR0]]
196197
; CHECK-NEXT: ret ptr [[PTR]]
197198
;
198199
%memset = tail call ptr @memset(ptr nonnull dereferenceable(40) %ptr, i32 0, i32 %size) #1
@@ -202,7 +203,7 @@ define ptr @memset_attrs2(i1 %b, ptr %ptr, i32 %size) {
202203
; size is unknown, just copy attrs, no changes in attrs
203204
define ptr @memset_attrs3(i1 %b, ptr %ptr, i32 %size) {
204205
; CHECK-LABEL: @memset_attrs3(
205-
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr nonnull align 1 dereferenceable_or_null(40) [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) [[ATTR0]]
206+
; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr nonnull align 1 dereferenceable_or_null(40) [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) #[[ATTR0]]
206207
; CHECK-NEXT: ret ptr [[PTR]]
207208
;
208209
%memset = tail call ptr @memset(ptr nonnull dereferenceable_or_null(40) %ptr, i32 0, i32 %size) #1
@@ -212,7 +213,7 @@ define ptr @memset_attrs3(i1 %b, ptr %ptr, i32 %size) {
212213
; be sure to drop nonnull since size is unknown and can be 0
213214
define ptr @memset_attrs4(i1 %b, ptr %ptr, i32 %size) {
214215
; CHECK-LABEL: @memset_attrs4(
215-
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr nonnull align 1 [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) [[ATTR0]]
216+
; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr nonnull align 1 [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) #[[ATTR0]]
216217
; CHECK-NEXT: ret ptr [[PTR]]
217218
;
218219
%memset = tail call ptr @memset(ptr nonnull %ptr, i32 0, i32 %size) #1

llvm/test/Transforms/InstCombine/printf-1.ll

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f3
1515
@percent_f = constant [3 x i8] c"%f\00"
1616
@percent_s = constant [4 x i8] c"%s\0A\00"
1717
@empty = constant [1 x i8] c"\00"
18-
; CHECK: [[$STR:@[a-z0-9]+]] = private unnamed_addr constant [12 x i8] c"hello world\00", align 1
1918

2019
declare i32 @printf(ptr, ...)
2120

@@ -79,11 +78,11 @@ define void @test_simplify3() {
7978

8079
define void @test_simplify4() {
8180
; CHECK-LABEL: @test_simplify4(
82-
; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str)
81+
; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @str)
8382
; CHECK-NEXT: ret void
8483
;
8584
; CHECK-IPRINTF-LABEL: @test_simplify4(
86-
; CHECK-IPRINTF-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str)
85+
; CHECK-IPRINTF-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @str)
8786
; CHECK-IPRINTF-NEXT: ret void
8887
;
8988
call i32 (ptr, ...) @printf(ptr @hello_world)
@@ -109,11 +108,11 @@ define void @test_simplify5() {
109108

110109
define void @test_simplify6() {
111110
; CHECK-LABEL: @test_simplify6(
112-
; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @hello_world)
111+
; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @hello_world)
113112
; CHECK-NEXT: ret void
114113
;
115114
; CHECK-IPRINTF-LABEL: @test_simplify6(
116-
; CHECK-IPRINTF-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @hello_world)
115+
; CHECK-IPRINTF-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @hello_world)
117116
; CHECK-IPRINTF-NEXT: ret void
118117
;
119118
call i32 (ptr, ...) @printf(ptr @percent_s, ptr @hello_world)
@@ -124,7 +123,7 @@ define void @test_simplify6() {
124123

125124
define void @test_simplify7() {
126125
; CHECK-LABEL: @test_simplify7(
127-
; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull @percent_d, i32 187)
126+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @percent_d, i32 187)
128127
; CHECK-NEXT: ret void
129128
;
130129
; CHECK-IPRINTF-LABEL: @test_simplify7(
@@ -137,11 +136,11 @@ define void @test_simplify7() {
137136

138137
define void @test_no_simplify1() {
139138
; CHECK-LABEL: @test_no_simplify1(
140-
; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull @percent_f, double 1.870000e+00)
139+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @percent_f, double 1.870000e+00)
141140
; CHECK-NEXT: ret void
142141
;
143142
; CHECK-IPRINTF-LABEL: @test_no_simplify1(
144-
; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull @percent_f, double 1.870000e+00)
143+
; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @percent_f, double 1.870000e+00)
145144
; CHECK-IPRINTF-NEXT: ret void
146145
;
147146
call i32 (ptr, ...) @printf(ptr @percent_f, double 1.87)
@@ -163,7 +162,7 @@ define void @test_no_simplify2(ptr %fmt, double %d) {
163162

164163
define i32 @test_no_simplify3() {
165164
; CHECK-LABEL: @test_no_simplify3(
166-
; CHECK-NEXT: [[RET:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull @h)
165+
; CHECK-NEXT: [[RET:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @h)
167166
; CHECK-NEXT: ret i32 [[RET]]
168167
;
169168
; CHECK-IPRINTF-LABEL: @test_no_simplify3(

llvm/test/Transforms/InstCombine/printf-2.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ define void @test_simplify1() {
3838

3939
define void @test_simplify2() {
4040
; CHECK-LABEL: @test_simplify2(
41-
; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str)
41+
; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @str)
4242
; CHECK-NEXT: ret void
4343
;
4444
call i32 (ptr, ...) @printf(ptr @hello_world)
@@ -47,7 +47,7 @@ define void @test_simplify2() {
4747

4848
define void @test_simplify6() {
4949
; CHECK-LABEL: @test_simplify6(
50-
; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @hello_world)
50+
; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @hello_world)
5151
; CHECK-NEXT: ret void
5252
;
5353
call i32 (ptr, ...) @printf(ptr @percent_s, ptr @hello_world)
@@ -77,7 +77,7 @@ define void @test_simplify8() {
7777

7878
define void @test_simplify9() {
7979
; CHECK-LABEL: @test_simplify9(
80-
; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str.1)
80+
; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @str.1)
8181
; CHECK-NEXT: ret void
8282
;
8383
call i32 (ptr, ...) @printf(ptr @format_str, ptr @hello_world)
@@ -91,7 +91,7 @@ define void @test_simplify9() {
9191
define void @test_simplify10() {
9292
; CHECK-LABEL: @test_simplify10(
9393
; CHECK-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 97)
94-
; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str.2)
94+
; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @str.2)
9595
; CHECK-NEXT: ret void
9696
;
9797
call i32 (ptr, ...) @printf(ptr @format_str, ptr @empty, i32 42, double 0x40091EB860000000)

0 commit comments

Comments
 (0)