[llvm] [GlobalISel] Add `GITypeOf` special type (PR #66079)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 12 06:26:52 PDT 2023
================
@@ -101,6 +101,48 @@ pattern, you can try naming your patterns to see exactly where the issue is.
// using $x again here copies operand 1 from G_AND into the new inst.
(apply (COPY $root, $x))
+Types
+-----
+
+ValueType
+~~~~~~~~~
+
+Subclasses of ``ValueType`` are valid types, e.g. ``i32``.
+
+GITypeOf
+~~~~~~~~
+
+``GITypeOf<"$x">`` is a ``GISpecialType`` that allows for the creation of a
+register or immediate with the same type as another (register) operand.
+
+Operand:
+
+* An operand name as a string, prefixed by ``$``.
+
+Semantics:
+
+* Can only appear in an 'apply' pattern.
+* The operand name used must appear in the 'match' pattern of the
+ same ``GICombineRule``.
+
+.. code-block:: text
+ :caption: Example: Immediate
+
+ def mul_by_neg_one: GICombineRule <
+ (defs root:$root),
+ (match (G_MUL $dst, $x, -1)),
+ (apply (G_SUB $dst, (GITypeOf<"$x"> 0), $x))
----------------
Pierre-vh wrote:
I agree it's ugly, but it's just a baby step. The intent here is just to enable the functionality.
I've been thinking a lot about how to fix this kind of combine and all solutions have their pros and cons - either they're sophisticated and hard to implement, or they have to compromise. This one compromises on readability, but it has the advantage that we can improve it and make it great "just by" fixing type inference in the MIR patterns (if we can infer the TypeOf, we're good).
Doing some proper inference is definitely on my list, I'm still trying to figure out how to do it well because the "OperandType" of `CodeGenInstruction` is too limiting - I think I will need to add a new field to `GenericInstruction` with a better description of inference constraints.
https://github.com/llvm/llvm-project/pull/66079
More information about the llvm-commits
mailing list