[llvm] [GlobalISel][TableGen] Adds GIReplaceRegWithConstant/GIReplaceRegWithFConstant MIR builtin patterns (PR #219563)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 28 12:03:53 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-globalisel
Author: Vikash Gupta (vg0204)
<details>
<summary>Changes</summary>
This patch extends the declarative apply-side vocabulary of MIR pattern builtins so combines can materialize a constant and replace the root without hand-written C++.
- GIReplaceRegWithConstant replaces a register defined by the match root with a G_CONSTANT of the same type - the declarative form of Helper.replaceInstWithConstant.
- GIReplaceRegWithFConstant does the same with a G_FCONSTANT - the declarative form of Helper.replaceInstWithFConstant.
Both take the immediate as a TableGen integer literal. For the fp variant the grammar has no fp literals, so the literal is interpreted as a floating-point value (0 -> 0.0, -1 -> -1.0); non-integer values such as 0.5 cannot be expressed today.
---
Patch is 33.96 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/219563.diff
13 Files Affected:
- (modified) llvm/docs/GlobalISel/MIRPatterns.md (+107-48)
- (modified) llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h (+6)
- (modified) llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h (+17-5)
- (modified) llvm/include/llvm/Target/GlobalISel/Combine.td (+37)
- (modified) llvm/test/TableGen/GlobalISelCombinerEmitter/builtins/builtin-pattern-errors.td (+93-1)
- (modified) llvm/test/TableGen/GlobalISelCombinerEmitter/builtins/builtin-pattern-parrsing.td (+45-1)
- (added) llvm/test/TableGen/GlobalISelCombinerEmitter/builtins/match-table-replacereg-constant.td (+38)
- (added) llvm/test/TableGen/GlobalISelCombinerEmitter/builtins/match-table-replacereg-fconstant.td (+39)
- (modified) llvm/utils/TableGen/Common/GlobalISel/MatchTable/Matchers.cpp (+9)
- (modified) llvm/utils/TableGen/Common/GlobalISel/MatchTable/Matchers.h (+20)
- (modified) llvm/utils/TableGen/Common/GlobalISel/Patterns.cpp (+14-1)
- (modified) llvm/utils/TableGen/Common/GlobalISel/Patterns.h (+5-1)
- (modified) llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp (+45)
``````````diff
diff --git a/llvm/docs/GlobalISel/MIRPatterns.md b/llvm/docs/GlobalISel/MIRPatterns.md
index 8253edf463562..27bc91248c9fb 100644
--- a/llvm/docs/GlobalISel/MIRPatterns.md
+++ b/llvm/docs/GlobalISel/MIRPatterns.md
@@ -32,34 +32,27 @@ MIR patterns use the DAG datatype in TableGen.
Operands essentially fall into one of two categories:
- immediates
-
- untyped, unnamed: `0`
- untyped, named: `0:$y`
- typed, unnamed: `(i32 0)`
- typed, named: `(i32 0):$y`
-
- machine operands
-
- untyped: `$x`
- typed: `i32:$x`
Semantics:
- A typed operand always adds an operand type check to the matcher.
-
- There is a trivial type inference system to propagate types.
-
- e.g. You only need to use `i32:$x` once in any pattern of a
- `GICombinePatFrag` alternative or `GICombineRule`, then all
- other patterns in that rule/alternative can simply use `$x`
- (`i32:$x` is redundant).
-
+ `GICombinePatFrag` alternative or `GICombineRule`, then all
+ other patterns in that rule/alternative can simply use `$x`
+ (`i32:$x` is redundant).
- A named operand's behavior depends on whether the name has been seen before.
-
- For match patterns, reusing an operand name checks that the operands
- are identical (see example 2 below).
+ are identical (see example 2 below).
- For apply patterns, reusing an operand name simply copies that operand into
- the new instruction (see example 2 below).
+ the new instruction (see example 2 below).
Operands are ordered just like they would be in a MachineInstr: the defs (outs)
come first, then the uses (ins).
@@ -113,7 +106,7 @@ Semantics:
- Can only appear in an 'apply' pattern.
- The operand name used must appear in the 'match' pattern of the
- same `GICombineRule`.
+same `GICombineRule`.
```{code-block} text
:caption: 'Example: Immediate'
@@ -143,12 +136,9 @@ more operands remaining on an instruction.
Type Parameters:
- The minimum number of additional operands to match. Must be greater than zero.
-
- Default is 1.
-
- The maximum number of additional operands to match. Must be strictly greater
- than the minimum.
-
+than the minimum.
- 0 can be used to indicate there is no upper limit.
- Default is 0.
@@ -159,11 +149,11 @@ Semantics:
- `GIVariadic<>` operands can only appear as the last operand in a 'match' pattern.
- Each instance within a 'match' pattern must be uniquely named.
- Re-using a `GIVariadic<>` operand in an 'apply' pattern will result in all
- the matched operands being copied from the original instruction.
+the matched operands being copied from the original instruction.
- The min/max operands will result in the matcher checking that the number of operands
- falls within that range.
+falls within that range.
- `GIVariadic<>` operands can be used in C++ code within a rule, which will
- result in the operand name being expanded to a value of type `ArrayRef<MachineOperand>`.
+result in the operand name being expanded to a value of type `ArrayRef<MachineOperand>`.
```text
// bool checkBuildVectorToUnmerge(ArrayRef<MachineOperand>);
@@ -209,7 +199,59 @@ Semantics:
- Can only appear in an 'apply' pattern.
- If both old/new are operands of matched instructions,
- `canReplaceReg` is checked before applying the rule.
+`canReplaceReg` is checked before applying the rule.
+
+#### GIReplaceRegWithConstant
+
+```{code-block} text
+:caption: Usage
+
+(apply (GIReplaceRegWithConstant $reg, 42))
+```
+
+Operands:
+
+- `$reg` (out) register defined by the match root
+- the integer immediate to materialize (sign-extended to `$reg`'s type)
+
+Semantics:
+
+- Can only appear in an 'apply' pattern.
+- `$reg` must be a register defined by the match root.
+- Builds a `G_CONSTANT` of `$reg`'s type, replaces all uses of `$reg` with it,
+then erases the root. This is the declarative form of
+`Helper.replaceInstWithConstant`.
+
+#### GIReplaceRegWithFConstant
+
+```{code-block} text
+:caption: Usage
+
+(apply (GIReplaceRegWithFConstant $reg, 0))
+```
+
+Operands:
+
+- `$reg` (out) register defined by the match root
+- the immediate to materialize (see the constraint below)
+
+```{warning}
+The immediate **must be an integer literal**; it is interpreted as a
+floating-point value. The MIR pattern grammar has no floating-point literals,
+so only fp values that have an exact integer form can be written, e.g. `0` ->
+`0.0`, `1` -> `1.0`, `-1` -> `-1.0`. Non-integer fp values such as `0.5` (and
+special values like `NaN`/`inf`) **cannot** be expressed with this builtin
+today. Do not write `0.5` or `(f32 0)`: only a bare integer literal is
+accepted.
+```
+
+Semantics:
+
+- Can only appear in an 'apply' pattern.
+- `$reg` must be a register defined by the match root.
+- Builds a `G_FCONSTANT` of `$reg`'s type, replaces all uses of b`$reg` with it,
+then erases the root. This is the declarative form of
+`Helper.replaceInstWithFConstant`.
#### GIEraseRoot
@@ -271,18 +313,18 @@ def TestNot : GICombineRule<
This a non-exhaustive list of known issues with MIR patterns at this time.
- Using `GICombinePatFrag` within another `GICombinePatFrag` is not
- supported.
+supported.
- `GICombinePatFrag` can only have a single root.
- Instructions with multiple defs cannot be the root of a `GICombinePatFrag`.
- Using `GICombinePatFrag` in the `apply` pattern of a `GICombineRule`
- is not supported.
+is not supported.
- We cannot rewrite a matched instruction other than the root.
- Matching/creating a (CImm) immediate >64 bits is not supported
- (see comment in `GIM_CheckConstantInt`)
+(see comment in `GIM_CheckConstantInt`)
- There is currently no way to constrain two register/immediate types to
- match. e.g. if a pattern needs to work on both i32 and i64, you either
- need to leave it untyped and check the type in C++, or duplicate the
- pattern.
+match. e.g. if a pattern needs to work on both i32 and i64, you either
+need to leave it untyped and check the type in C++, or duplicate the
+pattern.
- `GISpecialType` operands are not allowed within a `GICombinePatFrag`.
- `GIVariadic<>` matched operands must each have a unique name.
@@ -318,11 +360,11 @@ def Foo : GICombineRule<
(apply (G_STORE (i32 0), $ptr):$root)>;
```
-Combine Rules also allow mixing C++ code with MIR patterns, so that you
+Combine Rules also allow mixing C++code with MIR patterns, so that you
may perform additional checks when matching, or run a C++ action after
matching.
-Note that C++ code in `apply` pattern is mutually exclusive with
+Note that C++code in `apply` pattern is mutually exclusive with
other patterns. However, you can freely mix C++ code with other
types of patterns in `match` patterns.
C++ code in `match` patterns is always run last, after all other
@@ -351,7 +393,7 @@ The following expansions are available for MIR patterns:
- operand names (`MachineOperand &`)
- pattern names (`MachineInstr *` for `match`,
- `MachineInstrBuilder &` for apply)
+`MachineInstrBuilder &` for apply)
```{code-block} text
:caption: Example C++ Expansions
@@ -391,7 +433,7 @@ This has a couple of advantages:
As described above, this is syntactic sugar for the match+apply form. In a `combine` pattern:
- Everything except C++ code is considered the `match` part.
-- The C++ code is the `apply` part. C++ code is emitted in order of appearance.
+- The C++code is the `apply` part. C++ code is emitted in order of appearance.
:::{note}
The C++ code **must** return true if it changed any instruction. Returning false when changing
@@ -435,15 +477,40 @@ def Foo : GICombineRule<
(apply (GIEraseRoot))>;
```
-#### Common Pattern #3: Emitting a Constant Value
+#### Common Pattern #3: Replacing the Root with a Constant
+
+If we want to replace all uses of a register defined by the match root with a
+freshly materialized constant of the same type, we can use the
+`GIReplaceRegWithConstant` and `GIReplaceRegWithFConstant` builtins. They are
+the declarative forms of `Helper.replaceInstWithConstant` and
+`Helper.replaceInstWithFConstant`.
+
+```text
+// Replaces all uses of $dst with a G_CONSTANT of $dst's type, then erases the
+// root.
+def Foo : GICombineRule<
+ (defs root:$dst),
+ (match (G_FOO $dst, $src)),
+ (apply (GIReplaceRegWithConstant $dst, 42))>;
+
+// The FConstant variant builds a G_FCONSTANT instead. The immediate is written
+// as an integer literal and interpreted as a floating-point value (the pattern
+// grammar has no fp literals), so 0 materializes 0.0.
+def Bar : GICombineRule<
+ (defs root:$dst),
+ (match (G_BAR $dst, $src)),
+ (apply (GIReplaceRegWithFConstant $dst, 0))>;
+```
+
+#### Common Pattern #4: Emitting a Constant Value
When an immediate operand appears in an 'apply' pattern, the behavior
depends on whether it's typed or not.
- If the immediate is typed, `MachineIRBuilder::buildConstant` is used
- to create a `G_CONSTANT`. A `G_BUILD_VECTOR` will be used for vectors.
+to create a `G_CONSTANT`. A `G_BUILD_VECTOR` will be used for vectors.
- If the immediate is untyped, a simple immediate is added
- (`MachineInstrBuilder::addImm`).
+(`MachineInstrBuilder::addImm`).
There is of course a special case for `G_CONSTANT`. Immediates for
`G_CONSTANT` must always be typed, and a CImm is added
@@ -483,43 +550,35 @@ def Bux : GICombineRule<
They have two main usecases:
- Reduce repetition by creating a `GICombinePatFrag` for common
- patterns (see example 1).
+patterns (see example 1).
- Implicitly duplicate a CombineRule for multiple variants of a
- pattern (see example 2).
+pattern (see example 2).
A `GICombinePatFrag` is composed of three elements:
- zero or more `in` (def) parameter
-
- zero or more `out` parameter
-
- A list of MIR patterns that can match.
-
- When a `GICombinePatFrag` is used within a pattern, the pattern is
- cloned once for each alternative that can match.
+ cloned once for each alternative that can match.
Parameters can have the following types:
- `gi_mo`, which is the implicit default (no type = `gi_mo`).
-
- Refers to any operand of an instruction (register, BB ref, imm, etc.).
- Can be used in both `in` and `out` parameters.
- Users of the PatFrag can only use an operand name for this
- parameter (e.g. `(my_pat_frag $foo)`).
-
+ parameter (e.g. `(my_pat_frag $foo)`).
- `root`
-
- This is identical to `gi_mo`.
- Can only be used in `out` parameters to declare the root of the
- pattern.
+ pattern.
- Non-empty `out` parameter lists must always have exactly one `root`.
-
- `gi_imm`
-
- Refers to an (potentially typed) immediate.
- Can only be used in `in` parameters.
- Users of the PatFrag can only use an immediate for this parameter
- (e.g. `(my_pat_frag 0)` or `(my_pat_frag (i32 0))`)
+ (e.g. `(my_pat_frag 0)` or `(my_pat_frag (i32 0))`)
`out` operands can only be empty if the `GICombinePatFrag` only contains
C++ code. If the fragment contains instruction patterns, it has to have at
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h b/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h
index 6e3ccf1923c40..fc48fa9f3c21c 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h
@@ -384,6 +384,12 @@ enum {
/// - Imm(8) - The immediate to add
GIR_BuildConstant,
+ /// Builds a floating-point constant and stores its result in a TempReg.
+ /// The immediate is interpreted as a floating-point value.
+ /// - TempRegID(ULEB128) - Temp Register to define.
+ /// - Imm(8) - The immediate (interpreted as a double) to materialize
+ GIR_BuildFConstant,
+
/// Copy an operand to the specified instruction
/// - NewInsnID(ULEB128) - Instruction ID to modify
/// - OldInsnID(ULEB128) - Instruction ID to copy from
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h b/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h
index e0720928c6526..619e65bbc3893 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h
@@ -1112,14 +1112,26 @@ bool GIMatchTableExecutor::executeMatchTable(
break;
}
- case GIR_BuildConstant: {
+ case GIR_BuildConstant:
+ case GIR_BuildFConstant: {
uint64_t TempRegID = readULEB();
uint64_t Imm = readU64();
initializeBuilder();
- Builder.buildConstant(State.TempRegisters[TempRegID], Imm);
- DEBUG_WITH_TYPE(TgtExecutor::getName(),
- dbgs() << CurrentIdx << ": GIR_BuildConstant(TempReg["
- << TempRegID << "], Imm=" << Imm << ")\n");
+ if (MatcherOpcode == GIR_BuildFConstant) {
+ // The immediate is a signed integer literal interpreted as a
+ // floating-point value. Go through int64_t to preserve the sign;
+ // buildFConstant converts it to the temp reg's fp semantics.
+ Builder.buildFConstant(State.TempRegisters[TempRegID],
+ static_cast<double>(static_cast<int64_t>(Imm)));
+ } else {
+ Builder.buildConstant(State.TempRegisters[TempRegID], Imm);
+ }
+ DEBUG_WITH_TYPE(
+ TgtExecutor::getName(),
+ dbgs() << CurrentIdx << ": "
+ << (MatcherOpcode == GIR_BuildFConstant ? "GIR_BuildFConstant"
+ : "GIR_BuildConstant")
+ << "(TempReg[" << TempRegID << "], Imm=" << Imm << ")\n");
break;
}
diff --git a/llvm/include/llvm/Target/GlobalISel/Combine.td b/llvm/include/llvm/Target/GlobalISel/Combine.td
index e0f665e85c2cc..6b82463d862a1 100644
--- a/llvm/include/llvm/Target/GlobalISel/Combine.td
+++ b/llvm/include/llvm/Target/GlobalISel/Combine.td
@@ -162,6 +162,43 @@ class GIBuiltinInst;
// "canReplaceReg" is checked before applying the rule.
def GIReplaceReg : GIBuiltinInst;
+// Replace a register defined by the match root with a G_CONSTANT of the same
+// type. The declarative form of Helper.replaceInstWithConstant.
+//
+// Usage:
+// (apply (GIReplaceRegWithConstant $reg, 42))
+//
+// Operands:
+// - $reg (out) register defined by the match root
+// - the integer immediate to materialize (sign-extended to $reg's type)
+//
+// Semantics:
+// - Can only appear in an 'apply' pattern.
+// - $reg must be a register defined by the match root.
+// - Builds a G_CONSTANT of $reg's type, replaces all uses of $reg with it,
+// then erases the root.
+def GIReplaceRegWithConstant : GIBuiltinInst;
+
+// Replace a register defined by the match root with a G_FCONSTANT of the same
+// type. The declarative form of Helper.replaceInstWithFConstant.
+//
+// Usage:
+// (apply (GIReplaceRegWithFConstant $reg, 0))
+//
+// Operands:
+// - $reg (out) register defined by the match root
+// - the immediate to materialize, given as an integer literal and interpreted
+// as a floating-point value (the pattern grammar has no fp literals), e.g.
+// 0 -> 0.0, 1 -> 1.0, -1 -> -1.0. Non-integer fp values (e.g. 0.5) cannot be
+// expressed today.
+//
+// Semantics:
+// - Can only appear in an 'apply' pattern.
+// - $reg must be a register defined by the match root.
+// - Builds a G_FCONSTANT of $reg's type, replaces all uses of $reg with it,
+// then erases the root.
+def GIReplaceRegWithFConstant : GIBuiltinInst;
+
// Apply action that erases the match root.
//
// Usage:
diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/builtins/builtin-pattern-errors.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/builtins/builtin-pattern-errors.td
index 8e3e27daaa5bf..6512dd0e6e48c 100644
--- a/llvm/test/TableGen/GlobalISelCombinerEmitter/builtins/builtin-pattern-errors.td
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/builtins/builtin-pattern-errors.td
@@ -78,6 +78,86 @@ def replacereg_nonroot : GICombineRule<
(match (COPY $dst, $tmp), (COPY $tmp, $src)),
(apply (GIReplaceReg $dst, $src), (GIReplaceReg $tmp, $src))>;
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: 'GIReplaceRegWithConstant' cannot be used in a 'match' pattern
+def replaceregconstant_in_match : GICombineRule<
+ (defs root:$dst),
+ (match (GIReplaceRegWithConstant $dst, 0)),
+ (apply (COPY $dst, $src))>;
+
+// CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: 'GIReplaceRegWithConstant' expected 2 operands, got 1
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(GIReplaceRegWithConstant ?:$dst)'
+def replaceregconstant_ops : GICombineRule<
+ (defs root:$dst),
+ (match (COPY $dst, $src)),
+ (apply (GIReplaceRegWithConstant $dst))>;
+
+// CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: expected operand 1 of 'GIReplaceRegWithConstant' to be an immediate
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(GIReplaceRegWithConstant ?:$dst, ?:$src)'
+def replaceregconstant_nonimm : GICombineRule<
+ (defs root:$dst),
+ (match (COPY $dst, $src)),
+ (apply (GIReplaceRegWithConstant $dst, $src))>;
+
+// CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: out operand of 'GIReplaceRegWithConstant' cannot be an immediate
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(GIReplaceRegWithConstant (i32 0), 0)'
+def replaceregconstant_immreg : GICombineRule<
+ (defs root:$dst),
+ (match (COPY $dst, $src)),
+ (apply (GIReplaceRegWithConstant (i32 0), 0))>;
+
+// CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: expected operand 1 of 'GIReplaceRegWithConstant' to be an immediate
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(GIReplaceRegWithConstant ?:$dst, (i32 0):$k)'
+def replaceregconstant_namedimm : GICombineRule<
+ (defs root:$dst),
+ (match (COPY $dst, $src)),
+ (apply (GIReplaceRegWithConstant $dst, (i32 0):$k))>;
+
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: GIReplaceRegWithConstant cannot replace 'tmp': this builtin can only replace a register defined by the match root
+def replaceregconstant_nonroot : GICombineRule<
+ (defs root:$dst),
+ (match (COPY $dst, $tmp), (COPY $tmp, $src)),
+ (apply (GIReplaceReg $dst, $src), (GIReplaceRegWithConstant $tmp, 0))>;
+
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: 'GIReplaceRegWithFConstant' cannot be used in a 'match' pattern
+def replaceregfconstant_in_match : GICombineRule<
+ (defs root:$dst),
+ (match (GIReplaceRegWithFConstant $dst, 0)),
+ (apply (COPY $dst, $src))>;
+
+// CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: 'GIReplaceRegWithFConstant' expected 2 operands, got 1
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(GIReplaceRegWithFConstant ?:$dst)'
+def replaceregfconstant_ops : GICombineRule<
+ (defs root:$dst),
+ (match (COPY $dst, $src)),
+ (apply (GIReplaceRegWithFConstant $dst))>;
+
+// CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: expected operand 1 of 'GIReplaceRegWithFConstant' to be an immediate
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(GIReplaceRegWithFConstant ?:$dst, ?:$src)'
+def replaceregfconstant_nonimm : GICombineRule<
+ (defs root:$dst),
+ (match (COPY $dst, $src)),
+ (apply (GIReplaceRegWithFConstant $dst, $src))>;
+
+// CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: out operand of 'GIReplaceRegWithFConstant' cannot be an immediate
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(GIReplaceRegWithFConstant (i32 0), 0)'
+def replaceregfconstant_immreg : GICombineRule<
+ (defs root:$dst),
+ (match (COPY $dst, $src)),
+ (apply (GIReplaceRegWithFConstant (i32 0), 0))>;
+
+// CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: expected operand 1 of 'GIReplaceRegWithFConstant' to be an immediate
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(GIReplaceRegWithFConstant ?:$dst, (i32 0):$k)'
+def replaceregfconstant_namedimm : GICombineRule<
+ (defs root:$dst),
+ (match (COPY $dst, $src)),
+ (apply (GIReplaceRegWithFConstant $dst, (i32 0):$k))>;
+
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: GIReplaceRegWithFConstant cannot replace 'tmp': this builtin can only replace a register defined by the match root
+def replaceregfconstant_nonroot : GICombineRule<
+ (defs root:$dst),
+ (match (COPY $dst, $tmp), (COPY $tmp, $src)),
+ (apply (GIReplaceReg $dst, $src), (GIReplaceRegWithFConstant $tmp, 0))>;
+
// CHECK: error: Failed to parse one or more rules
def MyCombiner: GICombiner<"GenMyCombiner", [
@@ -90,5 +170,17 @@ def MyCombiner: GICombiner<"GenMyCombiner", [
eraseroot_notinstmatch,
replacer...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/219563
More information about the llvm-commits
mailing list