Skip to content

Commit b580829

Browse files
authored
[RISCV] Add helper method for checking for Zicond or XVentanaCondOps. NFC (#157891)
These two extensions have identical functionality so we always want to treat them the same.
1 parent 0dddfab commit b580829

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9141,9 +9141,7 @@ static SDValue lowerSelectToBinOp(SDNode *N, SelectionDAG &DAG,
91419141
return DAG.getNode(ISD::OR, DL, VT, Neg, DAG.getFreeze(TrueV));
91429142
}
91439143

9144-
const bool HasCZero =
9145-
VT.isScalarInteger() &&
9146-
(Subtarget.hasStdExtZicond() || Subtarget.hasVendorXVentanaCondOps());
9144+
const bool HasCZero = VT.isScalarInteger() && Subtarget.hasCZEROLike();
91479145

91489146
// (select c, 0, y) -> (c-1) & y
91499147
if (isNullConstant(TrueV) && (!HasCZero || isSimm12Constant(FalseV))) {
@@ -9281,8 +9279,7 @@ SDValue RISCVTargetLowering::lowerSELECT(SDValue Op, SelectionDAG &DAG) const {
92819279
// nodes to implement the SELECT. Performing the lowering here allows for
92829280
// greater control over when CZERO_{EQZ/NEZ} are used vs another branchless
92839281
// sequence or RISCVISD::SELECT_CC node (branch-based select).
9284-
if ((Subtarget.hasStdExtZicond() || Subtarget.hasVendorXVentanaCondOps()) &&
9285-
VT.isScalarInteger()) {
9282+
if (Subtarget.hasCZEROLike() && VT.isScalarInteger()) {
92869283

92879284
// (select c, t, 0) -> (czero_eqz t, c)
92889285
if (isNullConstant(FalseV))
@@ -15487,9 +15484,7 @@ static SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp,
1548715484

1548815485
if (!Subtarget.hasConditionalMoveFusion()) {
1548915486
// (select cond, x, (and x, c)) has custom lowering with Zicond.
15490-
if ((!Subtarget.hasStdExtZicond() &&
15491-
!Subtarget.hasVendorXVentanaCondOps()) ||
15492-
N->getOpcode() != ISD::AND)
15487+
if (!Subtarget.hasCZEROLike() || N->getOpcode() != ISD::AND)
1549315488
return SDValue();
1549415489

1549515490
// Maybe harmful when condition code has multiple use.
@@ -18953,8 +18948,7 @@ static SDValue useInversedSetcc(SDNode *N, SelectionDAG &DAG,
1895318948
// Replace (setcc eq (and x, C)) with (setcc ne (and x, C))) to generate
1895418949
// BEXTI, where C is power of 2.
1895518950
if (Subtarget.hasStdExtZbs() && VT.isScalarInteger() &&
18956-
(Subtarget.hasStdExtZicond() || Subtarget.hasVendorXVentanaCondOps() ||
18957-
Subtarget.hasVendorXTHeadCondMov())) {
18951+
(Subtarget.hasCZEROLike() || Subtarget.hasVendorXTHeadCondMov())) {
1895818952
SDValue LHS = Cond.getOperand(0);
1895918953
SDValue RHS = Cond.getOperand(1);
1896018954
ISD::CondCode CC = cast<CondCodeSDNode>(Cond.getOperand(2))->get();
@@ -24938,7 +24932,7 @@ RISCVTargetLowering::BuildSDIVPow2(SDNode *N, const APInt &Divisor,
2493824932

2493924933
bool RISCVTargetLowering::shouldFoldSelectWithSingleBitTest(
2494024934
EVT VT, const APInt &AndMask) const {
24941-
if (Subtarget.hasStdExtZicond() || Subtarget.hasVendorXVentanaCondOps())
24935+
if (Subtarget.hasCZEROLike())
2494224936
return !Subtarget.hasStdExtZbs() && AndMask.ugt(1024);
2494324937
return TargetLowering::shouldFoldSelectWithSingleBitTest(VT, AndMask);
2494424938
}

llvm/lib/Target/RISCV/RISCVSubtarget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ class RISCVSubtarget : public RISCVGenSubtargetInfo {
186186
return HasStdExtZfhmin || HasStdExtZfbfmin;
187187
}
188188

189+
bool hasCZEROLike() const {
190+
return HasStdExtZicond || HasVendorXVentanaCondOps;
191+
}
192+
189193
bool hasConditionalMoveFusion() const {
190194
// Do we support fusing a branch+mv or branch+c.mv as a conditional move.
191195
return (hasConditionalCompressedMoveFusion() && hasStdExtZca()) ||

0 commit comments

Comments
 (0)