[llvm] [AArch64][FEAT_CMPBR] Codegen for Armv9.6-a compare-and-branch (PR #116465)
David Tellenbach via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 16 17:05:45 PST 2024
================
@@ -10396,6 +10398,28 @@ SDValue AArch64TargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const {
DAG.getConstant(SignBitPos, dl, MVT::i64), Dest);
}
+ // Try to emit Armv9.6 CB instructions. We prefer tb{n}z/cb{n}z due to their
+ // larger branch displacement but do prefer CB over cmp + br.
+ if (Subtarget->hasCMPBR() &&
+ AArch64CC::isValidCBCond(changeIntCCToAArch64CC(CC)) &&
+ ProduceNonFlagSettingCondBr) {
+ AArch64CC::CondCode ACC = changeIntCCToAArch64CC(CC);
+ unsigned Opc = AArch64ISD::CBRR;
+ if (ConstantSDNode *Imm = dyn_cast<ConstantSDNode>(RHS)) {
+ APInt NewImm = Imm->getAPIntValue();
+ if (ACC == AArch64CC::GE || ACC == AArch64CC::HS)
+ NewImm = Imm->getAPIntValue() - 1;
+ else if (ACC == AArch64CC::LE || ACC == AArch64CC::LS)
+ NewImm = Imm->getAPIntValue() + 1;
+
+ if (NewImm.uge(0) && NewImm.ult(64))
+ Opc = AArch64ISD::CBRI;
----------------
dtellenbach wrote:
Should be covered by https://github.com/llvm/llvm-project/pull/116465/files#diff-fcc36455253ff1cd10e20c85b2b2abe15f5e30b3a65970c446da586edccad1f6 already. I'll add a few more test case closer to the bounds.
https://github.com/llvm/llvm-project/pull/116465
More information about the llvm-commits
mailing list