Skip to content

Commit 35bd40d

Browse files
authored
[RISCV] add more generic macrofusions (#151140)
These are some macrofusions that are used internally in Ventana in an yet not upstreamed processor. Figured it would be good to contribute them ahead of the processor to allow the community to also use them in their own processors, while also alleaviting our own downstream upkeep. The macrofusions being added are, considering load = lb,lh,lw,ld,lbu,lhu,lwu: - bfext (slli+srli) - auipc+load - lui+load - add(.uw)+load - addi+load - shXadd(.uw)+load, where X=1,2,3
1 parent 0e0ea71 commit 35bd40d

File tree

4 files changed

+1441
-1
lines changed

4 files changed

+1441
-1
lines changed

llvm/lib/Target/RISCV/RISCVMacroFusion.td

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,59 @@ def TuneLDADDFusion
9191
CheckIsImmOperand<2>,
9292
CheckImmOperand<2, 0>
9393
]>>;
94+
95+
defvar Load = [LB, LH, LW, LD, LBU, LHU, LWU];
96+
97+
// Fuse add(.uw) followed by a load (lb, lh, lw, ld, lbu, lhu, lwu):
98+
// add(.uw) rd, rs1, rs2
99+
// load rd, imm12(rd)
100+
def TuneADDLoadFusion
101+
: SimpleFusion<"add-load-fusion", "HasADDLoadFusion", "Enable ADD(.UW) + load macrofusion",
102+
CheckOpcode<[ADD, ADD_UW]>,
103+
CheckOpcode<Load>>;
104+
105+
// Fuse AUIPC followed by by a load (lb, lh, lw, ld, lbu, lhu, lwu)
106+
// auipc rd, imm20
107+
// load rd, imm12(rd)
108+
def TuneAUIPCLoadFusion
109+
: SimpleFusion<"auipc-load-fusion", "HasAUIPCLoadFusion",
110+
"Enable AUIPC + load macrofusion",
111+
CheckOpcode<[AUIPC]>,
112+
CheckOpcode<Load>>;
113+
114+
// Fuse LUI followed by a load (lb, lh, lw, ld, lbu, lhu, lwu)
115+
// lui rd, imm[31:12]
116+
// load rd, imm12(rd)
117+
def TuneLUILoadFusion
118+
: SimpleFusion<"lui-load-fusion", "HasLUILoadFusion",
119+
"Enable LUI + load macrofusion",
120+
CheckOpcode<[LUI]>,
121+
CheckOpcode<Load>>;
122+
123+
// Bitfield extract fusion: similar to TuneShiftedZExtWFusion
124+
// but without the immediate restriction
125+
// slli rd, rs1, imm12
126+
// srli rd, rd, imm12
127+
def TuneBFExtFusion
128+
: SimpleFusion<"bfext-fusion", "HasBFExtFusion",
129+
"Enable SLLI+SRLI (bitfield extract) macrofusion",
130+
CheckOpcode<[SLLI]>,
131+
CheckOpcode<[SRLI]>>;
132+
133+
// Fuse ADDI followed by a load (lb, lh, lw, ld, lbu, lhu, lwu)
134+
// addi rd, rs1, imm12
135+
// load rd, imm12(rd)
136+
def TuneADDILoadFusion
137+
: SimpleFusion<"addi-load-fusion", "HasADDILoadFusion",
138+
"Enable ADDI + load macrofusion",
139+
CheckOpcode<[ADDI]>,
140+
CheckOpcode<Load>>;
141+
142+
// Fuse shXadd(.uw) followed by a load (lb, lh, lw, ld, lbu, lhu, lwu)
143+
// shXadd(.uw) rd, rs1, rs2
144+
// load rd, imm12(rd)
145+
def TuneSHXADDLoadFusion
146+
: SimpleFusion<"shxadd-load-fusion", "HasSHXADDLoadFusion",
147+
"Enable SH(1|2|3)ADD(.UW) + load macrofusion",
148+
CheckOpcode<[SH1ADD, SH2ADD, SH3ADD, SH1ADD_UW, SH2ADD_UW, SH3ADD_UW]>,
149+
CheckOpcode<Load>>;

llvm/lib/Target/RISCV/RISCVProcessors.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,9 @@ def VENTANA_VEYRON_V1 : RISCVProcessorModel<"veyron-v1",
598598
TuneZExtHFusion,
599599
TuneZExtWFusion,
600600
TuneShiftedZExtWFusion,
601-
TuneLDADDFusion]> {
601+
TuneADDLoadFusion,
602+
TuneAUIPCLoadFusion,
603+
TuneLUILoadFusion]> {
602604
let MVendorID = 0x61f;
603605
let MArchID = 0x8000000000010000;
604606
let MImpID = 0x111;

llvm/test/CodeGen/RISCV/features-info.ll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
; CHECK-NEXT: 32bit - Implements RV32.
77
; CHECK-NEXT: 64bit - Implements RV64.
88
; CHECK-NEXT: a - 'A' (Atomic Instructions).
9+
; CHECK-NEXT: add-load-fusion - Enable ADD(.UW) + load macrofusion.
10+
; CHECK-NEXT: addi-load-fusion - Enable ADDI + load macrofusion.
911
; CHECK-NEXT: andes45 - Andes 45-Series processors.
1012
; CHECK-NEXT: auipc-addi-fusion - Enable AUIPC+ADDI macrofusion.
13+
; CHECK-NEXT: auipc-load-fusion - Enable AUIPC + load macrofusion.
1114
; CHECK-NEXT: b - 'B' (the collection of the Zba, Zbb, Zbs extensions).
15+
; CHECK-NEXT: bfext-fusion - Enable SLLI+SRLI (bitfield extract) macrofusion.
1216
; CHECK-NEXT: c - 'C' (Compressed Instructions).
1317
; CHECK-NEXT: conditional-cmv-fusion - Enable branch+c.mv fusion.
1418
; CHECK-NEXT: d - 'D' (Double-Precision Floating-Point).
@@ -62,6 +66,7 @@
6266
; CHECK-NEXT: ld-add-fusion - Enable LD+ADD macrofusion.
6367
; CHECK-NEXT: log-vrgather - Has vrgather.vv with LMUL*log2(LMUL) latency
6468
; CHECK-NEXT: lui-addi-fusion - Enable LUI+ADDI macro fusion.
69+
; CHECK-NEXT: lui-load-fusion - Enable LUI + load macrofusion.
6570
; CHECK-NEXT: m - 'M' (Integer Multiplication and Division).
6671
; CHECK-NEXT: mips-p8700 - MIPS p8700 processor.
6772
; CHECK-NEXT: no-default-unroll - Disable default unroll preference..
@@ -134,6 +139,7 @@
134139
; CHECK-NEXT: shvsatpa - 'Shvsatpa' (vsatp supports all modes supported by satp).
135140
; CHECK-NEXT: shvstvala - 'Shvstvala' (vstval provides all needed values).
136141
; CHECK-NEXT: shvstvecd - 'Shvstvecd' (vstvec supports Direct mode).
142+
; CHECK-NEXT: shxadd-load-fusion - Enable SH(1|2|3)ADD(.UW) + load macrofusion.
137143
; CHECK-NEXT: sifive7 - SiFive 7-Series processors.
138144
; CHECK-NEXT: smaia - 'Smaia' (Advanced Interrupt Architecture Machine Level).
139145
; CHECK-NEXT: smcdeleg - 'Smcdeleg' (Counter Delegation Machine Level).

0 commit comments

Comments
 (0)