[llvm] 5ae749b - [FunctionAttr] Invalidate callers with mismatching signature (#154289)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 20 02:38:35 PDT 2025
Author: Nikita Popov
Date: 2025-08-20T11:38:31+02:00
New Revision: 5ae749b77d0768083da7d2f4f4cb20665a736057
URL: https://github.com/llvm/llvm-project/commit/5ae749b77d0768083da7d2f4f4cb20665a736057
DIFF: https://github.com/llvm/llvm-project/commit/5ae749b77d0768083da7d2f4f4cb20665a736057.diff
LOG: [FunctionAttr] Invalidate callers with mismatching signature (#154289)
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).
Added:
llvm/test/Transforms/FunctionAttrs/mismatched-signature-invalidation.ll
Modified:
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
Removed:
################################################################################
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
+}
More information about the llvm-commits
mailing list