[PATCH] D136140: [SimplifyLibCalls] Add NoUndef/NonNull/Dereferenceable attributes to iprintf/isprintf
Karl-Johan Karlsson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 18 00:41:26 PDT 2022
Ka-Ka created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Ka-Ka requested review of this revision.
Herald added a project: LLVM.
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/isprintf.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D136140
Files:
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/printf-1.ll
llvm/test/Transforms/InstCombine/sprintf-1.ll
Index: llvm/test/Transforms/InstCombine/sprintf-1.ll
===================================================================
--- llvm/test/Transforms/InstCombine/sprintf-1.ll
+++ 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(
Index: llvm/test/Transforms/InstCombine/printf-1.ll
===================================================================
--- llvm/test/Transforms/InstCombine/printf-1.ll
+++ 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)
Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -2896,6 +2896,7 @@
CallInst *New = cast<CallInst>(CI->clone());
New->setCalledFunction(IPrintFFn);
B.Insert(New);
+ annotateNonNullNoUndefBasedOnAccess(New, 0);
return New;
}
@@ -2908,6 +2909,7 @@
CallInst *New = cast<CallInst>(CI->clone());
New->setCalledFunction(SmallPrintFFn);
B.Insert(New);
+ annotateNonNullNoUndefBasedOnAccess(New, 0);
return New;
}
@@ -3019,6 +3021,7 @@
CallInst *New = cast<CallInst>(CI->clone());
New->setCalledFunction(SIPrintFFn);
B.Insert(New);
+ annotateNonNullNoUndefBasedOnAccess(New, {0, 1});
return New;
}
@@ -3031,6 +3034,7 @@
CallInst *New = cast<CallInst>(CI->clone());
New->setCalledFunction(SmallSPrintFFn);
B.Insert(New);
+ annotateNonNullNoUndefBasedOnAccess(New, {0, 1});
return New;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136140.468440.patch
Type: text/x-patch
Size: 2802 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221018/54c12fb0/attachment-0001.bin>
More information about the llvm-commits
mailing list