[llvm] [BOLT][AArch64] Expand cmpbr when reversing would overflow (PR #202998)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 10 07:46:33 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Alexandros Lamprineas (labrinea)
<details>
<summary>Changes</summary>
AArch64 compare-and-branch instructions can usually be reversed by changing the condition and adjusting the immediate. At boundary values, that adjustment can underflow or overflow, leaving the branch non-reversible.
When condition flags are dead at such a branch, split the compare branch into an explicit compare followed by a conditional branch. The new sequence lets branch fixup reverse the condition without relying on an out-of-range adjusted immediate.
Teach the branch-fixing paths to use cached branch liveness information when deciding whether this expansion is legal. The liveness snapshot is built before branch relaxation/fixup and is safe for the current users: they only insert trampolines/stubs between existing CFG edges or invert branches without changing program semantics.
Since expansion can grow the source basic block, update the local address accounting used by branch relaxation.
Assisted-by: Codex
---
Patch is 43.92 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/202998.diff
15 Files Affected:
- (modified) bolt/include/bolt/Core/BinaryFunction.h (+3-1)
- (modified) bolt/include/bolt/Core/MCPlusBuilder.h (+24-3)
- (modified) bolt/include/bolt/Passes/LongJmp.h (+4-1)
- (modified) bolt/include/bolt/Utils/CommandLineOpts.h (+4)
- (modified) bolt/lib/Core/BinaryFunction.cpp (+4-3)
- (modified) bolt/lib/Passes/BinaryPasses.cpp (+21-7)
- (modified) bolt/lib/Passes/LongJmp.cpp (+71-33)
- (modified) bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp (+87-15)
- (modified) bolt/lib/Target/AArch64/CMakeLists.txt (+5-1)
- (modified) bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp (+4-2)
- (modified) bolt/lib/Target/X86/X86MCPlusBuilder.cpp (+4-2)
- (modified) bolt/lib/Utils/CommandLineOpts.cpp (+6)
- (modified) bolt/test/AArch64/compare-and-branch-inversion.S (+82-36)
- (modified) bolt/unittests/Core/CMakeLists.txt (+1)
- (modified) bolt/unittests/Core/MCPlusBuilder.cpp (+136-10)
``````````diff
diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h
index 0fdfcc5d76597..c056c05fe6cf1 100644
--- a/bolt/include/bolt/Core/BinaryFunction.h
+++ b/bolt/include/bolt/Core/BinaryFunction.h
@@ -64,6 +64,8 @@ class DWARFUnit;
namespace bolt {
+struct BranchLivenessInfo;
+
using InputOffsetToAddressMapTy = std::unordered_multimap<uint64_t, uint64_t>;
/// Types of macro-fusion alignment corrections.
@@ -2452,7 +2454,7 @@ class BinaryFunction {
/// while the second successor - false/fall-through branch.
///
/// When we reverse the branch condition, the CFG is updated accordingly.
- void fixBranches();
+ void fixBranches(const BranchLivenessInfo *BranchLiveness = nullptr);
/// Mark function as finalized. No further optimizations are permitted.
void setFinalized() { CurrentState = State::CFG_Finalized; }
diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h
index 76b4a5fe778c0..bf19b857aff8b 100644
--- a/bolt/include/bolt/Core/MCPlusBuilder.h
+++ b/bolt/include/bolt/Core/MCPlusBuilder.h
@@ -18,6 +18,7 @@
#include "bolt/Core/Relocation.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/CodeGen/TargetOpcodes.h"
#include "llvm/MC/MCAsmBackend.h"
@@ -52,6 +53,7 @@ namespace bolt {
class BinaryBasicBlock;
class BinaryContext;
class BinaryFunction;
+class DataflowInfoManager;
/// Different types of indirect branches encountered during disassembly.
enum class IndirectBranchType : char {
@@ -73,6 +75,15 @@ enum BTIKind {
JC /// Accepting both.
};
+struct BranchLivenessInfo {
+ DenseMap<const MCInst *, bool> FlagsLiveIn;
+
+ bool mustPreserveFlags(const MCInst &Inst) const {
+ auto It = FlagsLiveIn.find(&Inst);
+ return It == FlagsLiveIn.end() || It->second;
+ }
+};
+
class MCPlusBuilder {
public:
using AllocatorIdTy = uint16_t;
@@ -474,8 +485,15 @@ class MCPlusBuilder {
return false;
}
+ /// Return liveness info required for branch transformations.
+ virtual BranchLivenessInfo
+ createBranchLivenessInfo(BinaryFunction &, DataflowInfoManager &) const {
+ return BranchLivenessInfo();
+ }
+
/// Check whether this conditional branch can be reversed
- virtual bool isReversibleBranch(const MCInst &Inst) const {
+ virtual bool isReversibleBranch(const MCInst &Inst,
+ const BranchLivenessInfo * = nullptr) const {
assert(!isUnsupportedInstruction(Inst) && isConditionalBranch(Inst) &&
"Instruction is not known conditional branch");
@@ -2136,8 +2154,11 @@ class MCPlusBuilder {
}
/// Reverses the branch condition in Inst and update its taken target to TBB.
- virtual void reverseBranchCondition(MCInst &Inst, const MCSymbol *TBB,
- MCContext *Ctx) const {
+ /// Assumes that the branch is reversible.
+ virtual void
+ reverseBranchCondition(BinaryBasicBlock *Parent, MCInst &Inst,
+ const MCSymbol *TBB, MCContext *Ctx,
+ const BranchLivenessInfo * = nullptr) const {
llvm_unreachable("not implemented");
}
diff --git a/bolt/include/bolt/Passes/LongJmp.h b/bolt/include/bolt/Passes/LongJmp.h
index 4633d30104d43..a8a10c619dbca 100644
--- a/bolt/include/bolt/Passes/LongJmp.h
+++ b/bolt/include/bolt/Passes/LongJmp.h
@@ -14,6 +14,8 @@
namespace llvm {
namespace bolt {
+struct BranchLivenessInfo;
+
/// LongJmp is veneer-insertion pass originally written for AArch64 that
/// compensates for its short-range branches, typically done during linking. We
/// pull this pass inside BOLT because here we can do a better job at stub
@@ -74,7 +76,8 @@ class LongJmpPass : public BinaryFunctionPass {
/// Relax all internal function branches including those between fragments.
/// Assume that fragments are placed in different sections but are within
/// 128MB of each other.
- void relaxLocalBranches(BinaryFunction &BF);
+ void relaxLocalBranches(BinaryFunction &BF,
+ const BranchLivenessInfo *BranchLiveness);
/// -- Layout estimation methods --
/// Try to do layout before running the emitter, by looking at BinaryFunctions
diff --git a/bolt/include/bolt/Utils/CommandLineOpts.h b/bolt/include/bolt/Utils/CommandLineOpts.h
index 994e352e16218..56f6048bac36c 100644
--- a/bolt/include/bolt/Utils/CommandLineOpts.h
+++ b/bolt/include/bolt/Utils/CommandLineOpts.h
@@ -124,6 +124,10 @@ extern llvm::cl::opt<bool> UpdateDebugSections;
// dbgs() for output within DEBUG().
extern llvm::cl::opt<unsigned> Verbosity;
+// Option to control whether liveness analysis should be used by
+// FixupBranches and LongJmpPass. Needed for branch inversion on AArch64.
+extern llvm::cl::opt<bool> LivenessAnalysis;
+
/// Return true if we should process all functions in the binary.
bool processAllFunctions();
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 0e538fa48907a..5dca49b686574 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -3632,7 +3632,7 @@ bool BinaryFunction::validateCFG() const {
return true;
}
-void BinaryFunction::fixBranches() {
+void BinaryFunction::fixBranches(const BranchLivenessInfo *BranchLiveness) {
assert(isSimple() && "Expected function with valid CFG.");
auto &MIB = BC.MIB;
@@ -3691,7 +3691,7 @@ void BinaryFunction::fixBranches() {
// Reverse branch condition and swap successors.
auto swapSuccessors = [&]() {
- if (!MIB->isReversibleBranch(*CondBranch)) {
+ if (!MIB->isReversibleBranch(*CondBranch, BranchLiveness)) {
if (opts::Verbosity) {
BC.outs() << "BOLT-INFO: unable to swap successors in " << *this
<< '\n';
@@ -3701,7 +3701,8 @@ void BinaryFunction::fixBranches() {
std::swap(TSuccessor, FSuccessor);
BB->swapConditionalSuccessors();
auto L = BC.scopeLock();
- MIB->reverseBranchCondition(*CondBranch, TSuccessor->getLabel(), Ctx);
+ MIB->reverseBranchCondition(BB, *CondBranch, TSuccessor->getLabel(),
+ Ctx, BranchLiveness);
return true;
};
diff --git a/bolt/lib/Passes/BinaryPasses.cpp b/bolt/lib/Passes/BinaryPasses.cpp
index 89737b906e82b..1d14b7942619d 100644
--- a/bolt/lib/Passes/BinaryPasses.cpp
+++ b/bolt/lib/Passes/BinaryPasses.cpp
@@ -11,8 +11,10 @@
//===----------------------------------------------------------------------===//
#include "bolt/Passes/BinaryPasses.h"
+#include "bolt/Core/BinaryFunctionCallGraph.h"
#include "bolt/Core/FunctionLayout.h"
#include "bolt/Core/ParallelUtilities.h"
+#include "bolt/Passes/DataflowInfoManager.h"
#include "bolt/Passes/ReorderAlgorithm.h"
#include "bolt/Passes/ReorderFunctions.h"
#include "bolt/Utils/CommandLineOpts.h"
@@ -544,13 +546,25 @@ bool ReorderBasicBlocks::modifyFunctionLayout(BinaryFunction &BF,
}
Error FixupBranches::runOnFunctions(BinaryContext &BC) {
- for (auto &It : BC.getBinaryFunctions()) {
- BinaryFunction &Function = It.second;
- if (!BC.shouldEmit(Function) || !Function.isSimple())
- continue;
+ auto forEachFunction = [&](auto &&Apply) {
+ for (auto &It : BC.getBinaryFunctions()) {
+ BinaryFunction &Function = It.second;
+ if (!BC.shouldEmit(Function) || !Function.isSimple())
+ continue;
+ Apply(Function);
+ }
+ };
- Function.fixBranches();
- }
+ if (opts::LivenessAnalysis) {
+ BinaryFunctionCallGraph CG = buildCallGraph(BC);
+ RegAnalysis RA(BC, &BC.getBinaryFunctions(), &CG);
+ forEachFunction([&](BinaryFunction &BF) {
+ DataflowInfoManager DIM(BF, &RA, nullptr);
+ BranchLivenessInfo Info = BC.MIB->createBranchLivenessInfo(BF, DIM);
+ BF.fixBranches(&Info);
+ });
+ } else
+ forEachFunction([&](BinaryFunction &BF) { BF.fixBranches(nullptr); });
return Error::success();
}
@@ -960,7 +974,7 @@ uint64_t SimplifyConditionalTailCalls::fixTailCalls(BinaryFunction &BF) {
uint64_t Count = 0;
if (CondSucc != BB) {
// Patch the new target address into the conditional branch.
- MIB->reverseBranchCondition(*CondBranch, CalleeSymbol, Ctx);
+ MIB->reverseBranchCondition(PredBB, *CondBranch, CalleeSymbol, Ctx);
// Since we reversed the condition on the branch we need to change
// the target for the unconditional branch or add a unconditional
// branch to the old target. This has to be done manually since
diff --git a/bolt/lib/Passes/LongJmp.cpp b/bolt/lib/Passes/LongJmp.cpp
index f085500fccbd3..75bb0c227660d 100644
--- a/bolt/lib/Passes/LongJmp.cpp
+++ b/bolt/lib/Passes/LongJmp.cpp
@@ -11,7 +11,9 @@
//===----------------------------------------------------------------------===//
#include "bolt/Passes/LongJmp.h"
+#include "bolt/Core/BinaryFunctionCallGraph.h"
#include "bolt/Core/ParallelUtilities.h"
+#include "bolt/Passes/DataflowInfoManager.h"
#include "bolt/Utils/CommandLineOpts.h"
#include "llvm/Support/MathExtras.h"
@@ -656,7 +658,8 @@ Error LongJmpPass::relax(BinaryFunction &Func, bool &Modified) {
return Error::success();
}
-void LongJmpPass::relaxLocalBranches(BinaryFunction &BF) {
+void LongJmpPass::relaxLocalBranches(BinaryFunction &BF,
+ const BranchLivenessInfo *BranchLiveness) {
BinaryContext &BC = BF.getBinaryContext();
auto &MIB = BC.MIB;
@@ -702,14 +705,18 @@ void LongJmpPass::relaxLocalBranches(BinaryFunction &BF) {
DenseMap<const BinaryBasicBlock *, BinaryBasicBlock *> FragmentTrampolines;
// Create a trampoline code after \p BB or at the end of the fragment if BB
- // is nullptr. If \p UpdateOffsets is true, update FragmentSize and offsets
- // for basic blocks affected by the insertion of the trampoline.
+ // is nullptr. \p Offset is the fragment size delta caused by the insertion,
+ // including any growth of \p BB before the trampoline.
auto addTrampolineAfter = [&](BinaryBasicBlock *BB,
BinaryBasicBlock *TargetBB, uint64_t Count,
- bool UpdateOffsets = true) {
+ uint64_t Offset) {
FunctionTrampolines.emplace_back(BB ? BB : FF.back(),
BF.createBasicBlock());
BinaryBasicBlock *TrampolineBB = FunctionTrampolines.back().second.get();
+ const uint64_t BBGrowth = Offset ? Offset - TrampolineSize : 0;
+
+ if (BB)
+ BB->setOutputEndAddress(BB->getOutputEndAddress() + BBGrowth);
MCInst Inst;
{
@@ -725,13 +732,23 @@ void LongJmpPass::relaxLocalBranches(BinaryFunction &BF) {
TrampolineBB->setOutputEndAddress(TrampolineAddress + TrampolineSize);
TrampolineBB->setFragmentNum(FF.getFragmentNum());
+ // Shift the fragment-local output address range for blocks at or after
+ // the old end address.
+ auto adjustBasicBlockAddress = [](BinaryBasicBlock *BB, uint64_t Address,
+ uint64_t Offset) {
+ if (BB->getOutputStartAddress() < Address)
+ return;
+ BB->setOutputStartAddress(BB->getOutputStartAddress() + Offset);
+ BB->setOutputEndAddress(BB->getOutputEndAddress() + Offset);
+ };
+
if (!FragmentTrampolines.lookup(TargetBB))
FragmentTrampolines[TargetBB] = TrampolineBB;
- if (!UpdateOffsets)
+ if (!Offset)
return TrampolineBB;
- FragmentSize += TrampolineSize;
+ FragmentSize += Offset;
// If the trampoline was added at the end of the fragment, offsets of
// other fragments should stay intact.
@@ -739,13 +756,8 @@ void LongJmpPass::relaxLocalBranches(BinaryFunction &BF) {
return TrampolineBB;
// Update offsets for blocks after BB.
- for (BinaryBasicBlock *IBB : FF) {
- if (IBB->getOutputStartAddress() >= TrampolineAddress) {
- IBB->setOutputStartAddress(IBB->getOutputStartAddress() +
- TrampolineSize);
- IBB->setOutputEndAddress(IBB->getOutputEndAddress() + TrampolineSize);
- }
- }
+ for (BinaryBasicBlock *IBB : FF)
+ adjustBasicBlockAddress(IBB, TrampolineAddress - BBGrowth, Offset);
// Update offsets for trampolines in this fragment that are placed after
// the new trampoline. Note that trampoline blocks are not part of the
@@ -757,11 +769,7 @@ void LongJmpPass::relaxLocalBranches(BinaryFunction &BF) {
continue;
if (IBB == TrampolineBB)
continue;
- if (IBB->getOutputStartAddress() >= TrampolineAddress) {
- IBB->setOutputStartAddress(IBB->getOutputStartAddress() +
- TrampolineSize);
- IBB->setOutputEndAddress(IBB->getOutputEndAddress() + TrampolineSize);
- }
+ adjustBasicBlockAddress(IBB, TrampolineAddress - BBGrowth, Offset);
}
return TrampolineBB;
@@ -782,7 +790,7 @@ void LongJmpPass::relaxLocalBranches(BinaryFunction &BF) {
BinaryBasicBlock *TargetBB = BB->getSuccessor(TargetSymbol, BI);
BinaryBasicBlock *TrampolineBB =
- addTrampolineAfter(BB, TargetBB, BI.Count, /*UpdateOffsets*/ false);
+ addTrampolineAfter(BB, TargetBB, BI.Count, /*Offset=*/0);
BB->replaceSuccessor(TargetBB, TrampolineBB, BI.Count);
}
@@ -815,7 +823,8 @@ void LongJmpPass::relaxLocalBranches(BinaryFunction &BF) {
// case we will need further relaxation.
const int64_t OffsetToEnd = FragmentSize - InstAddress;
if (Count == 0 && isBranchOffsetInRange(Inst, OffsetToEnd)) {
- TrampolineBB = addTrampolineAfter(nullptr, TargetBB, Count);
+ TrampolineBB =
+ addTrampolineAfter(nullptr, TargetBB, Count, TrampolineSize);
BB->replaceSuccessor(TargetBB, TrampolineBB, Count);
auto L = BC.scopeLock();
MIB->replaceBranchTarget(Inst, TrampolineBB->getLabel(), BC.Ctx.get());
@@ -826,7 +835,7 @@ void LongJmpPass::relaxLocalBranches(BinaryFunction &BF) {
// If the other successor is a fall-through, invert the condition code.
BinaryBasicBlock *NextBB =
BF->getLayout().getBasicBlockAfter(BB, /*IgnoreSplits*/ false);
- bool IsReversibleBranch = MIB->isReversibleBranch(Inst);
+ bool IsReversibleBranch = MIB->isReversibleBranch(Inst, BranchLiveness);
bool ShouldReverseBranch = BB->getConditionalSuccessor(false) == NextBB;
// Create a trampoline basic block for the fall-through target of the
@@ -834,18 +843,26 @@ void LongJmpPass::relaxLocalBranches(BinaryFunction &BF) {
if (ShouldReverseBranch && !IsReversibleBranch) {
const uint64_t NextCount = BB->getBranchInfo(*NextBB).Count;
BinaryBasicBlock *FallThrough =
- addTrampolineAfter(BB, NextBB, NextCount);
+ addTrampolineAfter(BB, NextBB, NextCount, TrampolineSize);
BB->replaceSuccessor(NextBB, FallThrough, NextCount);
}
- // Create a trampoline basic block for the taken target of the branch.
- TrampolineBB = addTrampolineAfter(BB, TargetBB, Count);
-
if (ShouldReverseBranch && IsReversibleBranch) {
+ const uint64_t OldBBSize = BB->estimateSize();
BB->swapConditionalSuccessors();
- auto L = BC.scopeLock();
- MIB->reverseBranchCondition(Inst, NextBB->getLabel(), BC.Ctx.get());
+ {
+ auto L = BC.scopeLock();
+ MIB->reverseBranchCondition(BB, Inst, NextBB->getLabel(),
+ BC.Ctx.get(), BranchLiveness);
+ }
+ const uint64_t NewBBSize = BB->estimateSize();
+
+ // Create a trampoline basic block for the original taken target.
+ TrampolineBB = addTrampolineAfter(
+ BB, TargetBB, Count, TrampolineSize + (NewBBSize - OldBBSize));
} else {
+ // Create a trampoline basic block for the taken target of the branch.
+ TrampolineBB = addTrampolineAfter(BB, TargetBB, Count, TrampolineSize);
auto L = BC.scopeLock();
MIB->replaceBranchTarget(Inst, TrampolineBB->getLabel(), BC.Ctx.get());
}
@@ -860,7 +877,10 @@ void LongJmpPass::relaxLocalBranches(BinaryFunction &BF) {
for (auto BBI = FF.begin(); BBI != FF.end(); ++BBI) {
BinaryBasicBlock *BB = *BBI;
uint64_t NextInstOffset = BB->getOutputStartAddress();
- for (MCInst &Inst : *BB) {
+ // Branch reversal may replace the current instruction with a sequence.
+ // Use an index so the next instruction is reloaded after the mutation.
+ for (size_t I = 0; I < BB->size(); ++I) {
+ MCInst &Inst = *(BB->begin() + I);
const size_t InstAddress = NextInstOffset;
if (!MIB->isPseudo(Inst))
NextInstOffset += 4;
@@ -929,19 +949,37 @@ Error LongJmpPass::runOnFunctions(BinaryContext &BC) {
opts::SplitStrategy != opts::SplitFunctionsStrategy::CDSplit) &&
"LongJmp cannot work with functions split in more than two fragments");
+ DenseMap<BinaryFunction *, BranchLivenessInfo> BranchLiveness;
+ if (opts::LivenessAnalysis) {
+ BinaryFunctionCallGraph CG = buildCallGraph(BC);
+ RegAnalysis RA(BC, &BC.getBinaryFunctions(), &CG);
+ for (auto &It : BC.getBinaryFunctions()) {
+ BinaryFunction &BF = It.second;
+ if (!BC.shouldEmit(BF) || !BF.isSimple())
+ continue;
+ DataflowInfoManager DIM(BF, &RA, nullptr);
+ BranchLiveness[&BF] = BC.MIB->createBranchLivenessInfo(BF, DIM);
+ }
+ }
+ auto getBranchLiveness =
+ [&](BinaryFunction &BF) -> const BranchLivenessInfo * {
+ auto It = BranchLiveness.find(&BF);
+ return It == BranchLiveness.end() ? nullptr : &It->second;
+ };
+
if (opts::CompactCodeModel) {
BC.outs()
<< "BOLT-INFO: relaxing branches for compact code model (<128MB)\n";
- ParallelUtilities::WorkFuncTy WorkFun = [&](BinaryFunction &BF) {
- relaxLocalBranches(BF);
- };
-
ParallelUtilities::PredicateTy SkipPredicate =
[&](const BinaryFunction &BF) {
return !BC.shouldEmit(BF) || !BF.isSimple();
};
+ ParallelUtilities::WorkFuncTy WorkFun = [&](BinaryFunction &BF) {
+ relaxLocalBranches(BF, getBranchLiveness(BF));
+ };
+
ParallelUtilities::runOnEachFunction(
BC, ParallelUtilities::SchedulingPolicy::SP_INST_LINEAR, WorkFun,
SkipPredicate, "RelaxLocalBranches");
@@ -964,7 +1002,7 @@ Error LongJmpPass::runOnFunctions(BinaryContext &BC) {
// Don't ruin non-simple functions, they can't afford to have the layout
// changed.
if (Modified && Func->isSimple())
- Func->fixBranches();
+ Func->fixBranches(getBranchLiveness(*Func));
}
} while (Modified);
BC.outs() << "BOLT-INFO: Inserted " << NumHotStubs
diff --git a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
index b4a9dff9d25b2..964b0efd7012e 100644
--- a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
+++ b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
@@ -22,6 +22,7 @@
#include "bolt/Core/BinaryFunction.h"
#include "bolt/Core/MCInstUtils.h"
#include "bolt/Core/MCPlusBuilder.h"
+#include "bolt/Passes/DataflowInfoManager.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
@@ -2045,6 +2046,25 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
exit(1);
}
+ unsigned getInvertedCC(unsigned Opcode) const {
+ // clang-format off
+ switch (Opcode) {
+ default:
+ llvm_unreachable("Failed to invert condition code");
+ return Opcode;
+ // Compare register with immediate and branch.
+ case AArch64::CBGTWri: return AArch64CC::LE;
+ case AArch64::CBGTXri: return AArch64CC::LE;
+ case AArch64::CBLTWri: return AArch64CC::GE;
+ case AArch64::CBLTXri: return AArch64CC::GE;
+ case AArch64::CBHIWri: return AArch64CC::LS;
+ case AArch64::CBHIXri: return AArch64CC::LS;
+ case AArch64::CBLOWri: return AArch64CC::HS;
+ case AArch64::CBLOXri: return AArch64CC::HS;
+ }
+ // clang-format on
+ }
+
unsigned getInvertedBranchOpcode(unsigned Opcode) const {
/...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/202998
More information about the llvm-commits
mailing list