[llvm] 62cdcd6 - [FuncAttrs] Don't infer willreturn for nonexact definitions
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 21 12:27:48 PDT 2021
Author: sstefan1
Date: 2021-04-21T21:26:09+02:00
New Revision: 62cdcd6c5aee89e2cbdc498e5a6193d19bd498fb
URL: https://github.com/llvm/llvm-project/commit/62cdcd6c5aee89e2cbdc498e5a6193d19bd498fb
DIFF: https://github.com/llvm/llvm-project/commit/62cdcd6c5aee89e2cbdc498e5a6193d19bd498fb.diff
LOG: [FuncAttrs] Don't infer willreturn for nonexact definitions
Discovered during attributor testing comparing stats with
and without the attributor. Willreturn should not be inferred
for nonexact definitions.
Differential Revision: https://reviews.llvm.org/D100988
Added:
Modified:
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
llvm/test/Transforms/FunctionAttrs/willreturn.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 8f80a61ae08ee..ca8660a98ded8 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -1432,6 +1432,12 @@ static bool addNoReturnAttrs(const SCCNodeSet &SCCNodes) {
}
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;
diff --git a/llvm/test/Transforms/FunctionAttrs/willreturn.ll b/llvm/test/Transforms/FunctionAttrs/willreturn.ll
index 1f69c3d80d8b7..35f48e7a344c0 100644
--- a/llvm/test/Transforms/FunctionAttrs/willreturn.ll
+++ b/llvm/test/Transforms/FunctionAttrs/willreturn.ll
@@ -153,5 +153,12 @@ bb2:
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
More information about the llvm-commits
mailing list