-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GlobalIsel] Add Gallery to MIR Patterns #89974
Conversation
@llvm/pr-subscribers-llvm-globalisel Author: Thorsten Schütt (tschuett) ChangesFull diff: https://github.com/llvm/llvm-project/pull/89974.diff 1 Files Affected:
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),
|
:caption: Example fold ext(trunc) | ||
|
||
(match (wip_match_opcode G_ZEXT):$root, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should include the apply part of the example?
llvm/docs/GlobalISel/MIRPatterns.rst
Outdated
(match (G_TRUNC $src, $x), | ||
(G_ZEXT $root, $src), | ||
|
||
(match (G_TRUNC $src, $x, (MIFlags NoUWrap)), | ||
(G_ZEXT $root, $src), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this is showing 2 nearly identical patterns. What is the MIFlags doing if the first pattern didn't need flag checks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The third pattern is more precise. The one above hits with no flags and with NoSWrap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more precise, but if the first pattern works you wouldn't write the second
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot of misbehaviour in Combine.td. I just want some examples that we can point to in review.
llvm/docs/GlobalISel/MIRPatterns.rst
Outdated
(apply [{ Helper.applyBuildFnMO(${root}, ${matchinfo}); }])>; | ||
|
||
|
||
(match (G_TRUNC $src, $x), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a good idea to have some examples. I'd like it even more if each one had a comment explaining what it matches, either in English or in some pseudocode like Match (zext (trunc x))
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the top it states: fold ext(trunk:nuw)
I want to prevent misbehaviour like:
// Fold (zext (trunc x)) -> x if the source type is same as the destination type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the misbehaviour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It registers on G_ZEXT:
(match (wip_match_opcode G_ZEXT):$root,
but it states as a comment that it wants to fold zext(trunk(x).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's wrong with that? wip_match_opcode just matches the "topmost" / "outermost" opcode, which is zext in this case. The C++ code looks for the inner node, trunc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will match any G_ZEXT in the function. In most cases, there is no trunk on the zext. It is a waste of compile-time. If we would write more precise matches, it might reduce compile-time.
wip_match_opcode should be forbidden. Please write precise patterns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I was confused because "misbehaviour" generally implies that something is incorrect, not just suboptimal.
I would prefer comments on the individual patterns, e.g.:
// Imprecise: matches any G_ZEXT
...
// Better: matches G_ZEXT of G_TRUNC
...
// Precise: matches G_ZEXT of G_TRUNC with nuw flag
...
Without that, it is not clear to me why you have presented a list of similar-but-different patterns.
llvm/docs/GlobalISel/MIRPatterns.rst
Outdated
using wip_match_opcode in patterns. | ||
|
||
.. code-block:: text | ||
:caption: Example fold ext(trunc:nuw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:caption: Example fold ext(trunc:nuw) | |
:caption: Example fold zext(trunc:nuw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The text LGTM, but when I try to build docs-llvm-html
I get:
Warning, treated as error:
docs/GlobalISel/MIRPatterns.rst:471:Error in "code-block" directive:
maximum 1 argument(s) allowed, 7 supplied.
No description provided.