diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -2887,6 +2887,8 @@ return V; } + annotateNonNullNoUndefBasedOnAccess(CI, 0); + // printf(format, ...) -> iprintf(format, ...) if no floating point // arguments. if (isLibFuncEmittable(M, TLI, LibFunc_iprintf) && @@ -2911,7 +2913,6 @@ return New; } - annotateNonNullNoUndefBasedOnAccess(CI, 0); return nullptr; } @@ -3010,6 +3011,8 @@ return V; } + annotateNonNullNoUndefBasedOnAccess(CI, {0, 1}); + // sprintf(str, format, ...) -> siprintf(str, format, ...) if no floating // point arguments. if (isLibFuncEmittable(M, TLI, LibFunc_siprintf) && @@ -3034,7 +3037,6 @@ return New; } - annotateNonNullNoUndefBasedOnAccess(CI, {0, 1}); return nullptr; } diff --git a/llvm/test/Transforms/InstCombine/printf-1.ll b/llvm/test/Transforms/InstCombine/printf-1.ll --- a/llvm/test/Transforms/InstCombine/printf-1.ll +++ b/llvm/test/Transforms/InstCombine/printf-1.ll @@ -127,7 +127,7 @@ ; CHECK-NEXT: ret void ; ; CHECK-IPRINTF-LABEL: @test_simplify7( -; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @iprintf(ptr nonnull @percent_d, i32 187) +; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @iprintf(ptr noundef nonnull dereferenceable(1) @percent_d, i32 187) ; CHECK-IPRINTF-NEXT: ret void ; call i32 (ptr, ...) @printf(ptr @percent_d, i32 187) @@ -166,7 +166,7 @@ ; CHECK-NEXT: ret i32 [[RET]] ; ; CHECK-IPRINTF-LABEL: @test_no_simplify3( -; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @iprintf(ptr nonnull @h) +; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ...) @iprintf(ptr noundef nonnull dereferenceable(1) @h) ; CHECK-IPRINTF-NEXT: ret i32 [[TMP1]] ; %ret = call i32 (ptr, ...) @printf(ptr @h) diff --git a/llvm/test/Transforms/InstCombine/sprintf-1.ll b/llvm/test/Transforms/InstCombine/sprintf-1.ll --- a/llvm/test/Transforms/InstCombine/sprintf-1.ll +++ b/llvm/test/Transforms/InstCombine/sprintf-1.ll @@ -79,7 +79,7 @@ define void @test_simplify6(ptr %dst) { ; CHECK-IPRINTF-LABEL: @test_simplify6( -; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ptr, ...) @siprintf(ptr [[DST:%.*]], ptr nonnull @percent_d, i32 187) +; CHECK-IPRINTF-NEXT: [[TMP1:%.*]] = call i32 (ptr, ptr, ...) @siprintf(ptr noundef nonnull dereferenceable(1) [[DST:%.*]], ptr noundef nonnull dereferenceable(1) @percent_d, i32 187) ; CHECK-IPRINTF-NEXT: ret void ; ; WIN-LABEL: @test_simplify6(