Skip to content

Commit cfd13cb

Browse files
committed
[RISCV] Improve variable scoping in custom isel for ISD::AND.
Give the (and (srl/shl X, C2), C1) handling its owns private `C1` variable it can modify using known zeros. This may be out of sync with N1C->getZExtValue(). Add a separate const C1 for (and (sra X, C2), C1) and (and X, C). This copy will always be in sync with N1C->getZExtValue(). Remove the IsC1Mask and IsC1ANDI variables and compute them at their usage. Use N1C->getSExtValue() when calling isInt. This shouldn't be a functional change since we already checked that it was a mask. In order for it to be a mask and a negative number, it would need to be -1 which should have been removed by DAG combine.
1 parent 4745bb3 commit cfd13cb

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,9 +1217,6 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
12171217
auto *N1C = dyn_cast<ConstantSDNode>(Node->getOperand(1));
12181218
if (!N1C)
12191219
break;
1220-
uint64_t C1 = N1C->getZExtValue();
1221-
const bool IsC1Mask = isMask_64(C1);
1222-
const bool IsC1ANDI = isInt<12>(C1);
12231220

12241221
SDValue N0 = Node->getOperand(0);
12251222

@@ -1253,6 +1250,8 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
12531250
// TODO: What if ANDI faster than shift?
12541251
bool IsCANDI = isInt<6>(N1C->getSExtValue());
12551252

1253+
uint64_t C1 = N1C->getZExtValue();
1254+
12561255
// Clear irrelevant bits in the mask.
12571256
if (LeftShift)
12581257
C1 &= maskTrailingZeros<uint64_t>(C2);
@@ -1267,7 +1266,7 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
12671266

12681267
// Turn (and (srl x, c2) c1) -> (srli (slli x, c3-c2), c3) if c1 is a mask
12691268
// with c3 leading zeros.
1270-
if (!LeftShift && IsC1Mask) {
1269+
if (!LeftShift && isMask_64(C1)) {
12711270
unsigned Leading = XLen - llvm::bit_width(C1);
12721271
if (C2 < Leading) {
12731272
// If the number of leading zeros is C2+32 this can be SRLIW.
@@ -1450,6 +1449,8 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
14501449
}
14511450
}
14521451

1452+
const uint64_t C1 = N1C->getZExtValue();
1453+
14531454
// Turn (and (sra x, c2), c1) -> (srli (srai x, c2-c3), c3) if c1 is a mask
14541455
// with c3 leading zeros and c2 is larger than c3.
14551456
if (N0.getOpcode() == ISD::SRA && isa<ConstantSDNode>(N0.getOperand(1)) &&
@@ -1480,7 +1481,7 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
14801481
// available.
14811482
// Transform (and x, C1)
14821483
// -> (<bfextract> x, msb, lsb)
1483-
if (IsC1Mask && !IsC1ANDI) {
1484+
if (isMask_64(C1) && !isInt<12>(N1C->getSExtValue())) {
14841485
const unsigned Msb = llvm::bit_width(C1) - 1;
14851486
if (tryUnsignedBitfieldExtract(Node, DL, VT, N0, Msb, 0))
14861487
return;

0 commit comments

Comments
 (0)