[PATCH] D116749: [AArch64][SVE] Fold predicate into compare

Cullen Rhodes via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 6 08:12:25 PST 2022


c-rhodes created this revision.
c-rhodes added reviewers: sdesmalen, paulwalker-arm, david-arm.
Herald added subscribers: psnobl, hiraditya, kristof.beyls, tschuett.
Herald added a reviewer: efriedma.
c-rhodes requested review of this revision.
Herald added a project: LLVM.

Codegen of added testcase before this patch:

  ptrue   p0.s
  cmpgt   p1.s, p0/z, z0.s, z1.s
  cmpge   p2.s, p0/z, z2.s, z1.s
  and     p0.b, p0/z, p1.b, p2.b
  ret

Patterns originally authored by Will Lovett.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116749

Files:
  llvm/lib/Target/AArch64/SVEInstrFormats.td
  llvm/test/CodeGen/AArch64/sve-intrinsics-int-compares.ll


Index: llvm/test/CodeGen/AArch64/sve-intrinsics-int-compares.ll
===================================================================
--- llvm/test/CodeGen/AArch64/sve-intrinsics-int-compares.ll
+++ llvm/test/CodeGen/AArch64/sve-intrinsics-int-compares.ll
@@ -963,6 +963,19 @@
   ret <vscale x 4 x i1> %out
 }
 
+; Verify general predicate is folded into the compare
+define <vscale x 4 x i1> @predicated_icmp(<vscale x 4 x i32> %a, <vscale x 4 x i32> %b, <vscale x 4 x i32> %c) {
+; CHECK-LABEL: predicated_icmp:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    ptrue p0.s
+; CHECK-NEXT:    cmpgt p0.s, p0/z, z0.s, z1.s
+; CHECK-NEXT:    cmpge p0.s, p0/z, z2.s, z1.s
+; CHECK-NEXT:    ret
+  %icmp1 = icmp sgt <vscale x 4 x i32> %a, %b
+  %icmp2 = icmp sle <vscale x 4 x i32> %b, %c
+  %and = and <vscale x 4 x i1> %icmp1, %icmp2
+  ret <vscale x 4 x i1> %and
+}
 
 declare <vscale x 16 x i1> @llvm.aarch64.sve.cmpeq.nxv16i8(<vscale x 16 x i1>, <vscale x 16 x i8>, <vscale x 16 x i8>)
 declare <vscale x 8 x i1> @llvm.aarch64.sve.cmpeq.nxv8i16(<vscale x 8 x i1>, <vscale x 8 x i16>, <vscale x 8 x i16>)
Index: llvm/lib/Target/AArch64/SVEInstrFormats.td
===================================================================
--- llvm/lib/Target/AArch64/SVEInstrFormats.td
+++ llvm/lib/Target/AArch64/SVEInstrFormats.td
@@ -4641,6 +4641,10 @@
             (cmp $Op1, $Op2, $Op3)>;
   def : Pat<(predvt (AArch64setcc_z predvt:$Op1, intvt:$Op2, intvt:$Op3, invcc)),
             (cmp $Op1, $Op3, $Op2)>;
+  def : Pat<(predvt (and predvt:$Pg, (AArch64setcc_z (predvt (AArch64ptrue 31)), intvt:$Op2, intvt:$Op3, cc))),
+            (cmp $Pg, $Op2, $Op3)>;
+  def : Pat<(predvt (and predvt:$Pg, (AArch64setcc_z (predvt (AArch64ptrue 31)), intvt:$Op2, intvt:$Op3, invcc))),
+            (cmp $Pg, $Op3, $Op2)>;
 }
 
 multiclass SVE_SETCC_Pat_With_Zero<CondCode cc, CondCode invcc, ValueType predvt,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116749.397896.patch
Type: text/x-patch
Size: 1882 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220106/93f6b360/attachment.bin>


More information about the llvm-commits mailing list