[llvm] [GlobalIsel] Add Gallery to MIR Patterns (PR #89974)
Thorsten Schütt via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 25 04:13:42 PDT 2024
https://github.com/tschuett updated https://github.com/llvm/llvm-project/pull/89974
>From ba56f97273a24e3ff2b6244bbf5badd892dbc2c5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorsten=20Sch=C3=BCtt?= <schuett at gmail.com>
Date: Wed, 24 Apr 2024 20:46:27 +0200
Subject: [PATCH 1/6] [GlobalIsel] Add Gallery to MIr Patterns
---
llvm/docs/GlobalISel/MIRPatterns.rst | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/llvm/docs/GlobalISel/MIRPatterns.rst b/llvm/docs/GlobalISel/MIRPatterns.rst
index 728e3247014452..97717005ebd619 100644
--- a/llvm/docs/GlobalISel/MIRPatterns.rst
+++ b/llvm/docs/GlobalISel/MIRPatterns.rst
@@ -514,3 +514,21 @@ 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 ext(trunc)
+
+(match (wip_match_opcode G_ZEXT):$root,
+
+(match (G_TRUNC $src, $x),
+ (G_ZEXT $root, $src),
+
+(match (G_TRUNC $src, $x, (MIFlags NoUWrap)),
+ (G_ZEXT $root, $src),
>From 0e72c2da2e86458d8432bb34a65a535c4cdb5d04 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorsten=20Sch=C3=BCtt?= <schuett at gmail.com>
Date: Thu, 25 Apr 2024 08:41:58 +0200
Subject: [PATCH 2/6] address review comments
---
llvm/docs/GlobalISel/MIRPatterns.rst | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/llvm/docs/GlobalISel/MIRPatterns.rst b/llvm/docs/GlobalISel/MIRPatterns.rst
index 97717005ebd619..023cfc5fc0e279 100644
--- a/llvm/docs/GlobalISel/MIRPatterns.rst
+++ b/llvm/docs/GlobalISel/MIRPatterns.rst
@@ -523,12 +523,20 @@ We should use precise patterns that state our intentions. Please avoid
using wip_match_opcode in patterns.
.. code-block:: text
- :caption: Example fold ext(trunc)
+ :caption: Example fold ext(trunc:nuw)
(match (wip_match_opcode G_ZEXT):$root,
+ [{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
+ (apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;
+
(match (G_TRUNC $src, $x),
- (G_ZEXT $root, $src),
+ (G_ZEXT $root, $src),
+ [{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
+ (apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;
+
(match (G_TRUNC $src, $x, (MIFlags NoUWrap)),
- (G_ZEXT $root, $src),
+ (G_ZEXT $root, $src),
+ [{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
+ (apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;
>From 5f49276d8dec760b1346213a8d68c600ccc04372 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorsten=20Sch=C3=BCtt?= <schuett at gmail.com>
Date: Thu, 25 Apr 2024 08:45:55 +0200
Subject: [PATCH 3/6] whitespace
---
llvm/docs/GlobalISel/MIRPatterns.rst | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/docs/GlobalISel/MIRPatterns.rst b/llvm/docs/GlobalISel/MIRPatterns.rst
index 023cfc5fc0e279..6c7bec512626c6 100644
--- a/llvm/docs/GlobalISel/MIRPatterns.rst
+++ b/llvm/docs/GlobalISel/MIRPatterns.rst
@@ -531,12 +531,12 @@ using wip_match_opcode in patterns.
(match (G_TRUNC $src, $x),
- (G_ZEXT $root, $src),
+ (G_ZEXT $root, $src),
[{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
(apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;
(match (G_TRUNC $src, $x, (MIFlags NoUWrap)),
- (G_ZEXT $root, $src),
+ (G_ZEXT $root, $src),
[{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
(apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;
>From f132e1c7fd51afd5a92f39b000381594aac49cc7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorsten=20Sch=C3=BCtt?= <schuett at gmail.com>
Date: Thu, 25 Apr 2024 12:21:10 +0200
Subject: [PATCH 4/6] add comments
---
llvm/docs/GlobalISel/MIRPatterns.rst | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/llvm/docs/GlobalISel/MIRPatterns.rst b/llvm/docs/GlobalISel/MIRPatterns.rst
index 6c7bec512626c6..5cc29ad5561af3 100644
--- a/llvm/docs/GlobalISel/MIRPatterns.rst
+++ b/llvm/docs/GlobalISel/MIRPatterns.rst
@@ -523,19 +523,22 @@ We should use precise patterns that state our intentions. Please avoid
using wip_match_opcode in patterns.
.. code-block:: text
- :caption: Example fold ext(trunc:nuw)
+ :caption: Example fold zext(trunc:nuw)
+// Imprecise: matches any G_ZEXT
(match (wip_match_opcode G_ZEXT):$root,
[{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
(apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;
+// Imprecise: matches G_ZEXT of G_TRUNC
(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
(match (G_TRUNC $src, $x, (MIFlags NoUWrap)),
(G_ZEXT $root, $src),
[{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
>From 66208ecaa30f02761009514b9cdf840e22512d12 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorsten=20Sch=C3=BCtt?= <schuett at gmail.com>
Date: Thu, 25 Apr 2024 13:07:45 +0200
Subject: [PATCH 5/6] fix sphinx
---
llvm/docs/GlobalISel/MIRPatterns.rst | 40 +++++++++++++++++-----------
1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/llvm/docs/GlobalISel/MIRPatterns.rst b/llvm/docs/GlobalISel/MIRPatterns.rst
index 5cc29ad5561af3..3b06d14e38093e 100644
--- a/llvm/docs/GlobalISel/MIRPatterns.rst
+++ b/llvm/docs/GlobalISel/MIRPatterns.rst
@@ -516,8 +516,10 @@ of operands.
(apply (COPY $dst, $x))>;
- Gallery
-----------------
+
+
+Gallery
+=======
We should use precise patterns that state our intentions. Please avoid
using wip_match_opcode in patterns.
@@ -525,21 +527,27 @@ using wip_match_opcode in patterns.
.. code-block:: text
:caption: Example fold zext(trunc:nuw)
-// Imprecise: matches any G_ZEXT
-(match (wip_match_opcode G_ZEXT):$root,
- [{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
- (apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;
+ // Imprecise: matches any G_ZEXT
+ def zext : GICombineRule<
+ (defs root:$dst),
+ (match (wip_match_opcode G_ZEXT):$root,
+ [{ return Helper.matchZextOfTrunc(*${root}, ${matchinfo}); }]),
+ (apply [{ Helper.applyBuildFn(*${root}, ${matchinfo}); }])>;
-// Imprecise: matches G_ZEXT of G_TRUNC
-(match (G_TRUNC $src, $x),
- (G_ZEXT $root, $src),
- [{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
- (apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;
+ // Imprecise: matches G_ZEXT of G_TRUNC
+ def zext_of_trunc : GICombineRule<
+ (defs root:$dst),
+ (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
-(match (G_TRUNC $src, $x, (MIFlags NoUWrap)),
- (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:$dst),
+ (match (G_TRUNC $src, $x, (MIFlags NoUWrap)),
+ (G_ZEXT $root, $src),
+ [{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
+ (apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;
>From c6f5234173f2721686b48e4b1d2f1c9ba8db8bbe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorsten=20Sch=C3=BCtt?= <schuett at gmail.com>
Date: Thu, 25 Apr 2024 13:13:06 +0200
Subject: [PATCH 6/6] fix typos
---
llvm/docs/GlobalISel/MIRPatterns.rst | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/docs/GlobalISel/MIRPatterns.rst b/llvm/docs/GlobalISel/MIRPatterns.rst
index 3b06d14e38093e..d7dce1b978cd21 100644
--- a/llvm/docs/GlobalISel/MIRPatterns.rst
+++ b/llvm/docs/GlobalISel/MIRPatterns.rst
@@ -529,7 +529,7 @@ using wip_match_opcode in patterns.
// Imprecise: matches any G_ZEXT
def zext : GICombineRule<
- (defs root:$dst),
+ (defs root:$root),
(match (wip_match_opcode G_ZEXT):$root,
[{ return Helper.matchZextOfTrunc(*${root}, ${matchinfo}); }]),
(apply [{ Helper.applyBuildFn(*${root}, ${matchinfo}); }])>;
@@ -537,7 +537,7 @@ using wip_match_opcode in patterns.
// Imprecise: matches G_ZEXT of G_TRUNC
def zext_of_trunc : GICombineRule<
- (defs root:$dst),
+ (defs root:$root),
(match (G_TRUNC $src, $x),
(G_ZEXT $root, $src),
[{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
@@ -546,7 +546,7 @@ using wip_match_opcode in patterns.
// Precise: matches G_ZEXT of G_TRUNC with nuw flag
def zext_of_trunc_nuw : GICombineRule<
- (defs root:$dst),
+ (defs root:$root),
(match (G_TRUNC $src, $x, (MIFlags NoUWrap)),
(G_ZEXT $root, $src),
[{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
More information about the llvm-commits
mailing list