Skip to content

Commit 3c54762

Browse files
committed
[funcattrs] Consistently check call site attributes
This is mostly stylistic cleanup after D100226, but not entirely. When skimming the code, I found one case where we weren't accounting for attributes on the callsite at all. I'm also suspicious we had some latent bugs related to operand bundles (which are supposed to be able to *override* attributes on declarations), but I don't have concrete test cases for those, just suspicions. Aside: The only case left in the file which directly checks attributes on the declaration is the norecurse logic. I left that because I didn't understand it; it looks obviously wrong, so I suspect I'm misinterpreting the intended semantics of the attribute. Differential Revision: https://reviews.llvm.org/D100689
1 parent 782c3e2 commit 3c54762

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,15 +1271,10 @@ static bool InstrBreaksNoFree(Instruction &I, const SCCNodeSet &SCCNodes) {
12711271
if (CB->hasFnAttr(Attribute::NoFree))
12721272
return false;
12731273

1274-
Function *Callee = CB->getCalledFunction();
1275-
if (!Callee)
1276-
return true;
1277-
1278-
if (Callee->doesNotFreeMemory())
1279-
return false;
1280-
1281-
if (SCCNodes.contains(Callee))
1282-
return false;
1274+
// Speculatively assume in SCC.
1275+
if (Function *Callee = CB->getCalledFunction())
1276+
if (SCCNodes.contains(Callee))
1277+
return false;
12831278

12841279
return true;
12851280
}
@@ -1403,10 +1398,8 @@ static bool addNoRecurseAttrs(const SCCNodeSet &SCCNodes) {
14031398
}
14041399

14051400
static bool instructionDoesNotReturn(Instruction &I) {
1406-
if (auto *CB = dyn_cast<CallBase>(&I)) {
1407-
Function *Callee = CB->getCalledFunction();
1408-
return Callee && Callee->doesNotReturn();
1409-
}
1401+
if (auto *CB = dyn_cast<CallBase>(&I))
1402+
return CB->hasFnAttr(Attribute::NoReturn);
14101403
return false;
14111404
}
14121405

@@ -1517,13 +1510,6 @@ static bool InstrBreaksNoSync(Instruction &I, const SCCNodeSet &SCCNodes) {
15171510
if (CB->hasFnAttr(Attribute::NoSync))
15181511
return false;
15191512

1520-
// readnone + not convergent implies nosync
1521-
// (This is needed to initialize inference from declarations which aren't
1522-
// explicitly nosync, but are readnone and not convergent.)
1523-
if (CB->hasFnAttr(Attribute::ReadNone) &&
1524-
!CB->hasFnAttr(Attribute::Convergent))
1525-
return false;
1526-
15271513
// Non volatile memset/memcpy/memmoves are nosync
15281514
// NOTE: Only intrinsics with volatile flags should be handled here. All
15291515
// others should be marked in Intrinsics.td.

llvm/test/Transforms/FunctionAttrs/noreturn.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,10 @@ define i32 @caller6() naked {
6464
define i32 @alreadynoreturn() noreturn {
6565
unreachable
6666
}
67+
68+
; CHECK: Function Attrs: {{.*}}noreturn
69+
; CHECK-NEXT: @callsite_noreturn()
70+
define void @callsite_noreturn() {
71+
call i32 @f() noreturn
72+
ret void
73+
}

llvm/test/Transforms/FunctionAttrs/willreturn-callsites.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt -function-attrs -S %s | FileCheck %s
1+
; RUN: opt -inferattrs -function-attrs -S %s | FileCheck %s
22

33
declare void @decl_readonly() readonly
44
declare void @decl_readnone() readnone

0 commit comments

Comments
 (0)