[llvm] 07ed62b - [RISCV] Disable (mul (and X, 0xffffffff), (and Y, 0xffffffff)) optimization when Zba is enabled.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 20 15:33:12 PDT 2021


Author: Craig Topper
Date: 2021-03-20T15:31:45-07:00
New Revision: 07ed62b7d5514937a50b4af4feaa1969911d142e

URL: https://github.com/llvm/llvm-project/commit/07ed62b7d5514937a50b4af4feaa1969911d142e
DIFF: https://github.com/llvm/llvm-project/commit/07ed62b7d5514937a50b4af4feaa1969911d142e.diff

LOG: [RISCV] Disable (mul (and X, 0xffffffff), (and Y, 0xffffffff)) optimization when Zba is enabled.

This optimization is trying to save SRLI instructions needed to
implement the ANDs. If we have zext.w we won't save anything.
Because we don't check that the multiply is the only user of the
AND we might even increase instruction count.

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/RISCVInstrInfoM.td
    llvm/test/CodeGen/RISCV/xaluo.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVInstrInfoM.td b/llvm/lib/Target/RISCV/RISCVInstrInfoM.td
index d38b5a98b31c..8d5f3e92355a 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoM.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoM.td
@@ -93,7 +93,9 @@ def : Pat<(and (riscv_remuw (assertzexti32 GPR:$rs1),
 // produce a result where res[63:32]=0 and res[31]=1.
 def : Pat<(srem (sexti32 (i64 GPR:$rs1)), (sexti32 (i64 GPR:$rs2))),
           (REMW GPR:$rs1, GPR:$rs2)>;
+} // Predicates = [HasStdExtM, IsRV64]
 
+let Predicates = [HasStdExtM, IsRV64, NotHasStdExtZba] in {
 // Special case for calculating the full 64-bit product of a 32x32 unsigned
 // multiply where the inputs aren't known to be zero extended. We can shift the
 // inputs left by 32 and use a MULHU. This saves two SRLIs needed to finish

diff  --git a/llvm/test/CodeGen/RISCV/xaluo.ll b/llvm/test/CodeGen/RISCV/xaluo.ll
index 758cf4c41801..f34093e8d6f3 100644
--- a/llvm/test/CodeGen/RISCV/xaluo.ll
+++ b/llvm/test/CodeGen/RISCV/xaluo.ll
@@ -967,9 +967,9 @@ define zeroext i1 @umulo.i32(i32 %v1, i32 %v2, i32* %res) {
 ;
 ; RV64ZBA-LABEL: umulo.i32:
 ; RV64ZBA:       # %bb.0: # %entry
-; RV64ZBA-NEXT:    slli a1, a1, 32
-; RV64ZBA-NEXT:    slli a0, a0, 32
-; RV64ZBA-NEXT:    mulhu a1, a0, a1
+; RV64ZBA-NEXT:    zext.w a1, a1
+; RV64ZBA-NEXT:    zext.w a0, a0
+; RV64ZBA-NEXT:    mul a1, a0, a1
 ; RV64ZBA-NEXT:    srli a0, a1, 32
 ; RV64ZBA-NEXT:    snez a0, a0
 ; RV64ZBA-NEXT:    sw a1, 0(a2)
@@ -2270,9 +2270,9 @@ define i32 @umulo.select.i32(i32 %v1, i32 %v2) {
 ;
 ; RV64ZBA-LABEL: umulo.select.i32:
 ; RV64ZBA:       # %bb.0: # %entry
-; RV64ZBA-NEXT:    slli a2, a1, 32
-; RV64ZBA-NEXT:    slli a3, a0, 32
-; RV64ZBA-NEXT:    mulhu a2, a3, a2
+; RV64ZBA-NEXT:    zext.w a2, a1
+; RV64ZBA-NEXT:    zext.w a3, a0
+; RV64ZBA-NEXT:    mul a2, a3, a2
 ; RV64ZBA-NEXT:    srli a2, a2, 32
 ; RV64ZBA-NEXT:    bnez a2, .LBB42_2
 ; RV64ZBA-NEXT:  # %bb.1: # %entry
@@ -2310,9 +2310,9 @@ define i1 @umulo.not.i32(i32 %v1, i32 %v2) {
 ;
 ; RV64ZBA-LABEL: umulo.not.i32:
 ; RV64ZBA:       # %bb.0: # %entry
-; RV64ZBA-NEXT:    slli a1, a1, 32
-; RV64ZBA-NEXT:    slli a0, a0, 32
-; RV64ZBA-NEXT:    mulhu a0, a0, a1
+; RV64ZBA-NEXT:    zext.w a1, a1
+; RV64ZBA-NEXT:    zext.w a0, a0
+; RV64ZBA-NEXT:    mul a0, a0, a1
 ; RV64ZBA-NEXT:    srli a0, a0, 32
 ; RV64ZBA-NEXT:    seqz a0, a0
 ; RV64ZBA-NEXT:    ret
@@ -3281,9 +3281,9 @@ define zeroext i1 @umulo.br.i32(i32 %v1, i32 %v2) {
 ;
 ; RV64ZBA-LABEL: umulo.br.i32:
 ; RV64ZBA:       # %bb.0: # %entry
-; RV64ZBA-NEXT:    slli a1, a1, 32
-; RV64ZBA-NEXT:    slli a0, a0, 32
-; RV64ZBA-NEXT:    mulhu a0, a0, a1
+; RV64ZBA-NEXT:    zext.w a1, a1
+; RV64ZBA-NEXT:    zext.w a0, a0
+; RV64ZBA-NEXT:    mul a0, a0, a1
 ; RV64ZBA-NEXT:    srli a0, a0, 32
 ; RV64ZBA-NEXT:    beqz a0, .LBB57_2
 ; RV64ZBA-NEXT:  # %bb.1: # %overflow


        


More information about the llvm-commits mailing list