[PATCH] D100988: [FuncAttrs] Don't infer willreturn for nonexact definitions
Stefan Stipanovic via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 21 12:06:58 PDT 2021
sstefan1 created this revision.
sstefan1 added reviewers: jdoerfert, reames.
Herald added subscribers: uenoku, hiraditya.
Herald added a reviewer: uenoku.
sstefan1 requested review of this revision.
Herald added a reviewer: baziotis.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Discovered during attributor testing comparing stats with
and without the attributor. Willreturn should not be inferred
for nonexact definitions.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D100988
Files:
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
llvm/test/Transforms/FunctionAttrs/willreturn.ll
Index: llvm/test/Transforms/FunctionAttrs/willreturn.ll
===================================================================
--- llvm/test/Transforms/FunctionAttrs/willreturn.ll
+++ llvm/test/Transforms/FunctionAttrs/willreturn.ll
@@ -153,5 +153,12 @@
br label %bb1
}
+define linkonce i32 @square(i32) {
+; CHECK-NOT: Function Attrs: {{.*}}willreturn
+; CHECK: define linkonce i32 @square(
+ %2 = mul nsw i32 %0, %0
+ ret i32 %2
+}
+
declare i64 @fn_noread() readnone
declare void @fn_willreturn() willreturn
Index: llvm/lib/Transforms/IPO/FunctionAttrs.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -1432,6 +1432,12 @@
}
static bool functionWillReturn(const Function &F) {
+ // We can infer and propagate function attributes only when we know that the
+ // definition we'll get at link time is *exactly* the definition we see now.
+ // For more details, see GlobalValue::mayBeDerefined.
+ if (!F.hasExactDefinition())
+ return false;
+
// Must-progress function without side-effects must return.
if (F.mustProgress() && F.onlyReadsMemory())
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100988.339340.patch
Type: text/x-patch
Size: 1211 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210421/285aca17/attachment.bin>
More information about the llvm-commits
mailing list