diff options
author | Florian Hahn <flo@fhahn.com> | 2025-07-31 17:52:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-31 17:52:45 +0100 |
commit | 69f3ea08522eca4b8617145fdafb8fc6595ddf97 (patch) | |
tree | 77b8347a0092e52c5c2ff68e3442f01bd39c302c | |
parent | 3ca2050aa62bde68c74ddbb6c2501bd49831dd22 (diff) | |
download | llvm-69f3ea08522eca4b8617145fdafb8fc6595ddf97.zip llvm-69f3ea08522eca4b8617145fdafb8fc6595ddf97.tar.gz llvm-69f3ea08522eca4b8617145fdafb8fc6595ddf97.tar.bz2 |
[MachineBB] Make sure there are successors in terminatorIsComputedGoto. (#151342)
Currently terminatorIsComputedGoto will return for blocks with a
indirect branch terminator and no successor. If there are no successor,
the terminator is likely not a computed goto, return false in that case.
Note that this is currently NFC, as the only use checks it only if there
are successors, but it will be needed in
https://github.com/llvm/llvm-project/pull/150911.
PR: https://github.com/llvm/llvm-project/pull/151342
-rw-r--r-- | llvm/include/llvm/CodeGen/MachineBasicBlock.h | 9 | ||||
-rw-r--r-- | llvm/lib/CodeGen/TailDuplicator.cpp | 2 |
2 files changed, 6 insertions, 5 deletions
diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h index 938d71d..9e3d919 100644 --- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h +++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h @@ -323,10 +323,11 @@ public: const MachineFunction *getParent() const { return xParent; } MachineFunction *getParent() { return xParent; } - /// Returns true if the original IR terminator is an `indirectbr`. This - /// typically corresponds to a `goto` in C, rather than jump tables. - bool terminatorIsComputedGoto() const { - return back().isIndirectBranch() && + /// Returns true if the original IR terminator is an `indirectbr` with + /// successor blocks. This typically corresponds to a `goto` in C, rather than + /// jump tables. + bool terminatorIsComputedGotoWithSuccessors() const { + return back().isIndirectBranch() && !succ_empty() && llvm::all_of(successors(), [](const MachineBasicBlock *Succ) { return Succ->isIRBlockAddressTaken(); }); diff --git a/llvm/lib/CodeGen/TailDuplicator.cpp b/llvm/lib/CodeGen/TailDuplicator.cpp index a88c57f..d319a97 100644 --- a/llvm/lib/CodeGen/TailDuplicator.cpp +++ b/llvm/lib/CodeGen/TailDuplicator.cpp @@ -604,7 +604,7 @@ bool TailDuplicator::shouldTailDuplicate(bool IsSimple, bool HasComputedGoto = false; if (!TailBB.empty()) { HasIndirectbr = TailBB.back().isIndirectBranch(); - HasComputedGoto = TailBB.terminatorIsComputedGoto(); + HasComputedGoto = TailBB.terminatorIsComputedGotoWithSuccessors(); } if (HasIndirectbr && PreRegAlloc) |