[llvm] fdc904e - [RISCV] Add isel pattern to turn (or (zext X), Y) into add.uw when X and Y are disjoint.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 11 15:52:39 PST 2023
Author: Craig Topper
Date: 2023-11-11T15:51:38-08:00
New Revision: fdc904e5681c00f5e347f5889f4dfd4a448ebaf4
URL: https://github.com/llvm/llvm-project/commit/fdc904e5681c00f5e347f5889f4dfd4a448ebaf4
DIFF: https://github.com/llvm/llvm-project/commit/fdc904e5681c00f5e347f5889f4dfd4a448ebaf4.diff
LOG: [RISCV] Add isel pattern to turn (or (zext X), Y) into add.uw when X and Y are disjoint.
Improve code for -riscv-experimental-rv64-legal-i32.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zba.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
index e67fc34a344adb8..05bd5b56d24a777 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
@@ -854,6 +854,9 @@ def : Pat<(i64 (add_non_imm12 (zext GPR:$rs1), GPR:$rs2)),
(ADD_UW GPR:$rs1, GPR:$rs2)>;
def : Pat<(zext GPR:$src), (ADD_UW GPR:$src, (XLenVT X0))>;
+def : Pat<(i64 (or_is_add_non_imm12 (zext GPR:$rs1), GPR:$rs2)),
+ (ADD_UW GPR:$rs1, GPR:$rs2)>;
+
foreach i = {1,2,3} in {
defvar shxadd = !cast<Instruction>("SH"#i#"ADD");
def : Pat<(i32 (add_non_imm12 (shl GPR:$rs1, (i64 i)), GPR:$rs2)),
diff --git a/llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zba.ll b/llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zba.ll
index b29b59a85f01642..c15bc8b10f80200 100644
--- a/llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zba.ll
+++ b/llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zba.ll
@@ -1829,3 +1829,71 @@ define i64 @shl_31_sh3add(ptr %0, i32 signext %1) {
%6 = load i64, ptr %5, align 8
ret i64 %6
}
+
+define i64 @pack_i64(i64 %a, i64 %b) nounwind {
+; RV64I-LABEL: pack_i64:
+; RV64I: # %bb.0:
+; RV64I-NEXT: slli a0, a0, 32
+; RV64I-NEXT: srli a0, a0, 32
+; RV64I-NEXT: slli a1, a1, 32
+; RV64I-NEXT: or a0, a1, a0
+; RV64I-NEXT: ret
+;
+; RV64ZBA-LABEL: pack_i64:
+; RV64ZBA: # %bb.0:
+; RV64ZBA-NEXT: slli a1, a1, 32
+; RV64ZBA-NEXT: add.uw a0, a0, a1
+; RV64ZBA-NEXT: ret
+ %shl = and i64 %a, 4294967295
+ %shl1 = shl i64 %b, 32
+ %or = or i64 %shl1, %shl
+ ret i64 %or
+}
+
+define i64 @pack_i64_2(i32 signext %a, i32 signext %b) nounwind {
+; RV64I-LABEL: pack_i64_2:
+; RV64I: # %bb.0:
+; RV64I-NEXT: slli a0, a0, 32
+; RV64I-NEXT: srli a0, a0, 32
+; RV64I-NEXT: slli a1, a1, 32
+; RV64I-NEXT: or a0, a1, a0
+; RV64I-NEXT: ret
+;
+; RV64ZBA-LABEL: pack_i64_2:
+; RV64ZBA: # %bb.0:
+; RV64ZBA-NEXT: slli a1, a1, 32
+; RV64ZBA-NEXT: add.uw a0, a0, a1
+; RV64ZBA-NEXT: ret
+ %zexta = zext i32 %a to i64
+ %zextb = zext i32 %b to i64
+ %shl1 = shl i64 %zextb, 32
+ %or = or i64 %shl1, %zexta
+ ret i64 %or
+}
+
+define i64 @pack_i64_3(i32 signext %a, i32 signext %b) nounwind {
+; RV64I-LABEL: pack_i64_3:
+; RV64I: # %bb.0:
+; RV64I-NEXT: addi a0, a0, 1
+; RV64I-NEXT: addi a1, a1, 1
+; RV64I-NEXT: slli a0, a0, 32
+; RV64I-NEXT: srli a0, a0, 32
+; RV64I-NEXT: slli a1, a1, 32
+; RV64I-NEXT: or a0, a1, a0
+; RV64I-NEXT: ret
+;
+; RV64ZBA-LABEL: pack_i64_3:
+; RV64ZBA: # %bb.0:
+; RV64ZBA-NEXT: addi a0, a0, 1
+; RV64ZBA-NEXT: addi a1, a1, 1
+; RV64ZBA-NEXT: slli a1, a1, 32
+; RV64ZBA-NEXT: add.uw a0, a0, a1
+; RV64ZBA-NEXT: ret
+ %adda = add i32 %a, 1
+ %addb = add i32 %b, 1
+ %zexta = zext i32 %adda to i64
+ %zextb = zext i32 %addb to i64
+ %shl1 = shl i64 %zextb, 32
+ %or = or i64 %shl1, %zexta
+ ret i64 %or
+}
More information about the llvm-commits
mailing list