Skip to content

Commit 2698e03

Browse files
committed
[RISCV] Add CompressPat for all cases in isCopyInstrImpl
We may end up with a non-canonical move (copy) instruction after a pass like MachineCopyPropagation that doesn't get compressed because we don't have an explicit pattern for it. This patch addressses that by adding additional CompressPat. This means that the generated code will be slightly different with/without the compressed extension. This isn't expected to be problematic as the instructions in question are all simple arithmetic ops.
1 parent b0524f3 commit 2698e03

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoC.td

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,11 +1012,15 @@ let Predicates = [HasStdExtCOrZca] in {
10121012
def : CompressPat<(JALR X0, GPRNoX0:$rs1, 0),
10131013
(C_JR GPRNoX0:$rs1)>;
10141014
let isCompressOnly = true in {
1015-
def : CompressPat<(ADD GPRNoX0:$rs1, X0, GPRNoX0:$rs2),
1016-
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
1017-
def : CompressPat<(ADD GPRNoX0:$rs1, GPRNoX0:$rs2, X0),
1018-
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
1015+
foreach Inst=[ADD, OR, XOR] in {
1016+
def : CompressPat<(Inst GPRNoX0:$rs1, X0, GPRNoX0:$rs2),
1017+
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
1018+
def : CompressPat<(Inst GPRNoX0:$rs1, GPRNoX0:$rs2, X0),
1019+
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
10191020
}
1021+
def : CompressPat<(SUB GPRNoX0:$rs1, GPRNoX0:$rs2, X0),
1022+
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
1023+
} // isCompressOnly = true
10201024
def : CompressPat<(ADDI GPRNoX0:$rs1, GPRNoX0:$rs2, 0),
10211025
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
10221026
def : CompressPat<(EBREAK), (C_EBREAK)>;
@@ -1053,3 +1057,21 @@ let Predicates = [HasStdExtCOrZca, IsRV64] in {
10531057
def : CompressPat<(SD GPR:$rs2, SPMem:$rs1, uimm9_lsb000:$imm),
10541058
(C_SDSP GPR:$rs2, SPMem:$rs1, uimm9_lsb000:$imm)>;
10551059
} // Predicates = [HasStdExtCOrZca, IsRV64]
1060+
1061+
let isCompressOnly = true, Predicates = [HasStdExtCOrZca, HasStdExtZba] in {
1062+
def : CompressPat<(SH1ADD GPRNoX0:$rs1, X0, GPRNoX0:$rs2),
1063+
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
1064+
def : CompressPat<(SH2ADD GPRNoX0:$rs1, X0, GPRNoX0:$rs2),
1065+
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
1066+
def : CompressPat<(SH3ADD GPRNoX0:$rs1, X0, GPRNoX0:$rs2),
1067+
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
1068+
} // isCompressOnly = true, Predicates = [HasStdExtCOrZca, HasStdExtZba]
1069+
1070+
let isCompressOnly = true, Predicates = [HasStdExtCOrZca, HasStdExtZba, IsRV64] in {
1071+
def : CompressPat<(SH1ADD_UW GPRNoX0:$rs1, X0, GPRNoX0:$rs2),
1072+
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
1073+
def : CompressPat<(SH2ADD_UW GPRNoX0:$rs1, X0, GPRNoX0:$rs2),
1074+
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
1075+
def : CompressPat<(SH3ADD_UW GPRNoX0:$rs1, X0, GPRNoX0:$rs2),
1076+
(C_MV GPRNoX0:$rs1, GPRNoX0:$rs2)>;
1077+
} // isCompressOnly = true, Predicates = [HasStdExtCOrZca, HasStdExtZba, IsRV64]

0 commit comments

Comments
 (0)