Skip to content

Commit 6af6416

Browse files
authored
[RISCV] Add a tune feature to disable stripping W suffix (#86255)
We have a hidden option to disable it, but I'd like to make it a tune feature. For some implementations, instructions with W suffix would be less costly as they only perform on 32 bits data. Though we may lose some chances to compress.
1 parent 5e5b656 commit 6af6416

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,10 @@ def TuneNoSinkSplatOperands
12261226
"false", "Disable sink splat operands to enable .vx, .vf,"
12271227
".wx, and .wf instructions">;
12281228

1229+
def TuneNoStripWSuffix
1230+
: SubtargetFeature<"no-strip-w-suffix", "EnableStripWSuffix", "false",
1231+
"Disable strip W suffix">;
1232+
12291233
def TuneConditionalCompressedMoveFusion
12301234
: SubtargetFeature<"conditional-cmv-fusion", "HasConditionalCompressedMoveFusion",
12311235
"true", "Enable branch+c.mv fusion">;

llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ bool RISCVOptWInstrs::stripWSuffixes(MachineFunction &MF,
672672
const RISCVInstrInfo &TII,
673673
const RISCVSubtarget &ST,
674674
MachineRegisterInfo &MRI) {
675-
if (DisableStripWSuffix)
675+
if (DisableStripWSuffix || !ST.enableStripWSuffix())
676676
return false;
677677

678678
bool MadeChange = false;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=riscv64 -mattr=+m -verify-machineinstrs < %s \
3+
; RUN: | FileCheck -check-prefixes=STRIP %s
4+
; RUN: llc -mtriple=riscv64 -mattr=+m,+no-strip-w-suffix -verify-machineinstrs < %s \
5+
; RUN: | FileCheck -check-prefixes=NO-STRIP %s
6+
7+
define i32 @addiw(i32 %a) {
8+
; STRIP-LABEL: addiw:
9+
; STRIP: # %bb.0:
10+
; STRIP-NEXT: lui a1, 1
11+
; STRIP-NEXT: addi a1, a1, -1
12+
; STRIP-NEXT: addw a0, a0, a1
13+
; STRIP-NEXT: ret
14+
;
15+
; NO-STRIP-LABEL: addiw:
16+
; NO-STRIP: # %bb.0:
17+
; NO-STRIP-NEXT: lui a1, 1
18+
; NO-STRIP-NEXT: addiw a1, a1, -1
19+
; NO-STRIP-NEXT: addw a0, a0, a1
20+
; NO-STRIP-NEXT: ret
21+
%ret = add i32 %a, 4095
22+
ret i32 %ret
23+
}
24+
25+
define i32 @addw(i32 %a, i32 %b) {
26+
; STRIP-LABEL: addw:
27+
; STRIP: # %bb.0:
28+
; STRIP-NEXT: add a0, a0, a1
29+
; STRIP-NEXT: addiw a0, a0, 1024
30+
; STRIP-NEXT: ret
31+
;
32+
; NO-STRIP-LABEL: addw:
33+
; NO-STRIP: # %bb.0:
34+
; NO-STRIP-NEXT: addw a0, a0, a1
35+
; NO-STRIP-NEXT: addiw a0, a0, 1024
36+
; NO-STRIP-NEXT: ret
37+
%add = add i32 %a, %b
38+
%ret = add i32 %add, 1024
39+
ret i32 %ret
40+
}
41+
42+
define i32 @mulw(i32 %a, i32 %b) {
43+
; STRIP-LABEL: mulw:
44+
; STRIP: # %bb.0:
45+
; STRIP-NEXT: mul a0, a0, a1
46+
; STRIP-NEXT: addiw a0, a0, 1024
47+
; STRIP-NEXT: ret
48+
;
49+
; NO-STRIP-LABEL: mulw:
50+
; NO-STRIP: # %bb.0:
51+
; NO-STRIP-NEXT: mulw a0, a0, a1
52+
; NO-STRIP-NEXT: addiw a0, a0, 1024
53+
; NO-STRIP-NEXT: ret
54+
%mul = mul i32 %a, %b
55+
%ret = add i32 %mul, 1024
56+
ret i32 %ret
57+
}
58+
59+
define i32 @slliw(i32 %a) {
60+
; STRIP-LABEL: slliw:
61+
; STRIP: # %bb.0:
62+
; STRIP-NEXT: slli a0, a0, 1
63+
; STRIP-NEXT: addiw a0, a0, 1024
64+
; STRIP-NEXT: ret
65+
;
66+
; NO-STRIP-LABEL: slliw:
67+
; NO-STRIP: # %bb.0:
68+
; NO-STRIP-NEXT: slliw a0, a0, 1
69+
; NO-STRIP-NEXT: addiw a0, a0, 1024
70+
; NO-STRIP-NEXT: ret
71+
%shl = shl i32 %a, 1
72+
%ret = add i32 %shl, 1024
73+
ret i32 %ret
74+
}

0 commit comments

Comments
 (0)