[llvm] bfb7843 - [RISCV] Add packw/packh patterns for -riscv-experimental-rv64-legal-i32
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 11 17:56:29 PST 2023
Author: Craig Topper
Date: 2023-11-11T17:52:22-08:00
New Revision: bfb7843580ae27996e4dc0a49e898d142d1dc358
URL: https://github.com/llvm/llvm-project/commit/bfb7843580ae27996e4dc0a49e898d142d1dc358
DIFF: https://github.com/llvm/llvm-project/commit/bfb7843580ae27996e4dc0a49e898d142d1dc358.diff
LOG: [RISCV] Add packw/packh patterns for -riscv-experimental-rv64-legal-i32
Added:
Modified:
llvm/lib/Target/RISCV/RISCVInstrInfo.td
llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zbkb.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
index 93e75b3c640b007..034d67f0f928f5f 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -1208,7 +1208,9 @@ def assertzexti32 : PatFrag<(ops node:$src), (assertzext node:$src), [{
}]>;
def zexti32 : ComplexPattern<i64, 1, "selectZExtBits<32>">;
def zexti16 : ComplexPattern<XLenVT, 1, "selectZExtBits<16>">;
+def zexti16i32 : ComplexPattern<i32, 1, "selectZExtBits<16>">;
def zexti8 : ComplexPattern<XLenVT, 1, "selectZExtBits<8>">;
+def zexti8i32 : ComplexPattern<i32, 1, "selectZExtBits<8>">;
def ext : PatFrags<(ops node:$A), [(sext node:$A), (zext node:$A)]>;
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
index 05bd5b56d24a777..1ecbbd6323b0a44 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
@@ -846,6 +846,18 @@ def : Pat<(i32 (rotl GPR:$rs1, uimm5:$rs2)),
(RORIW GPR:$rs1, (ImmSubFrom32 uimm5:$rs2))>;
} // Predicates = [HasStdExtZbbOrZbkb, IsRV64]
+let Predicates = [HasStdExtZbkb, IsRV64] in {
+def : Pat<(or (and (shl GPR:$rs2, (i64 8)), 0xFFFF),
+ (zexti8i32 (i32 GPR:$rs1))),
+ (PACKH GPR:$rs1, GPR:$rs2)>;
+def : Pat<(or (shl (zexti8i32 (i32 GPR:$rs2)), (i64 8)),
+ (zexti8i32 (i32 GPR:$rs1))),
+ (PACKH GPR:$rs1, GPR:$rs2)>;
+
+def : Pat<(i32 (or (shl GPR:$rs2, (i64 16)), (zexti16i32 (i32 GPR:$rs1)))),
+ (PACKW GPR:$rs1, GPR:$rs2)>;
+} // Predicates = [HasStdExtZbkb, IsRV64]
+
let Predicates = [HasStdExtZba, IsRV64] in {
def : Pat<(shl (i64 (zext i32:$rs1)), uimm5:$shamt),
(SLLI_UW GPR:$rs1, uimm5:$shamt)>;
diff --git a/llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zbkb.ll b/llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zbkb.ll
index 9187600fc41546c..1dbee8b283d1515 100644
--- a/llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zbkb.ll
+++ b/llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zbkb.ll
@@ -15,10 +15,7 @@ define signext i32 @pack_i32(i32 signext %a, i32 signext %b) nounwind {
;
; RV64ZBKB-LABEL: pack_i32:
; RV64ZBKB: # %bb.0:
-; RV64ZBKB-NEXT: slli a0, a0, 48
-; RV64ZBKB-NEXT: srli a0, a0, 48
-; RV64ZBKB-NEXT: slliw a1, a1, 16
-; RV64ZBKB-NEXT: or a0, a1, a0
+; RV64ZBKB-NEXT: packw a0, a0, a1
; RV64ZBKB-NEXT: ret
%shl = and i32 %a, 65535
%shl1 = shl i32 %b, 16
@@ -35,8 +32,7 @@ define signext i32 @pack_i32_2(i16 zeroext %a, i16 zeroext %b) nounwind {
;
; RV64ZBKB-LABEL: pack_i32_2:
; RV64ZBKB: # %bb.0:
-; RV64ZBKB-NEXT: slliw a1, a1, 16
-; RV64ZBKB-NEXT: or a0, a1, a0
+; RV64ZBKB-NEXT: packw a0, a0, a1
; RV64ZBKB-NEXT: ret
%zexta = zext i16 %a to i32
%zextb = zext i16 %b to i32
@@ -56,8 +52,7 @@ define signext i32 @pack_i32_3(i16 zeroext %0, i16 zeroext %1, i32 signext %2) {
;
; RV64ZBKB-LABEL: pack_i32_3:
; RV64ZBKB: # %bb.0:
-; RV64ZBKB-NEXT: slli a0, a0, 16
-; RV64ZBKB-NEXT: or a0, a0, a1
+; RV64ZBKB-NEXT: packw a0, a1, a0
; RV64ZBKB-NEXT: addw a0, a0, a2
; RV64ZBKB-NEXT: ret
%4 = zext i16 %0 to i32
@@ -142,10 +137,7 @@ define signext i32 @packh_i32(i32 signext %a, i32 signext %b) nounwind {
;
; RV64ZBKB-LABEL: packh_i32:
; RV64ZBKB: # %bb.0:
-; RV64ZBKB-NEXT: andi a0, a0, 255
-; RV64ZBKB-NEXT: slli a1, a1, 56
-; RV64ZBKB-NEXT: srli a1, a1, 48
-; RV64ZBKB-NEXT: or a0, a1, a0
+; RV64ZBKB-NEXT: packh a0, a0, a1
; RV64ZBKB-NEXT: ret
%and = and i32 %a, 255
%and1 = shl i32 %b, 8
@@ -165,10 +157,7 @@ define i32 @packh_i32_2(i32 %a, i32 %b) nounwind {
;
; RV64ZBKB-LABEL: packh_i32_2:
; RV64ZBKB: # %bb.0:
-; RV64ZBKB-NEXT: andi a0, a0, 255
-; RV64ZBKB-NEXT: andi a1, a1, 255
-; RV64ZBKB-NEXT: slliw a1, a1, 8
-; RV64ZBKB-NEXT: or a0, a1, a0
+; RV64ZBKB-NEXT: packh a0, a0, a1
; RV64ZBKB-NEXT: ret
%and = and i32 %a, 255
%and1 = and i32 %b, 255
@@ -228,8 +217,7 @@ define zeroext i16 @packh_i16(i8 zeroext %a, i8 zeroext %b) nounwind {
;
; RV64ZBKB-LABEL: packh_i16:
; RV64ZBKB: # %bb.0:
-; RV64ZBKB-NEXT: slli a1, a1, 8
-; RV64ZBKB-NEXT: or a0, a1, a0
+; RV64ZBKB-NEXT: packh a0, a0, a1
; RV64ZBKB-NEXT: slli a0, a0, 32
; RV64ZBKB-NEXT: srli a0, a0, 32
; RV64ZBKB-NEXT: ret
@@ -300,8 +288,7 @@ define signext i32 @pack_i32_allWUsers(i16 zeroext %0, i16 zeroext %1, i16 zeroe
; RV64ZBKB-LABEL: pack_i32_allWUsers:
; RV64ZBKB: # %bb.0:
; RV64ZBKB-NEXT: add a0, a1, a0
-; RV64ZBKB-NEXT: slliw a0, a0, 16
-; RV64ZBKB-NEXT: or a0, a0, a2
+; RV64ZBKB-NEXT: packw a0, a2, a0
; RV64ZBKB-NEXT: ret
%4 = add i16 %1, %0
%5 = zext i16 %4 to i32
More information about the llvm-commits
mailing list