[PATCH] D107820: [RISCV] Optimize mul in the zba extension with SH*ADD
Ben Shi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 10 05:57:40 PDT 2021
benshi001 updated this revision to Diff 365453.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107820/new/
https://reviews.llvm.org/D107820
Files:
llvm/lib/Target/RISCV/RISCVInstrInfoB.td
llvm/test/CodeGen/RISCV/rv64zba.ll
Index: llvm/test/CodeGen/RISCV/rv64zba.ll
===================================================================
--- llvm/test/CodeGen/RISCV/rv64zba.ll
+++ llvm/test/CodeGen/RISCV/rv64zba.ll
@@ -1254,14 +1254,14 @@
;
; RV64IB-LABEL: mulw192:
; RV64IB: # %bb.0:
-; RV64IB-NEXT: addi a1, zero, 192
-; RV64IB-NEXT: mulw a0, a0, a1
+; RV64IB-NEXT: sh1add a0, a0, a0
+; RV64IB-NEXT: slliw a0, a0, 6
; RV64IB-NEXT: ret
;
; RV64IBA-LABEL: mulw192:
; RV64IBA: # %bb.0:
-; RV64IBA-NEXT: addi a1, zero, 192
-; RV64IBA-NEXT: mulw a0, a0, a1
+; RV64IBA-NEXT: sh1add a0, a0, a0
+; RV64IBA-NEXT: slliw a0, a0, 6
; RV64IBA-NEXT: ret
%c = mul i32 %a, 192
ret i32 %c
@@ -1276,14 +1276,14 @@
;
; RV64IB-LABEL: mulw320:
; RV64IB: # %bb.0:
-; RV64IB-NEXT: addi a1, zero, 320
-; RV64IB-NEXT: mulw a0, a0, a1
+; RV64IB-NEXT: sh2add a0, a0, a0
+; RV64IB-NEXT: slliw a0, a0, 6
; RV64IB-NEXT: ret
;
; RV64IBA-LABEL: mulw320:
; RV64IBA: # %bb.0:
-; RV64IBA-NEXT: addi a1, zero, 320
-; RV64IBA-NEXT: mulw a0, a0, a1
+; RV64IBA-NEXT: sh2add a0, a0, a0
+; RV64IBA-NEXT: slliw a0, a0, 6
; RV64IBA-NEXT: ret
%c = mul i32 %a, 320
ret i32 %c
@@ -1298,14 +1298,14 @@
;
; RV64IB-LABEL: mulw576:
; RV64IB: # %bb.0:
-; RV64IB-NEXT: addi a1, zero, 576
-; RV64IB-NEXT: mulw a0, a0, a1
+; RV64IB-NEXT: sh3add a0, a0, a0
+; RV64IB-NEXT: slliw a0, a0, 6
; RV64IB-NEXT: ret
;
; RV64IBA-LABEL: mulw576:
; RV64IBA: # %bb.0:
-; RV64IBA-NEXT: addi a1, zero, 576
-; RV64IBA-NEXT: mulw a0, a0, a1
+; RV64IBA-NEXT: sh3add a0, a0, a0
+; RV64IBA-NEXT: slliw a0, a0, 6
; RV64IBA-NEXT: ret
%c = mul i32 %a, 576
ret i32 %c
Index: llvm/lib/Target/RISCV/RISCVInstrInfoB.td
===================================================================
--- llvm/lib/Target/RISCV/RISCVInstrInfoB.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfoB.td
@@ -1065,6 +1065,16 @@
(SH2ADDUW GPR:$rs1, GPR:$rs2)>;
def : Pat<(i64 (add (and (shl GPR:$rs1, (i64 3)), 0x7FFFFFFFF), non_imm12:$rs2)),
(SH3ADDUW GPR:$rs1, GPR:$rs2)>;
+
+def : Pat<(i64 (sext_inreg (mul GPR:$r, C3LeftShift:$i), i32)),
+ (SLLIW (SH1ADD GPR:$r, GPR:$r),
+ (TrailingZerosXForm C3LeftShift:$i))>;
+def : Pat<(i64 (sext_inreg (mul GPR:$r, C5LeftShift:$i), i32)),
+ (SLLIW (SH2ADD GPR:$r, GPR:$r),
+ (TrailingZerosXForm C5LeftShift:$i))>;
+def : Pat<(i64 (sext_inreg (mul GPR:$r, C9LeftShift:$i), i32)),
+ (SLLIW (SH3ADD GPR:$r, GPR:$r),
+ (TrailingZerosXForm C9LeftShift:$i))>;
} // Predicates = [HasStdExtZba, IsRV64]
let Predicates = [HasStdExtZbbOrZbp, IsRV64] in {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107820.365453.patch
Type: text/x-patch
Size: 2723 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210810/79d17f99/attachment.bin>
More information about the llvm-commits
mailing list