[llvm] a590760 - [RISCV] Add isel patterns for using PACK for zext.h and zext.w.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 9 10:14:23 PST 2020
Author: Craig Topper
Date: 2020-11-09T10:13:45-08:00
New Revision: a59076006ba5b12acd1c602bfb67d4a92e17290c
URL: https://github.com/llvm/llvm-project/commit/a59076006ba5b12acd1c602bfb67d4a92e17290c
DIFF: https://github.com/llvm/llvm-project/commit/a59076006ba5b12acd1c602bfb67d4a92e17290c.diff
LOG: [RISCV] Add isel patterns for using PACK for zext.h and zext.w.
Differential Revision: https://reviews.llvm.org/D91024
Added:
Modified:
llvm/lib/Target/RISCV/RISCV.td
llvm/lib/Target/RISCV/RISCVInstrInfo.td
llvm/lib/Target/RISCV/RISCVInstrInfoB.td
llvm/test/CodeGen/RISCV/rv32Zbbp.ll
llvm/test/CodeGen/RISCV/rv64Zbbp.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCV.td b/llvm/lib/Target/RISCV/RISCV.td
index 3d942815f20b..2ab8ba8fe704 100644
--- a/llvm/lib/Target/RISCV/RISCV.td
+++ b/llvm/lib/Target/RISCV/RISCV.td
@@ -116,6 +116,8 @@ def HasStdExtZbt : Predicate<"Subtarget->hasStdExtZbt()">,
def HasStdExtZbbOrZbp
: Predicate<"Subtarget->hasStdExtZbb() || Subtarget->hasStdExtZbp()">,
AssemblerPredicate<(any_of FeatureExtZbb, FeatureExtZbp)>;
+def NotHasStdExtZbbOrZbp
+ : Predicate<"!(Subtarget->hasStdExtZbb() || Subtarget->hasStdExtZbp())">;
def FeatureExtZbproposedc
: SubtargetFeature<"experimental-zbproposedc", "HasStdExtZbproposedc", "true",
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
index dde1a15cef2f..1db80e7407bc 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -1120,12 +1120,14 @@ def ADJCALLSTACKUP : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
/// RV64 patterns
+let Predicates = [IsRV64, NotHasStdExtZbbOrZbp] in
+def : Pat<(and GPR:$rs1, 0xffffffff), (SRLI (SLLI GPR:$rs1, 32), 32)>;
+
let Predicates = [IsRV64] in {
/// sext and zext
def : Pat<(sext_inreg GPR:$rs1, i32), (ADDIW GPR:$rs1, 0)>;
-def : Pat<(and GPR:$rs1, 0xffffffff), (SRLI (SLLI GPR:$rs1, 32), 32)>;
/// ALU operations
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoB.td b/llvm/lib/Target/RISCV/RISCVInstrInfoB.td
index 009d8cbca76e..c57ba326088d 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoB.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoB.td
@@ -862,6 +862,13 @@ def : Pat<(or (and (shl GPR:$rs2, (XLenVT 8)), 0xFF00),
(and GPR:$rs1, 0x00FF)),
(PACKH GPR:$rs1, GPR:$rs2)>;
+let Predicates = [HasStdExtZbbOrZbp, IsRV32] in
+def : Pat<(and GPR:$rs, 0x0000FFFF), (PACK GPR:$rs, X0)>;
+let Predicates = [HasStdExtZbbOrZbp, IsRV64] in {
+def : Pat<(and GPR:$rs, 0x000000000000FFFF), (PACKW GPR:$rs, X0)>;
+def : Pat<(and GPR:$rs, 0x00000000FFFFFFFF), (PACK GPR:$rs, X0)>;
+}
+
let Predicates = [HasStdExtZbp, IsRV32] in {
def : Pat<(or (or (and (shl GPR:$rs1, (i32 8)), (i32 0x00FF0000)),
(and GPR:$rs1, (i32 0xFF0000FF))),
diff --git a/llvm/test/CodeGen/RISCV/rv32Zbbp.ll b/llvm/test/CodeGen/RISCV/rv32Zbbp.ll
index ab75431e151e..0ae6d757287f 100644
--- a/llvm/test/CodeGen/RISCV/rv32Zbbp.ll
+++ b/llvm/test/CodeGen/RISCV/rv32Zbbp.ll
@@ -959,3 +959,59 @@ define i64 @packh_i64(i64 %a, i64 %b) nounwind {
%or = or i64 %shl, %and
ret i64 %or
}
+
+define i32 @zexth_i32(i32 %a) nounwind {
+; RV32I-LABEL: zexth_i32:
+; RV32I: # %bb.0:
+; RV32I-NEXT: lui a1, 16
+; RV32I-NEXT: addi a1, a1, -1
+; RV32I-NEXT: and a0, a0, a1
+; RV32I-NEXT: ret
+;
+; RV32IB-LABEL: zexth_i32:
+; RV32IB: # %bb.0:
+; RV32IB-NEXT: zext.h a0, a0
+; RV32IB-NEXT: ret
+;
+; RV32IBB-LABEL: zexth_i32:
+; RV32IBB: # %bb.0:
+; RV32IBB-NEXT: zext.h a0, a0
+; RV32IBB-NEXT: ret
+;
+; RV32IBP-LABEL: zexth_i32:
+; RV32IBP: # %bb.0:
+; RV32IBP-NEXT: pack a0, a0, zero
+; RV32IBP-NEXT: ret
+ %and = and i32 %a, 65535
+ ret i32 %and
+}
+
+define i64 @zexth_i64(i64 %a) nounwind {
+; RV32I-LABEL: zexth_i64:
+; RV32I: # %bb.0:
+; RV32I-NEXT: lui a1, 16
+; RV32I-NEXT: addi a1, a1, -1
+; RV32I-NEXT: and a0, a0, a1
+; RV32I-NEXT: mv a1, zero
+; RV32I-NEXT: ret
+;
+; RV32IB-LABEL: zexth_i64:
+; RV32IB: # %bb.0:
+; RV32IB-NEXT: zext.h a0, a0
+; RV32IB-NEXT: mv a1, zero
+; RV32IB-NEXT: ret
+;
+; RV32IBB-LABEL: zexth_i64:
+; RV32IBB: # %bb.0:
+; RV32IBB-NEXT: zext.h a0, a0
+; RV32IBB-NEXT: mv a1, zero
+; RV32IBB-NEXT: ret
+;
+; RV32IBP-LABEL: zexth_i64:
+; RV32IBP: # %bb.0:
+; RV32IBP-NEXT: pack a0, a0, zero
+; RV32IBP-NEXT: mv a1, zero
+; RV32IBP-NEXT: ret
+ %and = and i64 %a, 65535
+ ret i64 %and
+}
diff --git a/llvm/test/CodeGen/RISCV/rv64Zbbp.ll b/llvm/test/CodeGen/RISCV/rv64Zbbp.ll
index a2a5458597a1..c45569f0a719 100644
--- a/llvm/test/CodeGen/RISCV/rv64Zbbp.ll
+++ b/llvm/test/CodeGen/RISCV/rv64Zbbp.ll
@@ -662,3 +662,28 @@ define i64 @packh_i64(i64 %a, i64 %b) nounwind {
%or = or i64 %shl, %and
ret i64 %or
}
+
+define i64 @zextw_i64(i64 %a) nounwind {
+; RV64I-LABEL: zextw_i64:
+; RV64I: # %bb.0:
+; RV64I-NEXT: slli a0, a0, 32
+; RV64I-NEXT: srli a0, a0, 32
+; RV64I-NEXT: ret
+;
+; RV64IB-LABEL: zextw_i64:
+; RV64IB: # %bb.0:
+; RV64IB-NEXT: zext.w a0, a0
+; RV64IB-NEXT: ret
+;
+; RV64IBB-LABEL: zextw_i64:
+; RV64IBB: # %bb.0:
+; RV64IBB-NEXT: zext.w a0, a0
+; RV64IBB-NEXT: ret
+;
+; RV64IBP-LABEL: zextw_i64:
+; RV64IBP: # %bb.0:
+; RV64IBP-NEXT: pack a0, a0, zero
+; RV64IBP-NEXT: ret
+ %and = and i64 %a, 4294967295
+ ret i64 %and
+}
More information about the llvm-commits
mailing list