[llvm] [BOLT][AArch64] Transform cmpbr ~> cmp + br when inversion not possible (PR #185731)
Paschalis Mpeis via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 1 08:09:23 PDT 2026
================
@@ -2155,38 +2175,76 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
}
}
- bool isReversibleBranch(const MCInst &Inst) const override {
+ bool is32BitVariant(unsigned Opcode) const {
+ switch (Opcode) {
+ default:
+ return false;
+ case AArch64::CBGTWri:
+ case AArch64::CBLTWri:
+ case AArch64::CBHIWri:
+ case AArch64::CBLOWri:
+ return true;
+ }
+ }
+
+ bool isReversibleBranch(const MCInst &Inst,
+ DataflowInfoManager *DIM = nullptr) const override {
if (isCompAndBranch(Inst)) {
+ bool IsReversible =
+ DIM ? !DIM->getLivenessAnalysis().getLiveIn(Inst).test(getFlagsReg())
+ : false;
unsigned InvertedOpcode = getInvertedBranchOpcode(Inst.getOpcode());
- if (needsImmDec(InvertedOpcode) && Inst.getOperand(1).getImm() == 0)
+ if (needsImmDec(InvertedOpcode) && Inst.getOperand(1).getImm() == 0 &&
+ !IsReversible)
return false;
- if (needsImmInc(InvertedOpcode) && Inst.getOperand(1).getImm() == 63)
+ if (needsImmInc(InvertedOpcode) && Inst.getOperand(1).getImm() == 63 &&
+ !IsReversible)
return false;
}
return MCPlusBuilder::isReversibleBranch(Inst);
}
- void reverseBranchCondition(MCInst &Inst, const MCSymbol *TBB,
+ void reverseBranchCondition(BinaryBasicBlock *Parent, MCInst &Inst,
+ const MCSymbol *TBB,
MCContext *Ctx) const override {
- if (!isReversibleBranch(Inst)) {
----------------
paschalis-mpeis wrote:
Can you add a comment about this in the header file?
Also, should we add that check in SimplifyConditionalTailCalls too? We don't have to pass DIM in that call.
https://github.com/llvm/llvm-project/pull/185731
More information about the llvm-commits
mailing list