Skip to content

Commit 9a097cf

Browse files
committed
[RISCV] Enable (non trivial) remat for most scalar instructions
This is a follow up to the recent infrastructure work for to generally support non-trivial rematerialization. This is the first in a small series to enable non-trivially agressively for the RISC-V backend. It deliberately avoids both vector instructions and loads as those seem most likely to expose unexpected interactions. Note that this isn't ready to land just yet. We need to collect both compile time (in progress), and more perf numbers/stats on at least e.g. spec2017/test-suite. I'm posting it mostly as a placeholder since multiple people were talking about this and I want us to avoid duplicating work.
1 parent 95144b1 commit 9a097cf

File tree

6 files changed

+4893
-4797
lines changed

6 files changed

+4893
-4797
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfo.td

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -780,21 +780,18 @@ def SB : Store_rri<0b000, "sb">, Sched<[WriteSTB, ReadStoreData, ReadMemBase]>;
780780
def SH : Store_rri<0b001, "sh">, Sched<[WriteSTH, ReadStoreData, ReadMemBase]>;
781781
def SW : Store_rri<0b010, "sw">, Sched<[WriteSTW, ReadStoreData, ReadMemBase]>;
782782

783-
// ADDI isn't always rematerializable, but isReMaterializable will be used as
784-
// a hint which is verified in isReMaterializableImpl.
785-
let isReMaterializable = 1, isAsCheapAsAMove = 1 in
783+
let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
786784
def ADDI : ALU_ri<0b000, "addi">;
785+
def XORI : ALU_ri<0b100, "xori">;
786+
def ORI : ALU_ri<0b110, "ori">;
787+
}
787788

788-
let IsSignExtendingOpW = 1 in {
789+
let IsSignExtendingOpW = 1, isReMaterializable = 1 in {
789790
def SLTI : ALU_ri<0b010, "slti">;
790791
def SLTIU : ALU_ri<0b011, "sltiu">;
791792
}
792793

793-
let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
794-
def XORI : ALU_ri<0b100, "xori">;
795-
def ORI : ALU_ri<0b110, "ori">;
796-
}
797-
794+
let isReMaterializable = 1 in {
798795
def ANDI : ALU_ri<0b111, "andi">;
799796

800797
def SLLI : Shift_ri<0b00000, 0b001, "slli">,
@@ -826,6 +823,7 @@ def OR : ALU_rr<0b0000000, 0b110, "or", Commutable=1>,
826823
Sched<[WriteIALU, ReadIALU, ReadIALU]>;
827824
def AND : ALU_rr<0b0000000, 0b111, "and", Commutable=1>,
828825
Sched<[WriteIALU, ReadIALU, ReadIALU]>;
826+
}
829827

830828
let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in {
831829
def FENCE : RVInstI<0b000, OPC_MISC_MEM, (outs),
@@ -893,7 +891,7 @@ def LWU : Load_ri<0b110, "lwu">, Sched<[WriteLDW, ReadMemBase]>;
893891
def LD : Load_ri<0b011, "ld">, Sched<[WriteLDD, ReadMemBase]>;
894892
def SD : Store_rri<0b011, "sd">, Sched<[WriteSTD, ReadStoreData, ReadMemBase]>;
895893

896-
let IsSignExtendingOpW = 1 in {
894+
let IsSignExtendingOpW = 1, isReMaterializable = 1 in {
897895
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
898896
def ADDIW : RVInstI<0b000, OPC_OP_IMM_32, (outs GPR:$rd),
899897
(ins GPR:$rs1, simm12_lo:$imm12),
@@ -917,7 +915,7 @@ def SRLW : ALUW_rr<0b0000000, 0b101, "srlw">,
917915
Sched<[WriteShiftReg32, ReadShiftReg32, ReadShiftReg32]>;
918916
def SRAW : ALUW_rr<0b0100000, 0b101, "sraw">,
919917
Sched<[WriteShiftReg32, ReadShiftReg32, ReadShiftReg32]>;
920-
} // IsSignExtendingOpW = 1
918+
} // IsSignExtendingOpW = 1, isReMaterializable = 1
921919
} // Predicates = [IsRV64]
922920

923921
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)