[llvm] 65fb80b - [GlobalIsel] Add Gallery to MIR Patterns (#89974)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 25 22:06:52 PDT 2024


Author: Thorsten Schütt
Date: 2024-04-26T07:06:49+02:00
New Revision: 65fb80beaee235b76023fae3277694c56a1b7d99

URL: https://github.com/llvm/llvm-project/commit/65fb80beaee235b76023fae3277694c56a1b7d99
DIFF: https://github.com/llvm/llvm-project/commit/65fb80beaee235b76023fae3277694c56a1b7d99.diff

LOG: [GlobalIsel]  Add Gallery to MIR Patterns (#89974)

examples for fold of zext(trunc:nuw)

Added: 
    

Modified: 
    llvm/docs/GlobalISel/MIRPatterns.rst

Removed: 
    


################################################################################
diff  --git a/llvm/docs/GlobalISel/MIRPatterns.rst b/llvm/docs/GlobalISel/MIRPatterns.rst
index 728e3247014452..d7dce1b978cd21 100644
--- a/llvm/docs/GlobalISel/MIRPatterns.rst
+++ b/llvm/docs/GlobalISel/MIRPatterns.rst
@@ -514,3 +514,40 @@ of operands.
     (match (does_not_bind $tmp, $x)
            (G_MUL $dst, $x, $tmp)),
     (apply (COPY $dst, $x))>;
+
+
+
+
+Gallery
+=======
+
+We should use precise patterns that state our intentions. Please avoid
+using wip_match_opcode in patterns.
+
+.. code-block:: text
+  :caption: Example fold zext(trunc:nuw)
+
+  // Imprecise: matches any G_ZEXT
+  def zext : GICombineRule<
+    (defs root:$root),
+    (match (wip_match_opcode G_ZEXT):$root,
+    [{ return Helper.matchZextOfTrunc(*${root}, ${matchinfo}); }]),
+    (apply [{ Helper.applyBuildFn(*${root}, ${matchinfo}); }])>;
+
+
+  // Imprecise: matches G_ZEXT of G_TRUNC
+  def zext_of_trunc : GICombineRule<
+    (defs root:$root),
+    (match (G_TRUNC $src, $x),
+           (G_ZEXT $root, $src),
+    [{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
+    (apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;
+
+
+  // Precise: matches G_ZEXT of G_TRUNC with nuw flag
+  def zext_of_trunc_nuw : GICombineRule<
+    (defs root:$root),
+    (match (G_TRUNC $src, $x, (MIFlags NoUWrap)),
+           (G_ZEXT $root, $src),
+    [{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
+    (apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;


        


More information about the llvm-commits mailing list