Skip to content

Commit 8def89b

Browse files
committed
[RISCV] Set CostPerUse to 1 iff RVC is enabled
After D86836, we can define multiple cost values for different cost models. So here we set CostPerUse to 1 iff RVC is enabled to avoid potential impact on RA. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D117741
1 parent 82bb8a5 commit 8def89b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+6801
-6928
lines changed

llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,8 @@ void RISCVRegisterInfo::getOffsetOpcodes(const StackOffset &Offset,
347347
Ops.push_back(dwarf::DW_OP_minus);
348348
}
349349
}
350+
351+
unsigned
352+
RISCVRegisterInfo::getRegisterCostTableIndex(const MachineFunction &MF) const {
353+
return MF.getSubtarget<RISCVSubtarget>().hasStdExtC() ? 1 : 0;
354+
}

llvm/lib/Target/RISCV/RISCVRegisterInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ struct RISCVRegisterInfo : public RISCVGenRegisterInfo {
6666

6767
void getOffsetOpcodes(const StackOffset &Offset,
6868
SmallVectorImpl<uint64_t> &Ops) const override;
69+
70+
unsigned getRegisterCostTableIndex(const MachineFunction &MF) const override;
6971
};
7072
}
7173

llvm/lib/Target/RISCV/RISCVRegisterInfo.td

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,11 @@ def sub_vrm1_7 : ComposedSubRegIndex<sub_vrm2_3, sub_vrm1_1>;
7373
// are not part of GPRC, the most restrictive register class used by the
7474
// compressed instruction set. This will influence the greedy register
7575
// allocator to reduce the use of registers that can't be encoded in 16 bit
76-
// instructions. This affects register allocation even when compressed
77-
// instruction isn't targeted, we see no major negative codegen impact.
76+
// instructions.
7877

7978
let RegAltNameIndices = [ABIRegAltName] in {
8079
def X0 : RISCVReg<0, "x0", ["zero"]>, DwarfRegNum<[0]>;
81-
let CostPerUse = [1] in {
80+
let CostPerUse = [0, 1] in {
8281
def X1 : RISCVReg<1, "x1", ["ra"]>, DwarfRegNum<[1]>;
8382
def X2 : RISCVReg<2, "x2", ["sp"]>, DwarfRegNum<[2]>;
8483
def X3 : RISCVReg<3, "x3", ["gp"]>, DwarfRegNum<[3]>;
@@ -95,7 +94,7 @@ let RegAltNameIndices = [ABIRegAltName] in {
9594
def X13 : RISCVReg<13,"x13", ["a3"]>, DwarfRegNum<[13]>;
9695
def X14 : RISCVReg<14,"x14", ["a4"]>, DwarfRegNum<[14]>;
9796
def X15 : RISCVReg<15,"x15", ["a5"]>, DwarfRegNum<[15]>;
98-
let CostPerUse = [1] in {
97+
let CostPerUse = [0, 1] in {
9998
def X16 : RISCVReg<16,"x16", ["a6"]>, DwarfRegNum<[16]>;
10099
def X17 : RISCVReg<17,"x17", ["a7"]>, DwarfRegNum<[17]>;
101100
def X18 : RISCVReg<18,"x18", ["s2"]>, DwarfRegNum<[18]>;

llvm/test/CodeGen/RISCV/add-before-shl.ll

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,23 @@ define i128 @add_wide_operand(i128 %a) nounwind {
163163
; RV32I: # %bb.0:
164164
; RV32I-NEXT: lw a2, 0(a1)
165165
; RV32I-NEXT: lw a3, 4(a1)
166-
; RV32I-NEXT: lw a6, 12(a1)
166+
; RV32I-NEXT: lw a4, 12(a1)
167167
; RV32I-NEXT: lw a1, 8(a1)
168168
; RV32I-NEXT: srli a5, a2, 29
169-
; RV32I-NEXT: slli a4, a3, 3
170-
; RV32I-NEXT: or a4, a4, a5
169+
; RV32I-NEXT: slli a6, a3, 3
170+
; RV32I-NEXT: or a5, a6, a5
171171
; RV32I-NEXT: srli a3, a3, 29
172-
; RV32I-NEXT: slli a5, a1, 3
173-
; RV32I-NEXT: or a3, a5, a3
172+
; RV32I-NEXT: slli a6, a1, 3
173+
; RV32I-NEXT: or a3, a6, a3
174174
; RV32I-NEXT: srli a1, a1, 29
175-
; RV32I-NEXT: slli a5, a6, 3
176-
; RV32I-NEXT: or a1, a5, a1
175+
; RV32I-NEXT: slli a4, a4, 3
176+
; RV32I-NEXT: or a1, a4, a1
177177
; RV32I-NEXT: slli a2, a2, 3
178-
; RV32I-NEXT: lui a5, 128
179-
; RV32I-NEXT: add a1, a1, a5
178+
; RV32I-NEXT: lui a4, 128
179+
; RV32I-NEXT: add a1, a1, a4
180180
; RV32I-NEXT: sw a2, 0(a0)
181181
; RV32I-NEXT: sw a3, 8(a0)
182-
; RV32I-NEXT: sw a4, 4(a0)
182+
; RV32I-NEXT: sw a5, 4(a0)
183183
; RV32I-NEXT: sw a1, 12(a0)
184184
; RV32I-NEXT: jalr zero, 0(ra)
185185
;

llvm/test/CodeGen/RISCV/addcarry.ll

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ define i64 @addcarry(i64 %x, i64 %y) nounwind {
1010
; RISCV32-LABEL: addcarry:
1111
; RISCV32: # %bb.0:
1212
; RISCV32-NEXT: mul a4, a0, a3
13-
; RISCV32-NEXT: mulhu a7, a0, a2
14-
; RISCV32-NEXT: add a4, a7, a4
15-
; RISCV32-NEXT: mul a5, a1, a2
16-
; RISCV32-NEXT: add a6, a4, a5
17-
; RISCV32-NEXT: sltu t0, a6, a4
18-
; RISCV32-NEXT: sltu a4, a4, a7
19-
; RISCV32-NEXT: mulhu a5, a0, a3
20-
; RISCV32-NEXT: add a4, a5, a4
21-
; RISCV32-NEXT: mulhu a5, a1, a2
22-
; RISCV32-NEXT: add a4, a4, a5
23-
; RISCV32-NEXT: add a4, a4, t0
24-
; RISCV32-NEXT: mul a5, a1, a3
25-
; RISCV32-NEXT: add a5, a4, a5
13+
; RISCV32-NEXT: mulhu a5, a0, a2
14+
; RISCV32-NEXT: add a6, a5, a4
15+
; RISCV32-NEXT: mul a4, a1, a2
16+
; RISCV32-NEXT: add a4, a6, a4
17+
; RISCV32-NEXT: sltu a7, a4, a6
18+
; RISCV32-NEXT: sltu a5, a6, a5
19+
; RISCV32-NEXT: mulhu a6, a0, a3
20+
; RISCV32-NEXT: add a5, a6, a5
21+
; RISCV32-NEXT: mulhu a6, a1, a2
22+
; RISCV32-NEXT: add a5, a5, a6
23+
; RISCV32-NEXT: add a5, a5, a7
24+
; RISCV32-NEXT: mul a6, a1, a3
25+
; RISCV32-NEXT: add a5, a5, a6
2626
; RISCV32-NEXT: bgez a1, .LBB0_2
2727
; RISCV32-NEXT: # %bb.1:
2828
; RISCV32-NEXT: sub a5, a5, a2
@@ -32,9 +32,9 @@ define i64 @addcarry(i64 %x, i64 %y) nounwind {
3232
; RISCV32-NEXT: sub a5, a5, a0
3333
; RISCV32-NEXT: .LBB0_4:
3434
; RISCV32-NEXT: slli a1, a5, 30
35-
; RISCV32-NEXT: srli a3, a6, 2
35+
; RISCV32-NEXT: srli a3, a4, 2
3636
; RISCV32-NEXT: or a1, a1, a3
37-
; RISCV32-NEXT: slli a3, a6, 30
37+
; RISCV32-NEXT: slli a3, a4, 30
3838
; RISCV32-NEXT: mul a0, a0, a2
3939
; RISCV32-NEXT: srli a0, a0, 2
4040
; RISCV32-NEXT: or a0, a3, a0

0 commit comments

Comments
 (0)