Skip to content

Commit 65fb80b

Browse files
authored
[GlobalIsel] Add Gallery to MIR Patterns (llvm#89974)
examples for fold of zext(trunc:nuw)
1 parent 4b25508 commit 65fb80b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

llvm/docs/GlobalISel/MIRPatterns.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,3 +514,40 @@ of operands.
514514
(match (does_not_bind $tmp, $x)
515515
(G_MUL $dst, $x, $tmp)),
516516
(apply (COPY $dst, $x))>;
517+
518+
519+
520+
521+
Gallery
522+
=======
523+
524+
We should use precise patterns that state our intentions. Please avoid
525+
using wip_match_opcode in patterns.
526+
527+
.. code-block:: text
528+
:caption: Example fold zext(trunc:nuw)
529+
530+
// Imprecise: matches any G_ZEXT
531+
def zext : GICombineRule<
532+
(defs root:$root),
533+
(match (wip_match_opcode G_ZEXT):$root,
534+
[{ return Helper.matchZextOfTrunc(*${root}, ${matchinfo}); }]),
535+
(apply [{ Helper.applyBuildFn(*${root}, ${matchinfo}); }])>;
536+
537+
538+
// Imprecise: matches G_ZEXT of G_TRUNC
539+
def zext_of_trunc : GICombineRule<
540+
(defs root:$root),
541+
(match (G_TRUNC $src, $x),
542+
(G_ZEXT $root, $src),
543+
[{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
544+
(apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;
545+
546+
547+
// Precise: matches G_ZEXT of G_TRUNC with nuw flag
548+
def zext_of_trunc_nuw : GICombineRule<
549+
(defs root:$root),
550+
(match (G_TRUNC $src, $x, (MIFlags NoUWrap)),
551+
(G_ZEXT $root, $src),
552+
[{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
553+
(apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;

0 commit comments

Comments
 (0)