aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/InlineFunction.cpp
diff options
context:
space:
mode:
authorSteven Perron <stevenperron@google.com>2024-10-30 11:19:23 -0400
committerGitHub <noreply@github.com>2024-10-30 11:19:23 -0400
commitf405c683ba929fcd0bcaa435ca2fbe4bb221d04b (patch)
tree89d388abaa335d39b28baad85ebe5b521ddb4a8e /llvm/lib/Transforms/Utils/InlineFunction.cpp
parent4015e18d6713cdceb0640e77b2d5aa3b256d5ddb (diff)
downloadllvm-f405c683ba929fcd0bcaa435ca2fbe4bb221d04b.zip
llvm-f405c683ba929fcd0bcaa435ca2fbe4bb221d04b.tar.gz
llvm-f405c683ba929fcd0bcaa435ca2fbe4bb221d04b.tar.bz2
[OPT] Search whole BB for convergence token. (#112728)
The spec for llvm.experimental.convergence.entry says that is must be in the entry block for a function, and must preceed any other convergent operation. It does not have to be the first instruction in the entry block. Inlining assumes that the call to llvm.experimental.convergence.entry will be the first instruction after any phi instructions. This commit modifies inlining to search the entire block for the call.
Diffstat (limited to 'llvm/lib/Transforms/Utils/InlineFunction.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/InlineFunction.cpp38
1 files changed, 21 insertions, 17 deletions
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 4ad4262..a27cb4d 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -181,9 +181,21 @@ namespace {
}
}
};
-
} // end anonymous namespace
+static IntrinsicInst *getConvergenceEntry(BasicBlock &BB) {
+ auto *I = BB.getFirstNonPHI();
+ while (I) {
+ if (auto *IntrinsicCall = dyn_cast<ConvergenceControlInst>(I)) {
+ if (IntrinsicCall->isEntry()) {
+ return IntrinsicCall;
+ }
+ }
+ I = I->getNextNode();
+ }
+ return nullptr;
+}
+
/// Get or create a target for the branch from ResumeInsts.
BasicBlock *LandingPadInliningInfo::getInnerResumeDest() {
if (InnerResumeDest) return InnerResumeDest;
@@ -2496,15 +2508,10 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
// fully implements convergence control tokens, there is no mixing of
// controlled and uncontrolled convergent operations in the whole program.
if (CB.isConvergent()) {
- auto *I = CalledFunc->getEntryBlock().getFirstNonPHI();
- if (auto *IntrinsicCall = dyn_cast<IntrinsicInst>(I)) {
- if (IntrinsicCall->getIntrinsicID() ==
- Intrinsic::experimental_convergence_entry) {
- if (!ConvergenceControlToken) {
- return InlineResult::failure(
- "convergent call needs convergencectrl operand");
- }
- }
+ if (!ConvergenceControlToken &&
+ getConvergenceEntry(CalledFunc->getEntryBlock())) {
+ return InlineResult::failure(
+ "convergent call needs convergencectrl operand");
}
}
@@ -2795,13 +2802,10 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
}
if (ConvergenceControlToken) {
- auto *I = FirstNewBlock->getFirstNonPHI();
- if (auto *IntrinsicCall = dyn_cast<IntrinsicInst>(I)) {
- if (IntrinsicCall->getIntrinsicID() ==
- Intrinsic::experimental_convergence_entry) {
- IntrinsicCall->replaceAllUsesWith(ConvergenceControlToken);
- IntrinsicCall->eraseFromParent();
- }
+ IntrinsicInst *IntrinsicCall = getConvergenceEntry(*FirstNewBlock);
+ if (IntrinsicCall) {
+ IntrinsicCall->replaceAllUsesWith(ConvergenceControlToken);
+ IntrinsicCall->eraseFromParent();
}
}