[PATCH] D97262: [RISCV] Add isel pattern to match X > -1 to bgez.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 23 00:39:29 PST 2021


craig.topper updated this revision to Diff 325698.
craig.topper added a comment.

Remove an unnecessary 'the' from comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97262/new/

https://reviews.llvm.org/D97262

Files:
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/test/CodeGen/RISCV/branch.ll


Index: llvm/test/CodeGen/RISCV/branch.ll
===================================================================
--- llvm/test/CodeGen/RISCV/branch.ll
+++ llvm/test/CodeGen/RISCV/branch.ll
@@ -40,8 +40,7 @@
 ; RV32I-NEXT:    bnez a0, .LBB0_13
 ; RV32I-NEXT:  # %bb.11: # %test12
 ; RV32I-NEXT:    lw a0, 0(a1)
-; RV32I-NEXT:    addi a2, zero, -1
-; RV32I-NEXT:    blt a2, a0, .LBB0_13
+; RV32I-NEXT:    bgez a0, .LBB0_13
 ; RV32I-NEXT:  # %bb.12: # %test13
 ; RV32I-NEXT:    lw a0, 0(a1)
 ; RV32I-NEXT:  .LBB0_13: # %end
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.td
===================================================================
--- llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -992,6 +992,10 @@
 def : Pat<(brcond (XLenVT (xor GPR:$cond, 1)), bb:$imm12),
           (BEQ GPR:$cond, X0, bb:$imm12)>;
 
+// Match X > -1, the canonical form of X >= 0, to the bgez pattern.
+def : Pat<(brcond (XLenVT (setgt GPR:$rs1, -1)), bb:$imm12),
+          (BGE GPR:$rs1, X0, bb:$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: D97262.325698.patch
Type: text/x-patch
Size: 1228 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210223/bf6379b3/attachment.bin>


More information about the llvm-commits mailing list