[llvm] [GlobalISel] Add `combine` action for C++ combine rules (PR #135941)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 20 00:47:51 PDT 2025
================
@@ -370,6 +370,42 @@ The following expansions are available for MIR patterns:
(match (G_ZEXT $root, $src):$mi),
(apply "foobar(${root}.getReg(), ${src}.getReg(), ${mi}->hasImplicitDef())")>;
+``combine`` Operator
+~~~~~~~~~~~~~~~~~~~~
+
+``GICombineRule`` also supports a single ``combine`` pattern, which is a shorter way to
+declare patterns that just match one or more instruction, then defer all remaining matching
+and rewriting logic to C++ code.
+
+.. code-block:: text
+ :caption: Example usage of the combine operator.
+
+ // match + apply
+ def FooLong : GICombineRule<
+ (defs root:$root),
+ (match (G_ZEXT $root, $src):$mi, "return matchFoo(${mi});"),
+ (apply "applyFoo(${mi});")>;
+
+ // combine
+ def FooShort : GICombineRule<
+ (defs root:$root),
+ (combine (G_ZEXT $root, $src):$mi, "return combineFoo(${mi});")>;
----------------
s-barannikov wrote:
Just to clarify, is it different from
```
def FooShort : GICombineRule<
(defs root:$root),
(match (G_ZEXT $root, $src):$mi),
(apply "return combineFoo(${mi});")
>;
```
?
https://github.com/llvm/llvm-project/pull/135941
More information about the llvm-commits
mailing list