[llvm] da137d0 - [SimplifyLibCalls] Add NoUndef/NonNull/Dereferenceable attributes to iprintf/siprintf

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 18 07:37:05 PDT 2022


Author: uabkaka
Date: 2022-10-18T16:36:35+02:00
New Revision: da137d041b3766db755ab390528ea5d9eb60d0f0

URL: https://github.com/llvm/llvm-project/commit/da137d041b3766db755ab390528ea5d9eb60d0f0
DIFF: https://github.com/llvm/llvm-project/commit/da137d041b3766db755ab390528ea5d9eb60d0f0.diff

LOG: [SimplifyLibCalls] Add NoUndef/NonNull/Dereferenceable attributes to iprintf/siprintf

When SimplifyLibCalls fail to optimize printf and sprintf it add
NoUndef/NonNull/Dereferenceable attributes. This patch add the same attributes
if SimplifyLibCalls optimize printf/sprintf into the integer only
iprintf/siprintf.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D136140

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
    llvm/test/Transforms/InstCombine/printf-1.ll
    llvm/test/Transforms/InstCombine/sprintf-1.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 8f25e80a6c5a..dd25fb3e9a84 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -2887,6 +2887,8 @@ Value *LibCallSimplifier::optimizePrintF(CallInst *CI, IRBuilderBase &B) {
     return V;
   }
 
+  annotateNonNullNoUndefBasedOnAccess(CI, 0);
+
   // printf(format, ...) -> iprintf(format, ...) if no floating point
   // arguments.
   if (isLibFuncEmittable(M, TLI, LibFunc_iprintf) &&
@@ -2911,7 +2913,6 @@ Value *LibCallSimplifier::optimizePrintF(CallInst *CI, IRBuilderBase &B) {
     return New;
   }
 
-  annotateNonNullNoUndefBasedOnAccess(CI, 0);
   return nullptr;
 }
 
@@ -3010,6 +3011,8 @@ Value *LibCallSimplifier::optimizeSPrintF(CallInst *CI, IRBuilderBase &B) {
     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 @@ Value *LibCallSimplifier::optimizeSPrintF(CallInst *CI, IRBuilderBase &B) {
     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
index 3fd1ddc14b34..f162b2d948fe 100644
--- a/llvm/test/Transforms/InstCombine/printf-1.ll
+++ b/llvm/test/Transforms/InstCombine/printf-1.ll
@@ -127,7 +127,7 @@ define void @test_simplify7() {
 ; 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 @@ define i32 @test_no_simplify3() {
 ; 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
index ca49dccf6c7c..6b2fddbff5d3 100644
--- a/llvm/test/Transforms/InstCombine/sprintf-1.ll
+++ b/llvm/test/Transforms/InstCombine/sprintf-1.ll
@@ -79,7 +79,7 @@ define void @test_simplify5(ptr %dst, ptr %str) {
 
 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(


        


More information about the llvm-commits mailing list