Skip to content

Commit 6ec71fe

Browse files
asbmahesh-attarde
authored andcommitted
[RISCV] Add RISCV::SUBW to RISCVOptWInstrs::stripWSuffixes (llvm#149071)
This is purely a benefit for reducing unnecessary diffs between RV32 and RV64, as RVC does have a compressed form of SUBW (so SUB isn't more compressible). This affects ~57.2k instructions in an rva22u64 build of llvm-test-suite with SPEC CPU 2017 included.
1 parent 7da6a56 commit 6ec71fe

Some content is hidden

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

52 files changed

+600
-629
lines changed

llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,14 +731,17 @@ bool RISCVOptWInstrs::stripWSuffixes(MachineFunction &MF,
731731
for (MachineBasicBlock &MBB : MF) {
732732
for (MachineInstr &MI : MBB) {
733733
unsigned Opc;
734+
// clang-format off
734735
switch (MI.getOpcode()) {
735736
default:
736737
continue;
737738
case RISCV::ADDW: Opc = RISCV::ADD; break;
738739
case RISCV::ADDIW: Opc = RISCV::ADDI; break;
739740
case RISCV::MULW: Opc = RISCV::MUL; break;
740741
case RISCV::SLLIW: Opc = RISCV::SLLI; break;
742+
case RISCV::SUBW: Opc = RISCV::SUB; break;
741743
}
744+
// clang-format on
742745

743746
if (hasAllWUsers(MI, ST, MRI)) {
744747
LLVM_DEBUG(dbgs() << "Replacing " << MI);

llvm/test/CodeGen/RISCV/GlobalISel/div-by-constant.ll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ define i32 @udiv_constant_add(i32 %a) nounwind {
6666
; RV64IM-NEXT: srli a2, a2, 32
6767
; RV64IM-NEXT: mul a1, a2, a1
6868
; RV64IM-NEXT: srli a1, a1, 32
69-
; RV64IM-NEXT: subw a0, a0, a1
69+
; RV64IM-NEXT: sub a0, a0, a1
7070
; RV64IM-NEXT: srliw a0, a0, 1
7171
; RV64IM-NEXT: add a0, a0, a1
7272
; RV64IM-NEXT: srliw a0, a0, 2
@@ -79,7 +79,7 @@ define i32 @udiv_constant_add(i32 %a) nounwind {
7979
; RV64IMZB-NEXT: zext.w a2, a0
8080
; RV64IMZB-NEXT: mul a1, a2, a1
8181
; RV64IMZB-NEXT: srli a1, a1, 32
82-
; RV64IMZB-NEXT: subw a0, a0, a1
82+
; RV64IMZB-NEXT: sub a0, a0, a1
8383
; RV64IMZB-NEXT: srliw a0, a0, 1
8484
; RV64IMZB-NEXT: add a0, a0, a1
8585
; RV64IMZB-NEXT: srliw a0, a0, 2
@@ -250,7 +250,7 @@ define i8 @udiv8_constant_add(i8 %a) nounwind {
250250
; RV64-NEXT: zext.b a2, a0
251251
; RV64-NEXT: mul a1, a2, a1
252252
; RV64-NEXT: srli a1, a1, 8
253-
; RV64-NEXT: subw a0, a0, a1
253+
; RV64-NEXT: sub a0, a0, a1
254254
; RV64-NEXT: zext.b a0, a0
255255
; RV64-NEXT: srli a0, a0, 1
256256
; RV64-NEXT: add a0, a0, a1
@@ -816,7 +816,7 @@ define i8 @sdiv8_constant_sub_srai(i8 %a) nounwind {
816816
; RV64IM-NEXT: mul a1, a2, a1
817817
; RV64IM-NEXT: slli a1, a1, 48
818818
; RV64IM-NEXT: srai a1, a1, 56
819-
; RV64IM-NEXT: subw a1, a1, a0
819+
; RV64IM-NEXT: sub a1, a1, a0
820820
; RV64IM-NEXT: slli a1, a1, 56
821821
; RV64IM-NEXT: srai a0, a1, 58
822822
; RV64IM-NEXT: zext.b a1, a0
@@ -1071,7 +1071,7 @@ define i16 @sdiv16_constant_sub_srai(i16 %a) nounwind {
10711071
; RV64IM-NEXT: srai a2, a2, 48
10721072
; RV64IM-NEXT: mul a1, a2, a1
10731073
; RV64IM-NEXT: sraiw a1, a1, 16
1074-
; RV64IM-NEXT: subw a1, a1, a0
1074+
; RV64IM-NEXT: sub a1, a1, a0
10751075
; RV64IM-NEXT: slli a1, a1, 48
10761076
; RV64IM-NEXT: srai a0, a1, 51
10771077
; RV64IM-NEXT: slli a1, a0, 48

0 commit comments

Comments
 (0)