[PATCH] D71335: [ARM][MVE] Factor out an IntrinsicMX multiclass.

Simon Tatham via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 11 02:50:28 PST 2019


simon_tatham created this revision.
simon_tatham added reviewers: MarkMurrayARM, miyuki.
Herald added subscribers: cfe-commits, dmgreen, kristof.beyls.
Herald added a project: clang.

The ACLE intrinsics for MVE contain a lot of pairs of functions with
`_m` and `_x` in the name, wrapping a predicated MVE instruction which
only partially overwrites its output register. They have the common
pattern that the `_m` variant takes an initial argument called
'inactive', of the same type as the return value, supplying the input
value of the output register, so that lanes disabled by the
predication will be taken from that parameter; the `_x` variant omits
that initial argument, and simply sets it to undef.

That common pattern is simple enough to wrap into a multiclass, which
should save a lot of effort in setting up all the rest of the `_x`
variants. In this commit I introduce `multiclass IntrinsicMX` in
`arm_mve_defs.td`, and convert existing generation of m/x pairs to use
it.

In the `PredicatedImmediateVectorShift` multiclass, this has allowed
me to remove an annoying temporary definition of `predIntr`, which I
needed to reuse between the m/x variants, and also to `!con` together
some subsections of its argument list. But now `!con` lets you leave
some operator nodes as `?` (D71195 <https://reviews.llvm.org/D71195>), //and// the m/x variants are
defined together, I can get away with referring to that complicated
expression only once, at the tiny cost of having to change the type of
the `unsignedFlag` multiclass.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71335

Files:
  clang/include/clang/Basic/arm_mve.td
  clang/include/clang/Basic/arm_mve_defs.td


Index: clang/include/clang/Basic/arm_mve_defs.td
===================================================================
--- clang/include/clang/Basic/arm_mve_defs.td
+++ clang/include/clang/Basic/arm_mve_defs.td
@@ -432,6 +432,30 @@
   string basename = basename_;
 }
 
+// A wrapper to define both _m and _x versions of a predicated
+// intrinsic.
+multiclass IntrinsicMX<Type rettype, dag arguments, dag cg,
+                       string nameSuffix = "",
+                       PolymorphicNameType pnt_x = PNT_Type> {
+  // The _m variant takes an initial parameter called $inactive, which
+  // provides the input value of the output register, i.e. all the
+  // inactive lanes in the predicated operation take their values from
+  // this.
+  def "_m" # nameSuffix:
+     Intrinsic<rettype, !con((args rettype:$inactive), arguments), cg>;
+
+  // The _x variant leaves off that parameter, and simply uses an
+  // undef value of the same type.
+  def "_x" # nameSuffix:
+     Intrinsic<rettype, arguments, (seq (undef rettype):$inactive, cg)> {
+    // Allow overriding of the polymorphic name type, because
+    // sometimes the _m and _x variants polymorph differently
+    // (typically because the type of the inactive parameter can be
+    // used as a disambiguator if it's present).
+    let pnt = pnt_x;
+  }
+}
+
 // -----------------------------------------------------------------------------
 // Convenience lists of parameter types. 'T' is just a container record, so you
 // can define a typical intrinsic with 'let Params = T.Usual', or similar,
Index: clang/include/clang/Basic/arm_mve.td
===================================================================
--- clang/include/clang/Basic/arm_mve.td
+++ clang/include/clang/Basic/arm_mve.td
@@ -610,17 +610,10 @@
 defm vstrdq: scatter_offset_both<T.Int64, u64, 3>;
 
 multiclass PredicatedImmediateVectorShift<
-    Immediate immtype, string predIntrName, list<dag> unsignedFlag = []> {
-  foreach predIntr = [IRInt<predIntrName, [Vector, Predicate]>] in {
-    def _m_n: Intrinsic<Vector, (args Vector:$inactive, Vector:$v,
-                                      immtype:$sh, Predicate:$pred),
-       !con((predIntr $v, $sh), !dag(predIntr, unsignedFlag, ?),
-            (predIntr $pred, $inactive))>;
-    def _x_n: Intrinsic<Vector, (args Vector:$v, immtype:$sh,
-                                      Predicate:$pred),
-       !con((predIntr $v, $sh), !dag(predIntr, unsignedFlag, ?),
-            (predIntr $pred, (undef Vector)))>;
-  }
+    Immediate immtype, string predIntrName, dag unsignedFlag = (?)> {
+  defm "": IntrinsicMX<Vector, (args Vector:$v, immtype:$sh, Predicate:$pred),
+     !con((IRInt<predIntrName, [Vector, Predicate]> $v, $sh),
+          unsignedFlag, (? $pred, $inactive)), "_n">;
 }
 
 let params = T.Int in {
@@ -632,7 +625,7 @@
     def vshrq_n: Intrinsic<Vector, (args Vector:$v, imm_1toN:$sh),
                             (immshr $v, $sh, (unsignedflag Scalar))>;
     defm vshrq: PredicatedImmediateVectorShift<imm_1toN, "shr_imm_predicated",
-                                     [(unsignedflag Scalar)]>;
+                                     (? (unsignedflag Scalar))>;
   }
 }
 
@@ -713,25 +706,17 @@
 multiclass VectorComplexAddPred<dag not_halving, dag angle> {
   def "" : Intrinsic<Vector, (args Vector:$a, Vector:$b),
      (IRInt<"vcaddq", [Vector]> not_halving, angle, $a, $b)>;
-  def _m : Intrinsic<Vector, (args Vector:$inactive, Vector:$a, Vector:$b,
-                              Predicate:$pred),
+  defm "" : IntrinsicMX<Vector, (args Vector:$a, Vector:$b, Predicate:$pred),
      (IRInt<"vcaddq_predicated", [Vector, Predicate]>
        not_halving, angle, $inactive, $a, $b, $pred)>;
-  def _x : Intrinsic<Vector, (args Vector:$a, Vector:$b, Predicate:$pred),
-     (IRInt<"vcaddq_predicated", [Vector, Predicate]>
-       not_halving, angle, (undef Vector), $a, $b, $pred)>;
 }
 
 multiclass VectorComplexMulPred<dag angle> {
   def "" : Intrinsic<Vector, (args Vector:$a, Vector:$b),
     (IRInt<"vcmulq", [Vector]> angle, $a, $b)>;
-  def _m : Intrinsic<Vector, (args Vector:$inactive, Vector:$a, Vector:$b,
-                              Predicate:$pred),
+  defm "" : IntrinsicMX<Vector, (args Vector:$a, Vector:$b, Predicate:$pred),
     (IRInt<"vcmulq_predicated", [Vector, Predicate]> angle, $inactive, $a, $b,
       $pred)>;
-  def _x : Intrinsic<Vector, (args Vector:$a, Vector:$b, Predicate:$pred),
-    (IRInt<"vcmulq_predicated", [Vector, Predicate]> angle, (undef Vector), $a,
-      $b, $pred)>;
 }
 
 multiclass VectorComplexMLAPred<dag angle> {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71335.233294.patch
Type: text/x-patch
Size: 4591 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191211/17b1fad3/attachment-0001.bin>


More information about the cfe-commits mailing list