Skip to content

Commit 5ae749b

Browse files
authored
[FunctionAttr] Invalidate callers with mismatching signature (llvm#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 llvm#144497 (comment), where LICM ends up with a stale MemoryDef that could be a MemoryUse (which is a bug in LICM, but still non-optimal).
1 parent 5dbf73f commit 5ae749b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,7 @@ PreservedAnalyses PostOrderFunctionAttrsPass::run(LazyCallGraph::SCC &C,
23282328
// through function attributes.
23292329
for (auto *U : Changed->users()) {
23302330
if (auto *Call = dyn_cast<CallBase>(U)) {
2331-
if (Call->getCalledFunction() == Changed)
2331+
if (Call->getCalledOperand() == Changed)
23322332
FAM.invalidate(*Call->getFunction(), FuncPA);
23332333
}
23342334
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: opt -disable-output -passes="function(print<memoryssa>),cgscc(function-attrs),function(print<memoryssa>)" < %s 2>&1 | FileCheck %s
2+
3+
@g = external global i16
4+
5+
define i16 @fn() {
6+
%v = load i16, ptr @g
7+
ret i16 %v
8+
}
9+
10+
declare void @fn2(i16)
11+
12+
; CHECK-LABEL: MemorySSA for function: test
13+
; CHECK: 1 = MemoryDef(3)
14+
; CHECK-NEXT: %call = call i16 @fn(i32 0)
15+
16+
; CHECK-LABEL: MemorySSA for function: test
17+
; CHECK: MemoryUse(2)
18+
; CHECK-NEXT: %call = call i16 @fn(i32 0)
19+
20+
define void @test() {
21+
entry:
22+
br label %loop
23+
24+
loop:
25+
%call = call i16 @fn(i32 0) ; intentional signature mismatch
26+
call void @fn2(i16 %call)
27+
br i1 false, label %loop, label %exit
28+
29+
exit:
30+
ret void
31+
}

0 commit comments

Comments
 (0)