[llvm] [FunctionAttr] Invalid callers with mismatching signature (PR #154289)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 19 01:35:25 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Nikita Popov (nikic)
<details>
<summary>Changes</summary>
If FunctionAttrs infers additional attributes on a function, it also invalidates analysis on callers of that function. The way it does this right now limits this to calls with matching signature. However, the function attributes will also be used when the signatures do not match. Use getCalledOperand() to avoid a signature check.
This is not a correctness fix, just improves analysis quality. I noticed this due to https://github.com/llvm/llvm-project/pull/144497#issuecomment-3199330709, where LICM ends up with a stale MemoryDef that could be a MemoryUse (which is a bug in LICM, but still non-optimal).
---
Full diff: https://github.com/llvm/llvm-project/pull/154289.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/IPO/FunctionAttrs.cpp (+1-1)
- (added) llvm/test/Transforms/FunctionAttrs/mismatched-signature-invalidation.ll (+31)
``````````diff
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 44394f6deb9a2..7d367fcb21012 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -2328,7 +2328,7 @@ PreservedAnalyses PostOrderFunctionAttrsPass::run(LazyCallGraph::SCC &C,
// through function attributes.
for (auto *U : Changed->users()) {
if (auto *Call = dyn_cast<CallBase>(U)) {
- if (Call->getCalledFunction() == Changed)
+ if (Call->getCalledOperand() == Changed)
FAM.invalidate(*Call->getFunction(), FuncPA);
}
}
diff --git a/llvm/test/Transforms/FunctionAttrs/mismatched-signature-invalidation.ll b/llvm/test/Transforms/FunctionAttrs/mismatched-signature-invalidation.ll
new file mode 100644
index 0000000000000..c42535756e8f1
--- /dev/null
+++ b/llvm/test/Transforms/FunctionAttrs/mismatched-signature-invalidation.ll
@@ -0,0 +1,31 @@
+; RUN: opt -disable-output -passes="function(print<memoryssa>),cgscc(function-attrs),function(print<memoryssa>)" < %s 2>&1 | FileCheck %s
+
+ at g = external global i16
+
+define i16 @fn() {
+ %v = load i16, ptr @g
+ ret i16 %v
+}
+
+declare void @fn2(i16)
+
+; CHECK-LABEL: MemorySSA for function: test
+; CHECK: 1 = MemoryDef(3)
+; CHECK-NEXT: %call = call i16 @fn(i32 0)
+
+; CHECK-LABEL: MemorySSA for function: test
+; CHECK: MemoryUse(2)
+; CHECK-NEXT: %call = call i16 @fn(i32 0)
+
+define void @test() {
+entry:
+ br label %loop
+
+loop:
+ %call = call i16 @fn(i32 0) ; intentional signature mismatch
+ call void @fn2(i16 %call)
+ br i1 false, label %loop, label %exit
+
+exit:
+ ret void
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/154289
More information about the llvm-commits
mailing list