[PATCH] D98449: [RISCV] Add isel-patterns to optimize (a < 1) and (a > -1) into bge

Philipp Tomsich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 11 12:43:28 PST 2021


philipp.tomsich created this revision.
philipp.tomsich added a reviewer: craig.topper.
philipp.tomsich added a project: LLVM.
Herald added subscribers: 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.
philipp.tomsich requested review of this revision.
Herald added a subscriber: MaskRay.

  The following code-sequence showed up in a testcase (isolated from
  SPEC2017) for if-conversion and vectorization when searching for the
  maximum in an array:
          addi    a2, zero, 1
          blt     a1, a2, .LBB0_5
  which can be expressed as `bge zero,a1,.LBB0_5`.
  
  More generally, we want to express
   - (a > -1) as (a >= 0)
   - (a < 1) as (0 >= a)
  
  This adds the required isel-patterns.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98449

Files:
  llvm/lib/Target/RISCV/RISCVInstrInfo.td


Index: llvm/lib/Target/RISCV/RISCVInstrInfo.td
===================================================================
--- llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -998,6 +998,12 @@
 def : Pat<(brcond (XLenVT (xor GPR:$cond, 1)), bb:$imm12),
           (BEQ GPR:$cond, X0, bb:$imm12)>;
 
+// Lower (a > -1) to (a >= 0) and (a < 1) to (0 >= a).
+def : Pat<(brcond (XLenVT (setlt XLenVT:$lhs, 1)), bb:$dst),
+	  (BGE X0, XLenVT:$lhs, bb:$dst)>;
+def : Pat<(brcond (XLenVT (setgt XLenVT:$lhs, -1)), bb:$dst),
+	  (BGE XLenVT:$lhs, X0, bb:$dst)>;
+
 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: D98449.330056.patch
Type: text/x-patch
Size: 792 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210311/25efc905/attachment.bin>


More information about the llvm-commits mailing list