[PATCH] D156397: [FunctionAttrs] Unconditionally perform argument attribute inference in the first function-attrs pass
Changpeng Fang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 8 13:55:29 PDT 2023
cfang updated this revision to Diff 548345.
cfang added a comment.
update a comment
add pre-commit of the LIT to show the diff from this patch.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156397/new/
https://reviews.llvm.org/D156397
Files:
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
llvm/test/Transforms/InstCombine/unused-nonnull.ll
llvm/test/Transforms/PhaseOrdering/early-arg-attrs-inference.ll
Index: llvm/test/Transforms/PhaseOrdering/early-arg-attrs-inference.ll
===================================================================
--- llvm/test/Transforms/PhaseOrdering/early-arg-attrs-inference.ll
+++ llvm/test/Transforms/PhaseOrdering/early-arg-attrs-inference.ll
@@ -4,16 +4,13 @@
define i32 @f(ptr noalias %p, i32 %c) {
; CHECK-LABEL: define i32 @f
; CHECK-SAME: (ptr noalias nocapture readonly [[P:%.*]], i32 [[C:%.*]]) local_unnamed_addr {
-; CHECK-NEXT: [[I:%.*]] = load i32, ptr [[P]], align 4
; CHECK-NEXT: tail call void @g()
; CHECK-NEXT: tail call void @g()
; CHECK-NEXT: tail call void @g()
; CHECK-NEXT: tail call void @g()
; CHECK-NEXT: tail call void @g()
; CHECK-NEXT: tail call void @g()
-; CHECK-NEXT: [[I2:%.*]] = load i32, ptr [[P]], align 4
-; CHECK-NEXT: [[R:%.*]] = sub i32 [[I]], [[I2]]
-; CHECK-NEXT: ret i32 [[R]]
+; CHECK-NEXT: ret i32 0
;
%i = load i32, ptr %p
call void @g()
Index: llvm/test/Transforms/InstCombine/unused-nonnull.ll
===================================================================
--- llvm/test/Transforms/InstCombine/unused-nonnull.ll
+++ llvm/test/Transforms/InstCombine/unused-nonnull.ll
@@ -9,7 +9,7 @@
define i32 @main(i32 %argc, ptr %argv) #0 {
; CHECK-LABEL: define {{[^@]+}}@main
-; CHECK-SAME: (i32 [[ARGC:%.*]], ptr nocapture readnone [[ARGV:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+; CHECK-SAME: (i32 [[ARGC:%.*]], ptr nocapture readonly [[ARGV:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 [[ARGC]], 2
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TMP0]], i32 0, i32 [[ARGC]]
Index: llvm/lib/Transforms/IPO/FunctionAttrs.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -1720,7 +1720,8 @@
template <typename AARGetterT>
static SmallSet<Function *, 8>
-deriveAttrsInPostOrder(ArrayRef<Function *> Functions, AARGetterT &&AARGetter) {
+deriveAttrsInPostOrder(ArrayRef<Function *> Functions, AARGetterT &&AARGetter,
+ bool ArgAttrsOnly) {
SCCNodesResult Nodes = createSCCNodeSet(Functions);
// Bail if the SCC only contains optnone functions.
@@ -1728,6 +1729,10 @@
return {};
SmallSet<Function *, 8> Changed;
+ if (ArgAttrsOnly) {
+ addArgumentAttrs(Nodes.SCCNodes, Changed);
+ return Changed;
+ }
addArgumentReturnedAttrs(Nodes.SCCNodes, Changed);
addMemoryAttrs(Nodes.SCCNodes, AARGetter, Changed);
@@ -1762,10 +1767,13 @@
LazyCallGraph &CG,
CGSCCUpdateResult &) {
// Skip non-recursive functions if requested.
+ // Only infer argument attributes for non-recursive functions, because
+ // it can affect optimization behavior in conjunction with noalias.
+ bool ArgAttrsOnly = false;
if (C.size() == 1 && SkipNonRecursive) {
LazyCallGraph::Node &N = *C.begin();
if (!N->lookup(N))
- return PreservedAnalyses::all();
+ ArgAttrsOnly = true;
}
FunctionAnalysisManager &FAM =
@@ -1782,7 +1790,8 @@
Functions.push_back(&N.getFunction());
}
- auto ChangedFunctions = deriveAttrsInPostOrder(Functions, AARGetter);
+ auto ChangedFunctions =
+ deriveAttrsInPostOrder(Functions, AARGetter, ArgAttrsOnly);
if (ChangedFunctions.empty())
return PreservedAnalyses::all();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156397.548345.patch
Type: text/x-patch
Size: 3506 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230808/d8193104/attachment.bin>
More information about the llvm-commits
mailing list