Skip to content

Commit d325099

Browse files
committed
[RISCV] Rewrite an isel pattern to make it more amenable to GISel. NFC
The result pattern created an i1 constant and then used ImmSubFromXLen SDNodeXForm on it. GISel cannot handle this construct the same way as SelectionDAG. The GISel equivalent of the SDNodeXForm expects a G_CONSTANT, but the emitter can't create that. Work aound this by splitting the pattern into RV32 and RV64 versions and hard coding the constant. Additional changes are needed to import the pattern for GISel so there's no test.
1 parent 392651a commit d325099

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,9 +1348,10 @@ def add_like : PatFrags<(ops node:$lhs, node:$rhs),
13481348

13491349
// negate of low bit can be done via two (compressible) shifts. The negate
13501350
// is never compressible since rs1 and rd can't be the same register.
1351-
def : Pat<(XLenVT (sub 0, (and_oneuse GPR:$rs, 1))),
1352-
(SRAI (XLenVT (SLLI $rs, (ImmSubFromXLen (XLenVT 1)))),
1353-
(ImmSubFromXLen (XLenVT 1)))>;
1351+
def : Pat<(i32 (sub 0, (and_oneuse GPR:$rs, 1))),
1352+
(SRAI (i32 (SLLI $rs, 31)), 31)>, Requires<[IsRV32]>;
1353+
def : Pat<(i64 (sub 0, (and_oneuse GPR:$rs, 1))),
1354+
(SRAI (i64 (SLLI $rs, 63)), 63)>, Requires<[IsRV64]>;
13541355

13551356
// AND with leading/trailing ones mask exceeding simm32/simm12.
13561357
def : Pat<(i64 (and GPR:$rs, immop_oneuse<LeadingOnesMask>:$mask)),

0 commit comments

Comments
 (0)