if (!CI->paramHasAttr(ArgNo, Attribute::NoUndef))
CI->addParamAttr(ArgNo, Attribute::NoUndef);
- if (CI->paramHasAttr(ArgNo, Attribute::NonNull))
- continue;
- unsigned AS = CI->getArgOperand(ArgNo)->getType()->getPointerAddressSpace();
- if (llvm::NullPointerIsDefined(F, AS))
- continue;
+ if (!CI->paramHasAttr(ArgNo, Attribute::NonNull)) {
+ unsigned AS =
+ CI->getArgOperand(ArgNo)->getType()->getPointerAddressSpace();
+ if (llvm::NullPointerIsDefined(F, AS))
+ continue;
+ CI->addParamAttr(ArgNo, Attribute::NonNull);
+ }
- CI->addParamAttr(ArgNo, Attribute::NonNull);
annotateDereferenceableBytes(CI, ArgNo, 1);
}
}
define ptr @call_memchr_ax_2_uimax_p1() {
; CHECK-LABEL: @call_memchr_ax_2_uimax_p1(
-; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull @ax, i32 1, i64 4294967296)
+; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @ax, i32 1, i64 4294967296)
; CHECK-NEXT: ret ptr [[RES]]
;
define ptr @call_memchr_ax_2_uimax_p2() {
; CHECK-LABEL: @call_memchr_ax_2_uimax_p2(
-; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull @ax, i32 1, i64 4294967296)
+; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @ax, i32 1, i64 4294967296)
; CHECK-NEXT: ret ptr [[RES]]
;
define ptr @fold_memchr_a12345_c_uimax_p2(i32 %0) {
; CHECK-LABEL: @fold_memchr_a12345_c_uimax_p2(
-; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull @a12345, i32 [[TMP0:%.*]], i64 4294967297)
+; CHECK-NEXT: [[RES:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @a12345, i32 [[TMP0:%.*]], i64 4294967297)
; CHECK-NEXT: ret ptr [[RES]]
;
define ptr @fold_memchr_a00000_c_5(i32 %C) {
; CHECK-LABEL: @fold_memchr_a00000_c_5(
-; CHECK-NEXT: [[RET:%.*]] = call ptr @memchr(ptr noundef nonnull @a00000, i32 [[C:%.*]], i64 5)
+; CHECK-NEXT: [[RET:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @a00000, i32 [[C:%.*]], i64 5)
; CHECK-NEXT: ret ptr [[RET]]
;
define ptr @call_memchr_a1110111_c_7(i32 %C) {
; CHECK-LABEL: @call_memchr_a1110111_c_7(
-; CHECK-NEXT: [[RET:%.*]] = call ptr @memchr(ptr noundef nonnull @a1110111, i32 [[C:%.*]], i64 7)
+; CHECK-NEXT: [[RET:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @a1110111, i32 [[C:%.*]], i64 7)
; CHECK-NEXT: ret ptr [[RET]]
;
define zeroext i1 @strchr_to_memchr_n_equals_len(i32 %c) {
; CHECK-LABEL: @strchr_to_memchr_n_equals_len(
-; CHECK-NEXT: [[MEMCHR:%.*]] = tail call ptr @memchr(ptr noundef nonnull @.str, i32 [[C:%.*]], i64 27)
+; CHECK-NEXT: [[MEMCHR:%.*]] = tail call ptr @memchr(ptr noundef nonnull dereferenceable(1) @.str, i32 [[C:%.*]], i64 27)
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[MEMCHR]], null
; CHECK-NEXT: ret i1 [[CMP]]
;
define zeroext i1 @memchr_n_less_than_len(i32 %c) {
; CHECK-LABEL: @memchr_n_less_than_len(
-; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @memchr(ptr noundef nonnull @.str, i32 [[C:%.*]], i64 15)
+; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @memchr(ptr noundef nonnull dereferenceable(1) @.str, i32 [[C:%.*]], i64 15)
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[CALL]], null
; CHECK-NEXT: ret i1 [[CMP]]
;
define zeroext i1 @memchr_n_more_than_len(i32 %c) {
; CHECK-LABEL: @memchr_n_more_than_len(
-; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @memchr(ptr noundef nonnull @.str, i32 [[C:%.*]], i64 30)
+; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @memchr(ptr noundef nonnull dereferenceable(1) @.str, i32 [[C:%.*]], i64 30)
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[CALL]], null
; CHECK-NEXT: ret i1 [[CMP]]
;
define ptr @memchr_no_zero_cmp(i32 %c) {
; CHECK-LABEL: @memchr_no_zero_cmp(
-; CHECK-NEXT: [[MEMCHR:%.*]] = tail call ptr @memchr(ptr noundef nonnull @.str, i32 [[C:%.*]], i64 27)
+; CHECK-NEXT: [[MEMCHR:%.*]] = tail call ptr @memchr(ptr noundef nonnull dereferenceable(1) @.str, i32 [[C:%.*]], i64 27)
; CHECK-NEXT: ret ptr [[MEMCHR]]
;
%call = tail call ptr @strchr(ptr nonnull dereferenceable(27) @.str, i32 %c)
define zeroext i1 @memchr_n_equals_len_minsize(i32 %c) minsize {
; CHECK-LABEL: @memchr_n_equals_len_minsize(
-; CHECK-NEXT: [[MEMCHR:%.*]] = tail call ptr @memchr(ptr noundef nonnull @.str, i32 [[C:%.*]], i64 27)
+; CHECK-NEXT: [[MEMCHR:%.*]] = tail call ptr @memchr(ptr noundef nonnull dereferenceable(1) @.str, i32 [[C:%.*]], i64 27)
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[MEMCHR]], null
; CHECK-NEXT: ret i1 [[CMP]]
;
define void @test4(i32 %chr) {
; CHECK-LABEL: @test4(
-; CHECK-NEXT: [[DST:%.*]] = call ptr @memchr(ptr noundef nonnull @hello, i32 [[CHR:%.*]], i32 14)
+; CHECK-NEXT: [[DST:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @hello, i32 [[CHR:%.*]], i32 14)
; CHECK-NEXT: store ptr [[DST]], ptr @chp, align 4
; CHECK-NEXT: ret void
;
; No 64 bits here
define i1 @test12(i32 %C) {
; CHECK-LABEL: @test12(
-; CHECK-NEXT: [[DST:%.*]] = call ptr @memchr(ptr noundef nonnull @spaces, i32 [[C:%.*]], i32 3)
+; CHECK-NEXT: [[DST:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @spaces, i32 [[C:%.*]], i32 3)
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[DST]], null
; CHECK-NEXT: ret i1 [[CMP]]
;
define i1 @test15(i32 %C) {
; CHECK-LABEL: @test15(
-; CHECK-NEXT: [[DST:%.*]] = call ptr @memchr(ptr noundef nonnull @negative, i32 [[C:%.*]], i32 3)
+; CHECK-NEXT: [[DST:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @negative, i32 [[C:%.*]], i32 3)
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[DST]], null
; CHECK-NEXT: ret i1 [[CMP]]
;
define ptr @test_simplify1_musttail(ptr %mem, i32 %val, i32 %size) {
; CHECK-LABEL: @test_simplify1_musttail(
-; CHECK-NEXT: %ret = musttail call ptr @memset(ptr %mem, i32 %val, i32 %size)
-; CHECK-NEXT: ret ptr %ret
+; CHECK-NEXT: [[RET:%.*]] = musttail call ptr @memset(ptr [[MEM:%.*]], i32 [[VAL:%.*]], i32 [[SIZE:%.*]])
+; CHECK-NEXT: ret ptr [[RET]]
;
%ret = musttail call ptr @memset(ptr %mem, i32 %val, i32 %size)
ret ptr %ret
define ptr @pr25892_lite(i32 %size) #0 {
; CHECK-LABEL: @pr25892_lite(
-; CHECK-NEXT: [[CALL:%.*]] = call ptr @malloc(i32 [[SIZE:%.*]])
-; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 1 [[CALL]], i8 0, i32 [[SIZE]], i1 false)
+; CHECK-NEXT: [[CALL1:%.*]] = call ptr @malloc(i32 [[SIZE:%.*]]) #[[ATTR0:[0-9]+]]
+; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 1 [[CALL1]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
+; CHECK-NEXT: ret ptr [[CALL1]]
;
%call1 = call ptr @malloc(i32 %size) #1
%call2 = call ptr @memset(ptr %call1, i32 0, i32 %size) #1
define ptr @notmalloc_memset(i32 %size, ptr %notmalloc) {
; CHECK-LABEL: @notmalloc_memset(
-; CHECK-NEXT: [[CALL1:%.*]] = call ptr [[NOTMALLOC:%.*]](i32 [[SIZE:%.*]]) [[ATTR0:#.*]]
-; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 1 [[CALL1]], i8 0, i32 [[SIZE]], i1 false) [[ATTR0]]
+; CHECK-NEXT: [[CALL1:%.*]] = call ptr [[NOTMALLOC:%.*]](i32 [[SIZE:%.*]]) #[[ATTR0]]
+; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 1 [[CALL1]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
; CHECK-NEXT: ret ptr [[CALL1]]
;
%call1 = call ptr %notmalloc(i32 %size) #1
define ptr @pr25892(i32 %size) #0 {
; CHECK-LABEL: @pr25892(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @malloc(i32 [[SIZE:%.*]]) [[ATTR0]]
+; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @malloc(i32 [[SIZE:%.*]]) #[[ATTR0]]
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[CALL]], null
; CHECK-NEXT: br i1 [[CMP]], label [[CLEANUP:%.*]], label [[IF_END:%.*]]
; CHECK: if.end:
-; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr nonnull align 1 [[CALL]], i8 0, i32 [[SIZE]], i1 false) [[ATTR0]]
+; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr nonnull align 1 [[CALL]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
; CHECK-NEXT: br label [[CLEANUP]]
; CHECK: cleanup:
; CHECK-NEXT: [[RETVAL_0:%.*]] = phi ptr [ [[CALL]], [[IF_END]] ], [ null, [[ENTRY:%.*]] ]
define ptr @buffer_is_modified_then_memset(i32 %size) {
; CHECK-LABEL: @buffer_is_modified_then_memset(
-; CHECK-NEXT: [[PTR:%.*]] = tail call ptr @malloc(i32 [[SIZE:%.*]]) [[ATTR0]]
+; CHECK-NEXT: [[PTR:%.*]] = tail call ptr @malloc(i32 [[SIZE:%.*]]) #[[ATTR0]]
; CHECK-NEXT: store i8 1, ptr [[PTR]], align 1
-; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr nonnull align 1 [[PTR]], i8 0, i32 [[SIZE]], i1 false) [[ATTR0]]
+; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr nonnull align 1 [[PTR]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
; CHECK-NEXT: ret ptr [[PTR]]
;
%ptr = tail call ptr @malloc(i32 %size) #1
define ptr @memset_size_select(i1 %b, ptr %ptr) {
; CHECK-LABEL: @memset_size_select(
; CHECK-NEXT: [[SIZE:%.*]] = select i1 [[B:%.*]], i32 10, i32 50
-; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(10) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) [[ATTR0]]
+; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(10) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
; CHECK-NEXT: ret ptr [[PTR]]
;
%size = select i1 %b, i32 10, i32 50
define ptr @memset_size_select2(i1 %b, ptr %ptr) {
; CHECK-LABEL: @memset_size_select2(
; CHECK-NEXT: [[SIZE:%.*]] = select i1 [[B:%.*]], i32 10, i32 50
-; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(80) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) [[ATTR0]]
+; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(80) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
; CHECK-NEXT: ret ptr [[PTR]]
;
%size = select i1 %b, i32 10, i32 50
define ptr @memset_size_select3(i1 %b, ptr %ptr) {
; CHECK-LABEL: @memset_size_select3(
; CHECK-NEXT: [[SIZE:%.*]] = select i1 [[B:%.*]], i32 10, i32 50
-; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(40) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false)
+; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(40) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false)
; CHECK-NEXT: ret ptr [[PTR]]
;
%size = select i1 %b, i32 10, i32 50
define ptr @memset_size_select4(i1 %b, ptr %ptr) {
; CHECK-LABEL: @memset_size_select4(
; CHECK-NEXT: [[SIZE:%.*]] = select i1 [[B:%.*]], i32 10, i32 50
-; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(40) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) [[ATTR0]]
+; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(40) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
; CHECK-NEXT: ret ptr [[PTR]]
;
%size = select i1 %b, i32 10, i32 50
define ptr @memset_size_ashr(i1 %b, ptr %ptr, i32 %v) {
; CHECK-LABEL: @memset_size_ashr(
; CHECK-NEXT: [[SIZE:%.*]] = ashr i32 -2, [[V:%.*]]
-; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) [[ATTR0]]
+; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(1) [[PTR:%.*]], i8 0, i32 [[SIZE]], i1 false) #[[ATTR0]]
; CHECK-NEXT: ret ptr [[PTR]]
;
%size = ashr i32 -2, %v
define ptr @memset_attrs1(i1 %b, ptr %ptr, i32 %size) {
; CHECK-LABEL: @memset_attrs1(
-; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr align 1 dereferenceable_or_null(40) [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) [[ATTR0]]
+; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr align 1 dereferenceable_or_null(40) [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) #[[ATTR0]]
; CHECK-NEXT: ret ptr [[PTR]]
;
%memset = tail call ptr @memset(ptr dereferenceable_or_null(40) %ptr, i32 0, i32 %size) #1
; do not change dereferenceable attribute
define ptr @memset_attrs2(i1 %b, ptr %ptr, i32 %size) {
; CHECK-LABEL: @memset_attrs2(
-; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr nonnull align 1 dereferenceable(40) [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) [[ATTR0]]
+; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr nonnull align 1 dereferenceable(40) [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) #[[ATTR0]]
; CHECK-NEXT: ret ptr [[PTR]]
;
%memset = tail call ptr @memset(ptr nonnull dereferenceable(40) %ptr, i32 0, i32 %size) #1
; size is unknown, just copy attrs, no changes in attrs
define ptr @memset_attrs3(i1 %b, ptr %ptr, i32 %size) {
; CHECK-LABEL: @memset_attrs3(
-; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr nonnull align 1 dereferenceable_or_null(40) [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) [[ATTR0]]
+; 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]]
; CHECK-NEXT: ret ptr [[PTR]]
;
%memset = tail call ptr @memset(ptr nonnull dereferenceable_or_null(40) %ptr, i32 0, i32 %size) #1
; be sure to drop nonnull since size is unknown and can be 0
define ptr @memset_attrs4(i1 %b, ptr %ptr, i32 %size) {
; CHECK-LABEL: @memset_attrs4(
-; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr nonnull align 1 [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) [[ATTR0]]
+; CHECK-NEXT: tail call void @llvm.memset.p0.i32(ptr nonnull align 1 [[PTR:%.*]], i8 0, i32 [[SIZE:%.*]], i1 false) #[[ATTR0]]
; CHECK-NEXT: ret ptr [[PTR]]
;
%memset = tail call ptr @memset(ptr nonnull %ptr, i32 0, i32 %size) #1
@percent_f = constant [3 x i8] c"%f\00"
@percent_s = constant [4 x i8] c"%s\0A\00"
@empty = constant [1 x i8] c"\00"
-; CHECK: [[$STR:@[a-z0-9]+]] = private unnamed_addr constant [12 x i8] c"hello world\00", align 1
declare i32 @printf(ptr, ...)
define void @test_simplify4() {
; CHECK-LABEL: @test_simplify4(
-; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str)
+; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @str)
; CHECK-NEXT: ret void
;
; CHECK-IPRINTF-LABEL: @test_simplify4(
-; CHECK-IPRINTF-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str)
+; CHECK-IPRINTF-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @str)
; CHECK-IPRINTF-NEXT: ret void
;
call i32 (ptr, ...) @printf(ptr @hello_world)
define void @test_simplify6() {
; CHECK-LABEL: @test_simplify6(
-; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @hello_world)
+; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @hello_world)
; CHECK-NEXT: ret void
;
; CHECK-IPRINTF-LABEL: @test_simplify6(
-; CHECK-IPRINTF-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @hello_world)
+; CHECK-IPRINTF-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @hello_world)
; CHECK-IPRINTF-NEXT: ret void
;
call i32 (ptr, ...) @printf(ptr @percent_s, ptr @hello_world)
define void @test_simplify7() {
; CHECK-LABEL: @test_simplify7(
-; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull @percent_d, i32 187)
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @percent_d, i32 187)
; CHECK-NEXT: ret void
;
; CHECK-IPRINTF-LABEL: @test_simplify7(
define void @test_no_simplify1() {
; CHECK-LABEL: @test_no_simplify1(
-; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull @percent_f, double 1.870000e+00)
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @percent_f, double 1.870000e+00)
; CHECK-NEXT: ret void
;
; CHECK-IPRINTF-LABEL: @test_no_simplify1(
-; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull @percent_f, double 1.870000e+00)
+; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @percent_f, double 1.870000e+00)
; CHECK-IPRINTF-NEXT: ret void
;
call i32 (ptr, ...) @printf(ptr @percent_f, double 1.87)
define i32 @test_no_simplify3() {
; CHECK-LABEL: @test_no_simplify3(
-; CHECK-NEXT: [[RET:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull @h)
+; CHECK-NEXT: [[RET:%.*]] = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @h)
; CHECK-NEXT: ret i32 [[RET]]
;
; CHECK-IPRINTF-LABEL: @test_no_simplify3(
define void @test_simplify2() {
; CHECK-LABEL: @test_simplify2(
-; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str)
+; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @str)
; CHECK-NEXT: ret void
;
call i32 (ptr, ...) @printf(ptr @hello_world)
define void @test_simplify6() {
; CHECK-LABEL: @test_simplify6(
-; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @hello_world)
+; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @hello_world)
; CHECK-NEXT: ret void
;
call i32 (ptr, ...) @printf(ptr @percent_s, ptr @hello_world)
define void @test_simplify9() {
; CHECK-LABEL: @test_simplify9(
-; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str.1)
+; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @str.1)
; CHECK-NEXT: ret void
;
call i32 (ptr, ...) @printf(ptr @format_str, ptr @hello_world)
define void @test_simplify10() {
; CHECK-LABEL: @test_simplify10(
; CHECK-NEXT: [[PUTCHAR:%.*]] = call i32 @putchar(i32 97)
-; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull @str.2)
+; CHECK-NEXT: [[PUTS:%.*]] = call i32 @puts(ptr nonnull dereferenceable(1) @str.2)
; CHECK-NEXT: ret void
;
call i32 (ptr, ...) @printf(ptr @format_str, ptr @empty, i32 42, double 0x40091EB860000000)
; CHECK-IPRINTF-NEXT: ret void
;
; WIN-LABEL: @test_simplify6(
-; WIN-NEXT: [[TMP1:%.*]] = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) [[DST:%.*]], ptr noundef nonnull @percent_d, i32 187)
+; WIN-NEXT: [[TMP1:%.*]] = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) [[DST:%.*]], ptr noundef nonnull dereferenceable(1) @percent_d, i32 187)
; WIN-NEXT: ret void
;
call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr @percent_d, i32 187)
define void @test_no_simplify1(ptr %dst) {
; CHECK-LABEL: @test_no_simplify1(
-; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) [[DST:%.*]], ptr noundef nonnull @percent_f, double 1.870000e+00)
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) [[DST:%.*]], ptr noundef nonnull dereferenceable(1) @percent_f, double 1.870000e+00)
; CHECK-NEXT: ret void
;
call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr @percent_f, double 1.87)
; CHECK-IPRINTF-NEXT: ret i32 [[TMP3]]
;
; WIN-LABEL: @test_no_simplify3(
-; WIN-NEXT: [[R:%.*]] = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) [[DST:%.*]], ptr noundef nonnull @percent_s, ptr [[STR:%.*]])
+; WIN-NEXT: [[R:%.*]] = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) [[DST:%.*]], ptr noundef nonnull dereferenceable(1) @percent_s, ptr [[STR:%.*]])
; WIN-NEXT: ret i32 [[R]]
;
%r = call i32 (ptr, ptr, ...) @sprintf(ptr %dst, ptr @percent_s, ptr %str)
define void @test_simplify4(i32 %chr) {
; CHECK-LABEL: @test_simplify4(
-; CHECK-NEXT: [[MEMCHR:%.*]] = call ptr @memchr(ptr noundef nonnull @hello, i32 [[CHR:%.*]], i32 14)
+; CHECK-NEXT: [[MEMCHR:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @hello, i32 [[CHR:%.*]], i32 14)
; CHECK-NEXT: store ptr [[MEMCHR]], ptr @chp, align 4
; CHECK-NEXT: ret void
;
define ptr @xform_strchr_s21111_C(i32 %C) {
; CHECK-LABEL: @xform_strchr_s21111_C(
-; CHECK-NEXT: [[MEMCHR:%.*]] = call ptr @memchr(ptr noundef nonnull @s21111, i32 [[C:%.*]], i64 6)
+; CHECK-NEXT: [[MEMCHR:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @s21111, i32 [[C:%.*]], i64 6)
; CHECK-NEXT: ret ptr [[MEMCHR]]
;
%ret = call ptr @strchr(ptr @s21111, i32 %C)
; Negative tests
define i32 @strcmp_memcmp_bad(ptr dereferenceable (12) %buf) nofree nosync {
; CHECK-LABEL: @strcmp_memcmp_bad(
-; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr noundef nonnull [[BUF:%.*]], ptr noundef nonnull dereferenceable(4) @key)
+; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) [[BUF:%.*]], ptr noundef nonnull dereferenceable(4) @key)
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[CALL]], 3
; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT: ret i32 [[CONV]]
define i32 @strcmp_memcmp_bad2(ptr dereferenceable (12) %buf) nofree nosync {
; CHECK-LABEL: @strcmp_memcmp_bad2(
-; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr noundef nonnull dereferenceable(4) @key, ptr noundef nonnull [[BUF:%.*]])
+; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr noundef nonnull dereferenceable(4) @key, ptr noundef nonnull dereferenceable(1) [[BUF:%.*]])
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[CALL]], 3
; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT: ret i32 [[CONV]]
define i32 @strcmp_memcmp_bad3(ptr dereferenceable (12) %buf) nofree nosync {
; CHECK-LABEL: @strcmp_memcmp_bad3(
-; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr noundef nonnull [[BUF:%.*]], ptr noundef nonnull dereferenceable(4) @key)
+; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) [[BUF:%.*]], ptr noundef nonnull dereferenceable(4) @key)
; CHECK-NEXT: ret i32 [[CALL]]
;
%call = call i32 @strcmp(ptr nonnull %buf, ptr @key)
define i32 @strcmp_memcmp_bad5(ptr dereferenceable (3) %buf) nofree nosync {
; CHECK-LABEL: @strcmp_memcmp_bad5(
-; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr noundef nonnull [[BUF:%.*]], ptr noundef nonnull dereferenceable(4) @key)
+; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) [[BUF:%.*]], ptr noundef nonnull dereferenceable(4) @key)
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT: ret i32 [[CONV]]
define i32 @strcmp_memcmp_bad6(ptr dereferenceable (4) %buf, ptr nocapture readonly %k) nofree nosync {
; CHECK-LABEL: @strcmp_memcmp_bad6(
-; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr noundef nonnull [[BUF:%.*]], ptr noundef nonnull dereferenceable(1) [[K:%.*]])
+; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) [[BUF:%.*]], ptr noundef nonnull dereferenceable(1) [[K:%.*]])
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT: ret i32 [[CONV]]
define i32 @strcmp_memcmp_bad8(ptr dereferenceable (4) %buf) nofree nosync {
; CHECK-LABEL: @strcmp_memcmp_bad8(
-; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr noundef nonnull [[BUF:%.*]], ptr noundef nonnull dereferenceable(4) @key)
+; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) [[BUF:%.*]], ptr noundef nonnull dereferenceable(4) @key)
; CHECK-NEXT: tail call void @use(i32 [[CALL]])
; CHECK-NEXT: ret i32 0
;
define i32 @strncmp_memcmp_bad(ptr dereferenceable (12) %buf) nofree nosync {
; CHECK-LABEL: @strncmp_memcmp_bad(
-; CHECK-NEXT: [[CALL:%.*]] = call i32 @strncmp(ptr noundef nonnull dereferenceable(4) @key, ptr noundef nonnull [[BUF:%.*]], i64 5)
+; CHECK-NEXT: [[CALL:%.*]] = call i32 @strncmp(ptr noundef nonnull dereferenceable(4) @key, ptr noundef nonnull dereferenceable(1) [[BUF:%.*]], i64 5)
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[CALL]], 3
; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT: ret i32 [[CONV]]
define i32 @strncmp_memcmp_bad1(ptr dereferenceable (12) %buf) nofree nosync {
; CHECK-LABEL: @strncmp_memcmp_bad1(
-; CHECK-NEXT: [[CALL:%.*]] = call i32 @strncmp(ptr noundef nonnull dereferenceable(4) @key, ptr noundef nonnull [[BUF:%.*]], i64 5)
+; CHECK-NEXT: [[CALL:%.*]] = call i32 @strncmp(ptr noundef nonnull dereferenceable(4) @key, ptr noundef nonnull dereferenceable(1) [[BUF:%.*]], i64 5)
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[CALL]], 3
; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT: ret i32 [[CONV]]
define i32 @strncmp_memcmp_bad4(ptr dereferenceable (4) %buf) nofree nosync {
; CHECK-LABEL: @strncmp_memcmp_bad4(
-; CHECK-NEXT: [[CALL:%.*]] = call i32 @strncmp(ptr noundef nonnull [[BUF:%.*]], ptr noundef nonnull dereferenceable(4) @key, i64 2)
+; CHECK-NEXT: [[CALL:%.*]] = call i32 @strncmp(ptr noundef nonnull dereferenceable(1) [[BUF:%.*]], ptr noundef nonnull dereferenceable(4) @key, i64 2)
; CHECK-NEXT: tail call void @use(i32 [[CALL]])
; CHECK-NEXT: ret i32 0
;
define i32 @strcmp_memcmp_msan(ptr dereferenceable (12) %buf) sanitize_memory {
; CHECK-LABEL: @strcmp_memcmp_msan(
-; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr noundef nonnull [[BUF:%.*]], ptr noundef nonnull dereferenceable(4) @key)
+; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) [[BUF:%.*]], ptr noundef nonnull dereferenceable(4) @key)
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0
; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[CMP]] to i32
; CHECK-NEXT: ret i32 [[CONV]]
define ptr @test_no_simplify1() {
; CHECK-LABEL: @test_no_simplify1(
-; CHECK-NEXT: [[RET:%.*]] = call ptr @strcpy(ptr noundef nonnull @a, ptr noundef nonnull @b)
+; CHECK-NEXT: [[RET:%.*]] = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) @a, ptr noundef nonnull dereferenceable(1) @b)
; CHECK-NEXT: ret ptr [[RET]]
;
; ANY-NEXT: call void @sink(ptr [[DST]], i64 [[NS0_N]])
; ANY-NEXT: [[NS1_N:%.*]] = call i64 @strlcpy(ptr [[DST]], ptr noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x i8], ptr @s4, i64 0, i64 3), i64 [[N]])
; ANY-NEXT: call void @sink(ptr [[DST]], i64 [[NS1_N]])
-; ANY-NEXT: [[NS4_N:%.*]] = call i64 @strlcpy(ptr [[DST]], ptr noundef nonnull @s4, i64 [[N]])
+; ANY-NEXT: [[NS4_N:%.*]] = call i64 @strlcpy(ptr [[DST]], ptr noundef nonnull dereferenceable(1) @s4, i64 [[N]])
; ANY-NEXT: call void @sink(ptr [[DST]], i64 [[NS4_N]])
; ANY-NEXT: ret void
;
define i32 @test_no_simplify1() {
; CHECK-LABEL: @test_no_simplify1(
-; CHECK-NEXT: [[A_L:%.*]] = call i32 @strlen(ptr noundef nonnull @a)
+; CHECK-NEXT: [[A_L:%.*]] = call i32 @strlen(ptr noundef nonnull dereferenceable(1) @a)
; CHECK-NEXT: ret i32 [[A_L]]
;
%a_l = call i32 @strlen(ptr @a)
define i32 @test_no_simplify2(i32 %x) {
; CHECK-LABEL: @test_no_simplify2(
; CHECK-NEXT: [[HELLO_P:%.*]] = getelementptr inbounds [7 x i8], ptr @null_hello, i32 0, i32 [[X:%.*]]
-; CHECK-NEXT: [[HELLO_L:%.*]] = call i32 @strlen(ptr noundef nonnull [[HELLO_P]])
+; CHECK-NEXT: [[HELLO_L:%.*]] = call i32 @strlen(ptr noundef nonnull dereferenceable(1) [[HELLO_P]])
; CHECK-NEXT: ret i32 [[HELLO_L]]
;
%hello_p = getelementptr inbounds [7 x i8], ptr @null_hello, i32 0, i32 %x
; CHECK-LABEL: @test_no_simplify3(
; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 15
; CHECK-NEXT: [[HELLO_P:%.*]] = getelementptr inbounds [13 x i8], ptr @null_hello_mid, i32 0, i32 [[AND]]
-; CHECK-NEXT: [[HELLO_L:%.*]] = call i32 @strlen(ptr noundef nonnull [[HELLO_P]])
+; CHECK-NEXT: [[HELLO_L:%.*]] = call i32 @strlen(ptr noundef nonnull dereferenceable(1) [[HELLO_P]])
; CHECK-NEXT: ret i32 [[HELLO_L]]
;
%and = and i32 %x, 15
; CHECK-LABEL: @fold_strlen_s3_pi_s5(
; CHECK-NEXT: [[PS3_PI:%.*]] = getelementptr inbounds [4 x i8], ptr @s3, i64 0, i64 [[I:%.*]]
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], ptr [[PS3_PI]], ptr @s5
-; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull [[SEL]])
+; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) [[SEL]])
; CHECK-NEXT: ret i64 [[LEN]]
;
; CHECK-LABEL: @call_strlen_s5_3_pi_s5(
; CHECK-NEXT: [[PS5_3_PI:%.*]] = getelementptr inbounds [10 x i8], ptr @s5_3, i64 0, i64 [[TMP1:%.*]]
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[TMP0:%.*]], ptr [[PS5_3_PI]], ptr @s5
-; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull [[SEL]])
+; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) [[SEL]])
; CHECK-NEXT: ret i64 [[LEN]]
;
; CHECK-LABEL: @call_strlen_s5_3_s5_pj(
; CHECK-NEXT: [[PS5:%.*]] = getelementptr inbounds [6 x i8], ptr @s5, i64 0, i64 [[J:%.*]]
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], ptr @s5_3, ptr [[PS5]]
-; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull [[SEL]])
+; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) [[SEL]])
; CHECK-NEXT: ret i64 [[LEN]]
;
; CHECK-LABEL: @fold_strlen_s3_s5_pj(
; CHECK-NEXT: [[PS5_PJ:%.*]] = getelementptr inbounds [6 x i8], ptr @s5, i64 0, i64 [[J:%.*]]
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], ptr @s3, ptr [[PS5_PJ]]
-; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull [[SEL]])
+; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) [[SEL]])
; CHECK-NEXT: ret i64 [[LEN]]
;
; CHECK-LABEL: @call_strlen_s3_s5_3_pj(
; CHECK-NEXT: [[PS5_3_PJ:%.*]] = getelementptr inbounds [10 x i8], ptr @s5_3, i64 0, i64 [[TMP1:%.*]]
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[TMP0:%.*]], ptr @s3, ptr [[PS5_3_PJ]]
-; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull [[SEL]])
+; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) [[SEL]])
; CHECK-NEXT: ret i64 [[LEN]]
;
; CHECK-NEXT: [[PS3_PI:%.*]] = getelementptr inbounds [4 x i8], ptr @s3, i64 0, i64 [[I:%.*]]
; CHECK-NEXT: [[PS5_PJ:%.*]] = getelementptr inbounds [6 x i8], ptr @s5, i64 0, i64 [[J:%.*]]
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], ptr [[PS3_PI]], ptr [[PS5_PJ]]
-; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull [[SEL]])
+; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) [[SEL]])
; CHECK-NEXT: ret i64 [[LEN]]
;
; Use CHECK-DAG since the two instructions below might be emitted in reverse
; CHECK-NEXT: [[X_EQ_5:%.*]] = icmp eq i32 [[X]], 5
; CHECK-NEXT: [[SEL_X_EQ_5:%.*]] = select i1 [[X_EQ_5]], ptr @s5, ptr @s7
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X_EQ_3]], ptr @s3, ptr [[SEL_X_EQ_5]]
-; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull [[SEL]])
+; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) [[SEL]])
; CHECK-NEXT: ret i64 [[LEN]]
;
; CHECK-NEXT: [[X_EQ_5:%.*]] = icmp eq i32 [[X]], 5
; CHECK-NEXT: [[SEL_X_EQ_5:%.*]] = select i1 [[X_EQ_5]], ptr @s5, ptr @s7
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X_EQ_3]], ptr @sx, ptr [[SEL_X_EQ_5]]
-; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull [[SEL]])
+; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) [[SEL]])
; CHECK-NEXT: ret i64 [[LEN]]
;
define void @test_simplify1() {
; CHECK-LABEL: @test_simplify1(
-; CHECK-NEXT: [[STRLEN:%.*]] = call i32 @strlen(ptr noundef nonnull @a)
+; CHECK-NEXT: [[STRLEN:%.*]] = call i32 @strlen(ptr noundef nonnull dereferenceable(1) @a)
; CHECK-NEXT: [[ENDPTR:%.*]] = getelementptr inbounds i8, ptr @a, i32 [[STRLEN]]
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(6) [[ENDPTR]], ptr noundef nonnull align 1 dereferenceable(6) @hello, i32 6, i1 false)
; CHECK-NEXT: ret void
define void @test_nosimplify1() {
; CHECK-LABEL: @test_nosimplify1(
-; CHECK-NEXT: [[TMP1:%.*]] = call ptr @strncat(ptr noundef nonnull @a, ptr noundef nonnull dereferenceable(6) @hello, i32 1)
+; CHECK-NEXT: [[TMP1:%.*]] = call ptr @strncat(ptr noundef nonnull dereferenceable(1) @a, ptr noundef nonnull dereferenceable(6) @hello, i32 1)
; CHECK-NEXT: ret void
;
; strncat(nonnull x, nonnull y, n) -> strncat(nonnull x, y, n)
define ptr @test1(ptr %str1, ptr %str2, i32 %n) {
; CHECK-LABEL: @test1(
-; CHECK-NEXT: [[TEMP1:%.*]] = call ptr @strncat(ptr noundef nonnull [[STR1:%.*]], ptr nonnull [[STR2:%.*]], i32 [[N:%.*]])
+; CHECK-NEXT: [[TEMP1:%.*]] = call ptr @strncat(ptr noundef nonnull dereferenceable(1) [[STR1:%.*]], ptr nonnull [[STR2:%.*]], i32 [[N:%.*]])
; CHECK-NEXT: ret ptr [[TEMP1]]
;
define i32 @call_strncmp_ax_bx_uimax_p1() {
; CHECK-LABEL: @call_strncmp_ax_bx_uimax_p1(
-; CHECK-NEXT: [[RES:%.*]] = call i32 @strncmp(ptr noundef nonnull @ax, ptr noundef nonnull @bx, i64 4294967296)
+; CHECK-NEXT: [[RES:%.*]] = call i32 @strncmp(ptr noundef nonnull dereferenceable(1) @ax, ptr noundef nonnull dereferenceable(1) @bx, i64 4294967296)
; CHECK-NEXT: ret i32 [[RES]]
;
define i32 @call_strncmp_ax_bx_uimax_p2() {
; CHECK-LABEL: @call_strncmp_ax_bx_uimax_p2(
-; CHECK-NEXT: [[RES:%.*]] = call i32 @strncmp(ptr noundef nonnull @ax, ptr noundef nonnull @bx, i64 4294967296)
+; CHECK-NEXT: [[RES:%.*]] = call i32 @strncmp(ptr noundef nonnull dereferenceable(1) @ax, ptr noundef nonnull dereferenceable(1) @bx, i64 4294967296)
; CHECK-NEXT: ret i32 [[RES]]
;
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(6) [[TARGET]], ptr noundef nonnull align 1 dereferenceable(6) @hello, i32 6, i1 false)
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(42) [[TARGET]], i8 0, i32 42, i1 false)
; CHECK-NEXT: call void @llvm.memset.p0.i32(ptr noundef nonnull align 1 dereferenceable(42) [[TARGET]], i8 0, i32 42, i1 false)
-; CHECK-NEXT: [[TMP1:%.*]] = call i32 @puts(ptr noundef nonnull [[TARGET]])
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @puts(ptr noundef nonnull dereferenceable(1) [[TARGET]])
; CHECK-NEXT: ret i32 0
;
%target = alloca [1024 x i8]
define void @test_no_simplify1() {
; CHECK-LABEL: @test_no_simplify1(
-; CHECK-NEXT: [[TMP1:%.*]] = call ptr @strncpy(ptr noundef nonnull @a, ptr noundef nonnull @b, i32 32)
+; CHECK-NEXT: [[TMP1:%.*]] = call ptr @strncpy(ptr noundef nonnull dereferenceable(1) @a, ptr noundef nonnull dereferenceable(1) @b, i32 32)
; CHECK-NEXT: ret void
;
define i64 @fold_strnlen_s3_s5_3(i1 %C) {
; CHECK-LABEL: @fold_strnlen_s3_s5_3(
; CHECK-NEXT: [[PTR:%.*]] = select i1 [[C:%.*]], ptr @s3, ptr @s6
-; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull [[PTR]], i64 3)
+; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull dereferenceable(1) [[PTR]], i64 3)
; CHECK-NEXT: ret i64 [[LEN]]
;
%ptr = select i1 %C, ptr @s3, ptr @s6
define i64 @fold_strnlen_s3_s5_4(i1 %C) {
; CHECK-LABEL: @fold_strnlen_s3_s5_4(
; CHECK-NEXT: [[PTR:%.*]] = select i1 [[C:%.*]], ptr @s3, ptr @s6
-; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull [[PTR]], i64 4)
+; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull dereferenceable(1) [[PTR]], i64 4)
; CHECK-NEXT: ret i64 [[LEN]]
;
%ptr = select i1 %C, ptr @s3, ptr @s6
define i64 @fold_strnlen_s3_s5_5(i1 %C) {
; CHECK-LABEL: @fold_strnlen_s3_s5_5(
; CHECK-NEXT: [[PTR:%.*]] = select i1 [[C:%.*]], ptr @s3, ptr @s6
-; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull [[PTR]], i64 5)
+; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull dereferenceable(1) [[PTR]], i64 5)
; CHECK-NEXT: ret i64 [[LEN]]
;
%ptr = select i1 %C, ptr @s3, ptr @s6
define i64 @fold_strnlen_s5_6(i1 %C) {
; CHECK-LABEL: @fold_strnlen_s5_6(
; CHECK-NEXT: [[PTR:%.*]] = select i1 [[C:%.*]], ptr @s5, ptr @s6
-; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull [[PTR]], i64 6)
+; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull dereferenceable(1) [[PTR]], i64 6)
; CHECK-NEXT: ret i64 [[LEN]]
;
; CHECK-NEXT: [[X_EQ_5:%.*]] = icmp eq i32 [[X]], 5
; CHECK-NEXT: [[SEL_X_EQ_5:%.*]] = select i1 [[X_EQ_5]], ptr @s5, ptr @s7
; CHECK-NEXT: [[SEL_X_EQ_3:%.*]] = select i1 [[X_EQ_3]], ptr @s3, ptr [[SEL_X_EQ_5]]
-; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strnlen(ptr noundef nonnull [[SEL_X_EQ_3]], i64 4)
+; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strnlen(ptr noundef nonnull dereferenceable(1) [[SEL_X_EQ_3]], i64 4)
; CHECK-NEXT: ret i64 [[LEN]]
;
; CHECK-NEXT: [[X_EQ_5:%.*]] = icmp eq i32 [[X]], 5
; CHECK-NEXT: [[SEL_X_EQ_5:%.*]] = select i1 [[X_EQ_5]], ptr @s5, ptr @s7
; CHECK-NEXT: [[SEL_X_EQ_3:%.*]] = select i1 [[X_EQ_3]], ptr @s3, ptr [[SEL_X_EQ_5]]
-; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strnlen(ptr noundef nonnull [[SEL_X_EQ_3]], i64 6)
+; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strnlen(ptr noundef nonnull dereferenceable(1) [[SEL_X_EQ_3]], i64 6)
; CHECK-NEXT: ret i64 [[LEN]]
;
; CHECK-NEXT: [[X_EQ_5:%.*]] = icmp eq i32 [[X]], 5
; CHECK-NEXT: [[SEL_X_EQ_5:%.*]] = select i1 [[X_EQ_5]], ptr @s5, ptr @s7
; CHECK-NEXT: [[SEL_X_EQ_3:%.*]] = select i1 [[X_EQ_3]], ptr @s3, ptr [[SEL_X_EQ_5]]
-; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strnlen(ptr noundef nonnull [[SEL_X_EQ_3]], i64 8)
+; CHECK-NEXT: [[LEN:%.*]] = tail call i64 @strnlen(ptr noundef nonnull dereferenceable(1) [[SEL_X_EQ_3]], i64 8)
; CHECK-NEXT: ret i64 [[LEN]]
;
define i64 @call_strnlen_a3_pi_2(i64 %i) {
; CHECK-LABEL: @call_strnlen_a3_pi_2(
; CHECK-NEXT: [[PTR:%.*]] = getelementptr inbounds [3 x i8], ptr @a3, i64 0, i64 [[I:%.*]]
-; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull [[PTR]], i64 2)
+; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull dereferenceable(1) [[PTR]], i64 2)
; CHECK-NEXT: ret i64 [[LEN]]
;
define i64 @call_strnlen_a3_pi_3(i64 %i) {
; CHECK-LABEL: @call_strnlen_a3_pi_3(
; CHECK-NEXT: [[PTR:%.*]] = getelementptr inbounds [3 x i8], ptr @a3, i64 0, i64 [[I:%.*]]
-; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull [[PTR]], i64 3)
+; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull dereferenceable(1) [[PTR]], i64 3)
; CHECK-NEXT: ret i64 [[LEN]]
;
define i64 @fold_strnlen_a3_pi_2(i64 %i) {
; CHECK-LABEL: @fold_strnlen_a3_pi_2(
; CHECK-NEXT: [[PTR:%.*]] = getelementptr inbounds [3 x i8], ptr @a3, i64 0, i64 [[I:%.*]]
-; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull [[PTR]], i64 2)
+; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull dereferenceable(1) [[PTR]], i64 2)
; CHECK-NEXT: ret i64 [[LEN]]
;
define i64 @fold_strnlen_s3_pi_2(i64 %i) {
; CHECK-LABEL: @fold_strnlen_s3_pi_2(
; CHECK-NEXT: [[PTR:%.*]] = getelementptr inbounds [4 x i8], ptr @s3, i64 0, i64 [[I:%.*]]
-; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull [[PTR]], i64 2)
+; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull dereferenceable(1) [[PTR]], i64 2)
; CHECK-NEXT: ret i64 [[LEN]]
;
define i64 @fold_strnlen_s3_pi_3(i64 %i) {
; CHECK-LABEL: @fold_strnlen_s3_pi_3(
; CHECK-NEXT: [[PTR:%.*]] = getelementptr inbounds [4 x i8], ptr @s3, i64 0, i64 [[I:%.*]]
-; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull [[PTR]], i64 3)
+; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull dereferenceable(1) [[PTR]], i64 3)
; CHECK-NEXT: ret i64 [[LEN]]
;
define i64 @call_strnlen_s5_3_pi_2(i64 %i) {
; CHECK-LABEL: @call_strnlen_s5_3_pi_2(
; CHECK-NEXT: [[PTR:%.*]] = getelementptr inbounds [10 x i8], ptr @s5_3, i64 0, i64 [[I:%.*]]
-; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull [[PTR]], i64 2)
+; CHECK-NEXT: [[LEN:%.*]] = call i64 @strnlen(ptr noundef nonnull dereferenceable(1) [[PTR]], i64 2)
; CHECK-NEXT: ret i64 [[LEN]]
;