Skip to content

Commit 0a34ff8

Browse files
committed
[RISCV] Replace AddiPair ComplexPattern with a PatLeaf. NFC
The ComplexPattern is looking for an immediate in a certain range that has a single use. This can be handled with a PatLeaf since we aren't matching multiple patterns or checking any complicated relationships between nodes. This shrinks the isel table a little bit since tablegen no longer has to generate patterns with commuted operands. With the PatLeaf, tablegen can see we're matching an immediate which should always be on the right hand side of add. Reviewed By: benshi001 Differential Revision: https://reviews.llvm.org/D102510
1 parent 6974f18 commit 0a34ff8

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,23 +1287,6 @@ bool RISCVDAGToDAGISel::selectZExti32(SDValue N, SDValue &Val) {
12871287
return false;
12881288
}
12891289

1290-
// Check if (add r, imm) can be optimized to (ADDI (ADDI r, imm0), imm1),
1291-
// in which imm = imm0 + imm1 and both imm0 and imm1 are simm12.
1292-
bool RISCVDAGToDAGISel::selectAddiPair(SDValue N, SDValue &Val) {
1293-
if (auto *ConstOp = dyn_cast<ConstantSDNode>(N)) {
1294-
// The immediate operand must have only use.
1295-
if (!(ConstOp->hasOneUse()))
1296-
return false;
1297-
// The immediate operand must be in range [-4096,-2049] or [2048,4094].
1298-
int64_t Imm = ConstOp->getSExtValue();
1299-
if ((-4096 <= Imm && Imm <= -2049) || (2048 <= Imm && Imm <= 4094)) {
1300-
Val = N;
1301-
return true;
1302-
}
1303-
}
1304-
return false;
1305-
}
1306-
13071290
// Check that it is a SLLIUW (Shift Logical Left Immediate Unsigned i32
13081291
// on RV64).
13091292
// SLLIUW is the same as SLLI except for the fact that it clears the bits

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ class RISCVDAGToDAGISel : public SelectionDAGISel {
5757
bool selectSExti32(SDValue N, SDValue &Val);
5858
bool selectZExti32(SDValue N, SDValue &Val);
5959

60-
bool selectAddiPair(SDValue N, SDValue &Val);
61-
6260
bool MatchSLLIUW(SDNode *N) const;
6361

6462
bool selectVLOp(SDValue N, SDValue &VL);

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,15 @@ def ImmSubFrom32 : SDNodeXForm<imm, [{
343343
N->getValueType(0));
344344
}]>;
345345

346-
// Check if an addition can be broken to a pair of ADDI.
347-
def AddiPair : ComplexPattern<XLenVT, 1, "selectAddiPair">;
346+
// Check if (add r, imm) can be optimized to (ADDI (ADDI r, imm0), imm1),
347+
// in which imm = imm0 + imm1 and both imm0 and imm1 are simm12.
348+
def AddiPair : PatLeaf<(imm), [{
349+
if (!N->hasOneUse())
350+
return false;
351+
// The immediate operand must be in range [-4096,-2049] or [2048,4094].
352+
int64_t Imm = N->getSExtValue();
353+
return (-4096 <= Imm && Imm <= -2049) || (2048 <= Imm && Imm <= 4094);
354+
}]>;
348355

349356
// Return imm/2.
350357
def AddiPairImmA : SDNodeXForm<imm, [{
@@ -1299,14 +1306,14 @@ def : Pat<(trap), (UNIMP)>;
12991306
def : Pat<(debugtrap), (EBREAK)>;
13001307

13011308
/// Simple optimization
1302-
def : Pat<(add GPR:$rs1, (AddiPair GPR:$rs2)),
1303-
(ADDI (ADDI GPR:$rs1, (AddiPairImmB GPR:$rs2)),
1309+
def : Pat<(add GPR:$rs1, (AddiPair:$rs2)),
1310+
(ADDI (ADDI GPR:$rs1, (AddiPairImmB AddiPair:$rs2)),
13041311
(AddiPairImmA GPR:$rs2))>;
13051312

13061313
let Predicates = [IsRV64] in {
1307-
def : Pat<(sext_inreg (add_oneuse GPR:$rs1, (AddiPair GPR:$rs2)), i32),
1308-
(ADDIW (ADDIW GPR:$rs1, (AddiPairImmB GPR:$rs2)),
1309-
(AddiPairImmA GPR:$rs2))>;
1314+
def : Pat<(sext_inreg (add_oneuse GPR:$rs1, (AddiPair:$rs2)), i32),
1315+
(ADDIW (ADDIW GPR:$rs1, (AddiPairImmB AddiPair:$rs2)),
1316+
(AddiPairImmA AddiPair:$rs2))>;
13101317
}
13111318

13121319
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)