Skip to content

[RISCV] Add a tune feature to disable stripping W suffix #86255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/lib/Target/RISCV/RISCVFeatures.td
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,10 @@ def TuneNoSinkSplatOperands
"false", "Disable sink splat operands to enable .vx, .vf,"
".wx, and .wf instructions">;

def TuneNoStripWSuffix
: SubtargetFeature<"no-strip-w-suffix", "EnableStripWSuffix", "false",
"Disable strip W suffix">;

def TuneConditionalCompressedMoveFusion
: SubtargetFeature<"conditional-cmv-fusion", "HasConditionalCompressedMoveFusion",
"true", "Enable branch+c.mv fusion">;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ bool RISCVOptWInstrs::stripWSuffixes(MachineFunction &MF,
const RISCVInstrInfo &TII,
const RISCVSubtarget &ST,
MachineRegisterInfo &MRI) {
if (DisableStripWSuffix)
if (DisableStripWSuffix || !ST.enableStripWSuffix())
return false;

bool MadeChange = false;
Expand Down
74 changes: 74 additions & 0 deletions llvm/test/CodeGen/RISCV/strip-w-suffix.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=riscv64 -mattr=+m -verify-machineinstrs < %s \
; RUN: | FileCheck -check-prefixes=STRIP %s
; RUN: llc -mtriple=riscv64 -mattr=+m,+no-strip-w-suffix -verify-machineinstrs < %s \
; RUN: | FileCheck -check-prefixes=NO-STRIP %s

define i32 @addiw(i32 %a) {
; STRIP-LABEL: addiw:
; STRIP: # %bb.0:
; STRIP-NEXT: lui a1, 1
; STRIP-NEXT: addi a1, a1, -1
; STRIP-NEXT: addw a0, a0, a1
; STRIP-NEXT: ret
;
; NO-STRIP-LABEL: addiw:
; NO-STRIP: # %bb.0:
; NO-STRIP-NEXT: lui a1, 1
; NO-STRIP-NEXT: addiw a1, a1, -1
; NO-STRIP-NEXT: addw a0, a0, a1
; NO-STRIP-NEXT: ret
%ret = add i32 %a, 4095
ret i32 %ret
}

define i32 @addw(i32 %a, i32 %b) {
; STRIP-LABEL: addw:
; STRIP: # %bb.0:
; STRIP-NEXT: add a0, a0, a1
; STRIP-NEXT: addiw a0, a0, 1024
; STRIP-NEXT: ret
;
; NO-STRIP-LABEL: addw:
; NO-STRIP: # %bb.0:
; NO-STRIP-NEXT: addw a0, a0, a1
; NO-STRIP-NEXT: addiw a0, a0, 1024
; NO-STRIP-NEXT: ret
%add = add i32 %a, %b
%ret = add i32 %add, 1024
ret i32 %ret
}

define i32 @mulw(i32 %a, i32 %b) {
; STRIP-LABEL: mulw:
; STRIP: # %bb.0:
; STRIP-NEXT: mul a0, a0, a1
; STRIP-NEXT: addiw a0, a0, 1024
; STRIP-NEXT: ret
;
; NO-STRIP-LABEL: mulw:
; NO-STRIP: # %bb.0:
; NO-STRIP-NEXT: mulw a0, a0, a1
; NO-STRIP-NEXT: addiw a0, a0, 1024
; NO-STRIP-NEXT: ret
%mul = mul i32 %a, %b
%ret = add i32 %mul, 1024
ret i32 %ret
}

define i32 @slliw(i32 %a) {
; STRIP-LABEL: slliw:
; STRIP: # %bb.0:
; STRIP-NEXT: slli a0, a0, 1
; STRIP-NEXT: addiw a0, a0, 1024
; STRIP-NEXT: ret
;
; NO-STRIP-LABEL: slliw:
; NO-STRIP: # %bb.0:
; NO-STRIP-NEXT: slliw a0, a0, 1
; NO-STRIP-NEXT: addiw a0, a0, 1024
; NO-STRIP-NEXT: ret
%shl = shl i32 %a, 1
%ret = add i32 %shl, 1024
ret i32 %ret
}