Skip to content

Commit 5341d54

Browse files
authored
[RISCV] Combine (and (select cond, x, -1), c) to (select cond, x, (and x, c)) with Zicond. (#69563)
It's only beneficial when cond is setcc with integer equality condition code. For other case, it has same instruction count as the original.
1 parent 4168845 commit 5341d54

File tree

2 files changed

+305
-41
lines changed

2 files changed

+305
-41
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11584,8 +11584,23 @@ static SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp,
1158411584
if (VT.isVector())
1158511585
return SDValue();
1158611586

11587-
if (!Subtarget.hasShortForwardBranchOpt() ||
11588-
(Slct.getOpcode() != ISD::SELECT &&
11587+
if (!Subtarget.hasShortForwardBranchOpt()) {
11588+
// (select cond, x, (and x, c)) has custom lowering with Zicond.
11589+
if ((!Subtarget.hasStdExtZicond() &&
11590+
!Subtarget.hasVendorXVentanaCondOps()) ||
11591+
N->getOpcode() != ISD::AND)
11592+
return SDValue();
11593+
11594+
// Maybe harmful when condition code has multiple use.
11595+
if (Slct.getOpcode() == ISD::SELECT && !Slct.getOperand(0).hasOneUse())
11596+
return SDValue();
11597+
11598+
// Maybe harmful when VT is wider than XLen.
11599+
if (VT.getSizeInBits() > Subtarget.getXLen())
11600+
return SDValue();
11601+
}
11602+
11603+
if ((Slct.getOpcode() != ISD::SELECT &&
1158911604
Slct.getOpcode() != RISCVISD::SELECT_CC) ||
1159011605
!Slct.hasOneUse())
1159111606
return SDValue();

0 commit comments

Comments
 (0)