[PATCH] D59753: [RISCV] Improve codegen of GPR == simm12
Luís Marques via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 24 15:04:39 PDT 2019
luismarques created this revision.
luismarques added reviewers: asb, apazos, rogfer01.
Herald added subscribers: llvm-commits, benna, psnobl, jdoerfert, jocewei, PkmX, rkruppe, the_o, brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar.
Herald added a project: LLVM.
Adds two patterns to improve the codegen of GPR value comparisons with small
constants. Instead of first loading the constant into another register and then
doing an XOR of those registers, these patterns directly use the constant as an
XORI immediate.
Repository:
rL LLVM
https://reviews.llvm.org/D59753
Files:
lib/Target/RISCV/RISCVInstrInfo.td
test/CodeGen/RISCV/i32-icmp.ll
Index: test/CodeGen/RISCV/i32-icmp.ll
===================================================================
--- test/CodeGen/RISCV/i32-icmp.ll
+++ test/CodeGen/RISCV/i32-icmp.ll
@@ -16,6 +16,17 @@
ret i32 %2
}
+define i32 @icmp_eq_constant(i32 %a) nounwind {
+; RV32I-LABEL: icmp_eq_constant:
+; RV32I: # %bb.0:
+; RV32I-NEXT: xori a0, a0, 42
+; RV32I-NEXT: seqz a0, a0
+; RV32I-NEXT: ret
+ %1 = icmp eq i32 %a, 42
+ %2 = zext i1 %1 to i32
+ ret i32 %2
+}
+
define i32 @icmp_eqz(i32 %a) nounwind {
; RV32I-LABEL: icmp_eqz:
; RV32I: # %bb.0:
@@ -37,6 +48,17 @@
ret i32 %2
}
+define i32 @icmp_ne_constant(i32 %a) nounwind {
+; RV32I-LABEL: icmp_ne_constant:
+; RV32I: # %bb.0:
+; RV32I-NEXT: xori a0, a0, 42
+; RV32I-NEXT: snez a0, a0
+; RV32I-NEXT: ret
+ %1 = icmp ne i32 %a, 42
+ %2 = zext i1 %1 to i32
+ ret i32 %2
+}
+
define i32 @icmp_nez(i32 %a) nounwind {
; RV32I-LABEL: icmp_nez:
; RV32I: # %bb.0:
Index: lib/Target/RISCV/RISCVInstrInfo.td
===================================================================
--- lib/Target/RISCV/RISCVInstrInfo.td
+++ lib/Target/RISCV/RISCVInstrInfo.td
@@ -771,8 +771,12 @@
// handled by a RISC-V instruction.
def : Pat<(seteq GPR:$rs1, 0), (SLTIU GPR:$rs1, 1)>;
def : Pat<(seteq GPR:$rs1, GPR:$rs2), (SLTIU (XOR GPR:$rs1, GPR:$rs2), 1)>;
+def : Pat<(seteq GPR:$rs1, simm12:$imm12),
+ (SLTIU (XORI GPR:$rs1, simm12:$imm12), 1)>;
def : Pat<(setne GPR:$rs1, 0), (SLTU X0, GPR:$rs1)>;
def : Pat<(setne GPR:$rs1, GPR:$rs2), (SLTU X0, (XOR GPR:$rs1, GPR:$rs2))>;
+def : Pat<(setne GPR:$rs1, simm12:$imm12),
+ (SLTU X0, (XORI GPR:$rs1, simm12:$imm12))>;
def : Pat<(setugt GPR:$rs1, GPR:$rs2), (SLTU GPR:$rs2, GPR:$rs1)>;
def : Pat<(setuge GPR:$rs1, GPR:$rs2), (XORI (SLTU GPR:$rs1, GPR:$rs2), 1)>;
def : Pat<(setule GPR:$rs1, GPR:$rs2), (XORI (SLTU GPR:$rs2, GPR:$rs1), 1)>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59753.192046.patch
Type: text/x-patch
Size: 1898 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190324/d02e8a53/attachment.bin>
More information about the llvm-commits
mailing list