Skip to content

Commit a2ea003

Browse files
committed
[RISCV] Don't convert fshr/fshl to target specific FSL/FSR node if shift amount is a constant.
As long as it's a constant we can directly pattern match it without any problems. It's only when it isn't a constant that we need to add an AND. In theory this should allow more target independent optimizations to remain active.
1 parent 1b4800c commit a2ea003

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,8 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op,
15581558
MVT VT = Op.getSimpleValueType();
15591559
assert(VT == Subtarget.getXLenVT() && "Unexpected custom legalization");
15601560
SDLoc DL(Op);
1561+
if (Op.getOperand(2).getOpcode() == ISD::Constant)
1562+
return Op;
15611563
// FSL/FSR take a log2(XLen)+1 bit shift amount but XLenVT FSHL/FSHR only
15621564
// use log(XLen) bits. Mask the shift amount accordingly.
15631565
unsigned ShAmtWidth = Subtarget.getXLen() - 1;

llvm/lib/Target/RISCV/RISCVInstrInfoB.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,11 @@ def : Pat<(riscv_fsl GPR:$rs1, GPR:$rs3, GPR:$rs2),
758758
def : Pat<(riscv_fsr GPR:$rs3, GPR:$rs1, GPR:$rs2),
759759
(FSR GPR:$rs1, GPR:$rs2, GPR:$rs3)>;
760760

761-
def : Pat<(riscv_fsr GPR:$rs3, GPR:$rs1, uimmlog2xlen:$shamt),
761+
def : Pat<(fshr GPR:$rs3, GPR:$rs1, uimmlog2xlen:$shamt),
762762
(FSRI GPR:$rs1, GPR:$rs3, uimmlog2xlen:$shamt)>;
763763
// We can use FSRI for fshl by immediate if we subtract the immediate from
764764
// XLen and swap the operands.
765-
def : Pat<(riscv_fsl GPR:$rs3, GPR:$rs1, uimmlog2xlen:$shamt),
765+
def : Pat<(fshl GPR:$rs3, GPR:$rs1, uimmlog2xlen:$shamt),
766766
(FSRI GPR:$rs1, GPR:$rs3, (ImmSubFromXLen uimmlog2xlen:$shamt))>;
767767
} // Predicates = [HasStdExtZbt]
768768

0 commit comments

Comments
 (0)