[PATCH] D132358: [RISCV][ISel] improved compressed instruction use
Dmitry via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 22 02:09:53 PDT 2022
dybv-sc created this revision.
Herald added subscribers: sunshaoce, VincentWu, luke957, vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, arichardson.
Herald added a project: All.
dybv-sc requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.
Helping to emit compressed BNEZ in comparasion with constant when possible.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D132358
Files:
llvm/lib/Target/RISCV/RISCVInstrInfo.td
llvm/test/CodeGen/RISCV/codemodel-lowering.ll
llvm/test/CodeGen/RISCV/isel-compressed-comp.ll
Index: llvm/test/CodeGen/RISCV/isel-compressed-comp.ll
===================================================================
--- llvm/test/CodeGen/RISCV/isel-compressed-comp.ll
+++ llvm/test/CodeGen/RISCV/isel-compressed-comp.ll
@@ -1,13 +1,11 @@
-; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
-; RUN: | FileCheck %s
; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
; RUN: | FileCheck %s
declare void @foo()
define void @bar(i64 %a) {
-; CHECK-NOT: slti
-; CHECK-NOT: bnez
+; CHECK: slti
+; CHECK-NEXT: bnez
%c = icmp slt i64 255, %a
br i1 %c, label %taken, label %return
taken:
Index: llvm/test/CodeGen/RISCV/codemodel-lowering.ll
===================================================================
--- llvm/test/CodeGen/RISCV/codemodel-lowering.ll
+++ llvm/test/CodeGen/RISCV/codemodel-lowering.ll
@@ -58,9 +58,9 @@
; RV32I-SMALL-NEXT: addi sp, sp, -16
; RV32I-SMALL-NEXT: lui a1, %hi(.Ltmp0)
; RV32I-SMALL-NEXT: addi a1, a1, %lo(.Ltmp0)
-; RV32I-SMALL-NEXT: li a2, 101
+; RV32I-SMALL-NEXT: slti a0, a0, 101
; RV32I-SMALL-NEXT: sw a1, 8(sp)
-; RV32I-SMALL-NEXT: blt a0, a2, .LBB2_3
+; RV32I-SMALL-NEXT: bnez a0, .LBB2_3
; RV32I-SMALL-NEXT: # %bb.1: # %if.then
; RV32I-SMALL-NEXT: lw a0, 8(sp)
; RV32I-SMALL-NEXT: jr a0
@@ -80,9 +80,9 @@
; RV32I-MEDIUM-NEXT: .Lpcrel_hi2:
; RV32I-MEDIUM-NEXT: auipc a1, %pcrel_hi(.Ltmp0)
; RV32I-MEDIUM-NEXT: addi a1, a1, %pcrel_lo(.Lpcrel_hi2)
-; RV32I-MEDIUM-NEXT: li a2, 101
+; RV32I-MEDIUM-NEXT: slti a0, a0, 101
; RV32I-MEDIUM-NEXT: sw a1, 8(sp)
-; RV32I-MEDIUM-NEXT: blt a0, a2, .LBB2_3
+; RV32I-MEDIUM-NEXT: bnez a0, .LBB2_3
; RV32I-MEDIUM-NEXT: # %bb.1: # %if.then
; RV32I-MEDIUM-NEXT: lw a0, 8(sp)
; RV32I-MEDIUM-NEXT: jr a0
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.td
===================================================================
--- llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -1329,6 +1329,10 @@
defm : BccPat<SETULT, BLTU>;
defm : BccPat<SETUGE, BGEU>;
+// Try to produce compressed bnez instruction if possible
+def : Pat<(riscv_brcc GPR:$rs1, simm12:$c, SETLT, bb:$imm12),
+ (BNE (SLTI GPR:$rs1, simm12:$c), X0, simm13_lsb0:$imm12)>;
+
let isBarrier = 1, isBranch = 1, isTerminator = 1 in
def PseudoBR : Pseudo<(outs), (ins simm21_lsb0_jal:$imm20), [(br bb:$imm20)]>,
PseudoInstExpansion<(JAL X0, simm21_lsb0_jal:$imm20)>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132358.454422.patch
Type: text/x-patch
Size: 2470 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220822/b3742edb/attachment.bin>
More information about the llvm-commits
mailing list