[llvm] [GlobalIsel] Update MIR gallery (PR #107903)
Thorsten Schütt via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 9 12:53:56 PDT 2024
https://github.com/tschuett updated https://github.com/llvm/llvm-project/pull/107903
>From edaf6a2a98f691b03241d5dca17483fc927d1c1e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorsten=20Sch=C3=BCtt?= <schuett at gmail.com>
Date: Mon, 9 Sep 2024 20:57:10 +0200
Subject: [PATCH 1/2] [GlobalIsel] Update MIR gallery
add more patterns
clarify wip_match_opcode usage
---
llvm/docs/GlobalISel/MIRPatterns.rst | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/llvm/docs/GlobalISel/MIRPatterns.rst b/llvm/docs/GlobalISel/MIRPatterns.rst
index 654a60730bb9c5..f36ffb889f813d 100644
--- a/llvm/docs/GlobalISel/MIRPatterns.rst
+++ b/llvm/docs/GlobalISel/MIRPatterns.rst
@@ -601,7 +601,7 @@ Gallery
=======
We should use precise patterns that state our intentions. Please avoid
-using wip_match_opcode in patterns.
+using wip_match_opcode in patterns. It can lead to imprecise patterns.
.. code-block:: text
:caption: Example fold zext(trunc:nuw)
@@ -630,3 +630,20 @@ using wip_match_opcode in patterns.
(G_ZEXT $root, $src),
[{ return Helper.matchZextOfTrunc(${root}, ${matchinfo}); }]),
(apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>;
+
+
+ // Precise: lists all combine combinations
+ class ext_of_ext_opcodes<Instruction ext1Opcode, Instruction ext2Opcode> : GICombineRule <
+ (defs root:$root, build_fn_matchinfo:$matchinfo),
+ (match (ext2Opcode $second, $src):$Second,
+ (ext1Opcode $root, $second):$First,
+ [{ return Helper.matchExtOfExt(*${First}, *${Second}, ${matchinfo}); }]),
+ (apply [{ Helper.applyBuildFn(*${First}, ${matchinfo}); }])>;
+
+ def zext_of_zext : ext_of_ext_opcodes<G_ZEXT, G_ZEXT>;
+ def zext_of_anyext : ext_of_ext_opcodes<G_ZEXT, G_ANYEXT>;
+ def sext_of_sext : ext_of_ext_opcodes<G_SEXT, G_SEXT>;
+ def sext_of_anyext : ext_of_ext_opcodes<G_SEXT, G_ANYEXT>;
+ def anyext_of_anyext : ext_of_ext_opcodes<G_ANYEXT, G_ANYEXT>;
+ def anyext_of_zext : ext_of_ext_opcodes<G_ANYEXT, G_ZEXT>;
+ def anyext_of_sext : ext_of_ext_opcodes<G_ANYEXT, G_SEXT>;
>From f3c33614217f60d6f1568a5f8f96dd861e4702d3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorsten=20Sch=C3=BCtt?= <schuett at gmail.com>
Date: Mon, 9 Sep 2024 21:53:27 +0200
Subject: [PATCH 2/2] fix alignment
---
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 f36ffb889f813d..42ceb1883f7de3 100644
--- a/llvm/docs/GlobalISel/MIRPatterns.rst
+++ b/llvm/docs/GlobalISel/MIRPatterns.rst
@@ -636,8 +636,8 @@ using wip_match_opcode in patterns. It can lead to imprecise patterns.
class ext_of_ext_opcodes<Instruction ext1Opcode, Instruction ext2Opcode> : GICombineRule <
(defs root:$root, build_fn_matchinfo:$matchinfo),
(match (ext2Opcode $second, $src):$Second,
- (ext1Opcode $root, $second):$First,
- [{ return Helper.matchExtOfExt(*${First}, *${Second}, ${matchinfo}); }]),
+ (ext1Opcode $root, $second):$First,
+ [{ return Helper.matchExtOfExt(*${First}, *${Second}, ${matchinfo}); }]),
(apply [{ Helper.applyBuildFn(*${First}, ${matchinfo}); }])>;
def zext_of_zext : ext_of_ext_opcodes<G_ZEXT, G_ZEXT>;
More information about the llvm-commits
mailing list