[llvm] [GlobalISel][TableGen] Support for typed G_FCONSTANT Imm in MIR-patttern (PR #219563)

Vikash Gupta via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 29 02:40:35 PDT 2026


https://github.com/vg0204 updated https://github.com/llvm/llvm-project/pull/219563

>From 460a4f90b32a1b16126a11ece1ad46f686c1e43f Mon Sep 17 00:00:00 2001
From: vg0204 <Vikash.Gupta at amd.com>
Date: Sat, 29 Aug 2026 03:56:17 +0530
Subject: [PATCH 1/2] [GlobalISel][TableGen] Support typed G_FCONSTANT Imm in
 MIR-patttern

GlobalISel MIR combine patterns can already build a typed integer
constant directly in an apply pattern, e.g. `(apply (G_CONSTANT $dst,
(GITypeOf<"$dst"> 0)))`. The same was not possible for `G_FCONSTANT`:
writing a typed literal on it silently producing invalid MIR, since the
immediate was routed through the path meant for register operands rather
than being emitted as a floating-point immediate.

This patch extends that support to `G_FCONSTANT`, letting typed
float-constant patterns be written declaratively and type-derived via
`GITypeOf` just like the integer case, instead of falling back to
hand-written C++ combine code or hitting the bad-MIR bug.

This is a prerequisite for migrating existing `wip_match_opcode`
combines that replace a matched value with a float constant of its
own type into pure MIR patterns.
---
 llvm/docs/GlobalISel/MIRPatterns.md           | 16 +++++++
 .../CodeGen/GlobalISel/GIMatchTableExecutor.h |  8 ++++
 .../GlobalISel/GIMatchTableExecutorImpl.h     | 21 +++++++++
 .../match-table-typeof-fconstant.td           | 46 +++++++++++++++++++
 .../Common/GlobalISel/MatchTable/Matchers.cpp |  5 +-
 .../Common/GlobalISel/MatchTable/Matchers.h   | 11 +++--
 .../TableGen/GlobalISelCombinerEmitter.cpp    | 21 +++++++--
 7 files changed, 120 insertions(+), 8 deletions(-)
 create mode 100644 llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-typeof-fconstant.td

diff --git a/llvm/docs/GlobalISel/MIRPatterns.md b/llvm/docs/GlobalISel/MIRPatterns.md
index 8253edf463562..e3873f9211ca2 100644
--- a/llvm/docs/GlobalISel/MIRPatterns.md
+++ b/llvm/docs/GlobalISel/MIRPatterns.md
@@ -449,6 +449,12 @@ There is of course a special case for `G_CONSTANT`. Immediates for
 `G_CONSTANT` must always be typed, and a CImm is added
 (`MachineInstrBuilder::addCImm`).
 
+`G_FCONSTANT` is handled the same way: immediates for `G_FCONSTANT` must
+always be typed, and an FP immediate is added (`MachineInstrBuilder::addFPImm`).
+Since the pattern grammar has no fp literals, the integer 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.
+
 ```{code-block} text
 :caption: 'Constant Emission Examples:'
 
@@ -475,6 +481,16 @@ def Bux : GICombineRule<
   (defs root:$dst),
   (match (G_FOO $dst, $src)),
   (apply (G_CONSTANT $dst, (i32 0)))>;
+
+// GITypeOf can be combined with this to reuse an already-matched register's
+// type instead of hardcoding one, which is handy when replacing the root:
+//
+// Example output:
+//    %dst = G_FCONSTANT float 0.0
+def Baz : GICombineRule<
+  (defs root:$dst),
+  (match (G_FOO $dst, $src)),
+  (apply (G_FCONSTANT $dst, (GITypeOf<"$dst"> 0)))>;
 ```
 
 ### GICombinePatFrag
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h b/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h
index 6e3ccf1923c40..ba6f90a125707 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h
@@ -489,6 +489,14 @@ enum {
   /// - Imm(8) - The immediate to add
   GIR_AddCImm,
 
+  /// Add a floating-point immediate to the specified instruction.
+  /// The immediate is interpreted as a floating-point value (a double) and
+  /// converted to the semantics matching Ty before being attached.
+  /// - InsnID(ULEB128) - Instruction ID to modify
+  /// - Ty(1) - Type of the constant immediate.
+  /// - Imm(8) - The immediate (interpreted as a double) to add
+  GIR_AddCFPImm,
+
   /// Render complex operands to the specified instruction
   /// - InsnID(ULEB128) - Instruction ID to modify
   /// - RendererID(2) - The renderer to call
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h b/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h
index e0720928c6526..6a078adb04a42 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h
@@ -20,6 +20,7 @@
 #include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
 #include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
 #include "llvm/CodeGen/GlobalISel/Utils.h"
+#include "llvm/CodeGen/LowLevelTypeUtils.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/CodeGen/MachineOperand.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
@@ -1334,6 +1335,26 @@ bool GIMatchTableExecutor::executeMatchTable(
       break;
     }
 
+    case GIR_AddCFPImm: {
+      uint64_t InsnID = readULEB();
+      int TypeID = readS8();
+      uint64_t Imm = readU64();
+      assert(OutMIs[InsnID] && "Attempted to add to undefined instruction");
+
+      LLT Ty = ExecInfo.TypeObjects[TypeID];
+      LLVMContext &Ctx = MF->getFunction().getContext();
+      APFloat APF(static_cast<double>(static_cast<int64_t>(Imm)));
+      bool Ignored;
+      APF.convert(getFltSemanticForLLT(Ty.getScalarType()),
+                  APFloat::rmNearestTiesToEven, &Ignored);
+      OutMIs[InsnID].addFPImm(ConstantFP::get(Ctx, APF));
+      DEBUG_WITH_TYPE(TgtExecutor::getName(),
+                      dbgs() << CurrentIdx << ": GIR_AddCFPImm(OutMIs["
+                             << InsnID << "], TypeID=" << TypeID
+                             << ", Imm=" << Imm << ")\n");
+      break;
+    }
+
     case GIR_ComplexRenderer: {
       uint64_t InsnID = readULEB();
       uint16_t RendererID = readU16();
diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-typeof-fconstant.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-typeof-fconstant.td
new file mode 100644
index 0000000000000..56da3de3acc74
--- /dev/null
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-typeof-fconstant.td
@@ -0,0 +1,46 @@
+// RUN: llvm-tblgen -I %p/../../../include -gen-global-isel-combiner \
+// RUN:     -combiners=MyCombiner %s | \
+// RUN: FileCheck %s
+
+include "llvm/Target/Target.td"
+include "llvm/Target/GlobalISel/Combine.td"
+
+def MyTargetISA : InstrInfo;
+def MyTarget : Target { let InstructionSet = MyTargetISA; }
+
+// G_FCONSTANT, like G_CONSTANT, can be built directly in an apply pattern
+// with a GITypeOf-typed literal. The literal is interpreted as a
+// floating-point value (the pattern grammar has no fp literals).
+def Test0 : GICombineRule<
+  (defs root:$dst),
+  (match (G_FNEG $t, $src),
+         (G_FNEG $dst, $t)),
+  (apply (G_FCONSTANT $dst, (GITypeOf<"$dst"> 0)))>;
+
+// CHECK:      const uint8_t *GenMyCombiner::getMatchTable() const {
+// CHECK-NEXT:   constexpr static uint8_t MatchTable0[] = {
+// CHECK-NEXT:     GIM_Try, /*On fail goto*//*Label 0*/ GIMT_Encode4([[L34:[0-9]+]]), // Rule ID 0 //
+// CHECK-NEXT:       GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule0Enabled),
+// CHECK-NEXT:       GIM_CheckOpcode, /*MI*/0, GIMT_Encode2(TargetOpcode::G_FNEG),
+// CHECK-NEXT:       // MIs[0] dst
+// CHECK-NEXT:       GIM_RecordRegType, /*MI*/0, /*Op*/0, /*TempTypeIdx*/255,
+// CHECK-NEXT:       // MIs[0] t
+// CHECK-NEXT:       GIM_RecordInsnIgnoreCopies, /*DefineMI*/1, /*MI*/0, /*OpIdx*/1, // MIs[1]
+// CHECK-NEXT:       GIM_CheckOpcode, /*MI*/1, GIMT_Encode2(TargetOpcode::G_FNEG),
+// CHECK-NEXT:       // MIs[1] src
+// CHECK-NEXT:       // No operand predicates
+// CHECK-NEXT:       GIM_CheckIsSafeToFold, /*NumInsns*/1,
+// CHECK-NEXT:       // Combiner Rule #0: Test0
+// CHECK-NEXT:       GIR_BuildRootMI, /*Opcode*/GIMT_Encode2(TargetOpcode::G_FCONSTANT),
+// CHECK-NEXT:       GIR_RootToRootCopy, /*OpIdx*/0, // dst
+// CHECK-NEXT:       GIR_AddCFPImm, /*InsnID*/0, /*Type*/255, /*Imm*/GIMT_Encode8(0),
+// CHECK-NEXT:       GIR_EraseRootFromParent_Done,
+// CHECK-NEXT:     // Label 0: @[[L34]]
+// CHECK-NEXT:     GIM_Reject,
+// CHECK-NEXT:     }; // Size: {{[0-9]+}} bytes
+// CHECK-NEXT:   return MatchTable0;
+// CHECK-NEXT: }
+
+def MyCombiner: GICombiner<"GenMyCombiner", [
+  Test0
+]>;
diff --git a/llvm/utils/TableGen/Common/GlobalISel/MatchTable/Matchers.cpp b/llvm/utils/TableGen/Common/GlobalISel/MatchTable/Matchers.cpp
index cc1089fc316c7..656ab5379fc11 100644
--- a/llvm/utils/TableGen/Common/GlobalISel/MatchTable/Matchers.cpp
+++ b/llvm/utils/TableGen/Common/GlobalISel/MatchTable/Matchers.cpp
@@ -1846,8 +1846,9 @@ void ImmRenderer::emitRenderOpcodes(MatchTable &Table) const {
   if (CImmLLT) {
     assert(Table.isCombiner() &&
            "ConstantInt immediate are only for combiners!");
-    Table << MatchTable::Opcode("GIR_AddCImm") << MatchTable::Comment("InsnID")
-          << MatchTable::ULEB128Value(InsnID) << MatchTable::Comment("Type");
+    Table << MatchTable::Opcode(IsFP ? "GIR_AddCFPImm" : "GIR_AddCImm")
+          << MatchTable::Comment("InsnID") << MatchTable::ULEB128Value(InsnID)
+          << MatchTable::Comment("Type");
     emitType(Table, *CImmLLT);
     Table << MatchTable::Comment("Imm") << MatchTable::IntValue(8, Imm)
           << MatchTable::LineBreak;
diff --git a/llvm/utils/TableGen/Common/GlobalISel/MatchTable/Matchers.h b/llvm/utils/TableGen/Common/GlobalISel/MatchTable/Matchers.h
index b7ea01279eea9..63c3b09272fbe 100644
--- a/llvm/utils/TableGen/Common/GlobalISel/MatchTable/Matchers.h
+++ b/llvm/utils/TableGen/Common/GlobalISel/MatchTable/Matchers.h
@@ -2032,19 +2032,24 @@ class TempRegRenderer : public OperandRenderer {
 };
 
 /// Adds a specific immediate to the instruction being built.
-/// If a LLT is passed, a ConstantInt immediate is created instead.
+/// If a LLT is passed, a ConstantInt immediate is created instead, unless
+/// IsFP is set, in which case the immediate is interpreted as a
+/// floating-point value (a double) and a ConstantFP immediate is created.
 class ImmRenderer : public OperandRenderer {
 protected:
   unsigned InsnID;
   int64_t Imm;
   std::optional<LLTCodeGenOrTempType> CImmLLT;
+  bool IsFP = false;
 
 public:
   ImmRenderer(unsigned InsnID, int64_t Imm)
       : OperandRenderer(OR_Imm), InsnID(InsnID), Imm(Imm) {}
 
-  ImmRenderer(unsigned InsnID, int64_t Imm, const LLTCodeGenOrTempType &CImmLLT)
-      : OperandRenderer(OR_Imm), InsnID(InsnID), Imm(Imm), CImmLLT(CImmLLT) {
+  ImmRenderer(unsigned InsnID, int64_t Imm, const LLTCodeGenOrTempType &CImmLLT,
+              bool IsFP = false)
+      : OperandRenderer(OR_Imm), InsnID(InsnID), Imm(Imm), CImmLLT(CImmLLT),
+        IsFP(IsFP) {
     if (CImmLLT.isLLTCodeGen())
       KnownTypes.insert(CImmLLT.getLLTCodeGen());
   }
diff --git a/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp b/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
index bb93d0248e55f..5b05ba24d77f8 100644
--- a/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
@@ -2130,12 +2130,15 @@ bool CombineRuleBuilder::emitCodeGenInstructionApplyImmOperand(
     RuleMatcher &M, BuildMIAction &DstMI, const CodeGenInstructionPattern &P,
     const InstructionOperand &O) {
   // If we have a type, we implicitly emit a G_CONSTANT, except for G_CONSTANT
-  // itself where we emit a CImm.
+  // itself (which needs a CImm) and G_FCONSTANT (which needs an FP immediate,
+  // the literal being interpreted as a floating-point value since the
+  // pattern grammar has no fp literals).
   //
   // No type means we emit a simple imm.
-  // G_CONSTANT is a special case and needs a CImm though so this is likely a
-  // mistake.
+  // G_CONSTANT/G_FCONSTANT are special cases and need a typed immediate
+  // though so this is likely a mistake.
   const bool isGConstant = P.is("G_CONSTANT");
+  const bool isGFConstant = P.is("G_FCONSTANT");
   const auto Ty = O.getType();
   if (!Ty) {
     if (isGConstant) {
@@ -2145,6 +2148,13 @@ bool CombineRuleBuilder::emitCodeGenInstructionApplyImmOperand(
       return false;
     }
 
+    if (isGFConstant) {
+      PrintError("'G_FCONSTANT' immediate must be typed!");
+      PrintNote("while emitting pattern '" + P.getName() + "' (" +
+                P.getInstName() + ")");
+      return false;
+    }
+
     DstMI.addRenderer<ImmRenderer>(O.getImmValue());
     return true;
   }
@@ -2158,6 +2168,11 @@ bool CombineRuleBuilder::emitCodeGenInstructionApplyImmOperand(
     return true;
   }
 
+  if (isGFConstant) {
+    DstMI.addRenderer<ImmRenderer>(O.getImmValue(), *ImmTy, /*IsFP=*/true);
+    return true;
+  }
+
   unsigned TempRegID = M.allocateTempRegID();
   // Ensure MakeTempReg & the BuildConstantAction occur at the beginning.
   auto InsertIt = M.insertAction<MakeTempRegisterAction>(M.actions_begin(),

>From e33d8fe265e585efa64f85c7a5003c873e62daaf Mon Sep 17 00:00:00 2001
From: vg0204 <Vikash.Gupta at amd.com>
Date: Sat, 29 Aug 2026 14:57:08 +0530
Subject: [PATCH 2/2] Added match-table & pattern error tests for G_FCONSTANT

---
 llvm/docs/GlobalISel/MIRPatterns.md           |  9 +++-
 .../match-table-imms.td                       | 54 +++++++++++++------
 .../pattern-errors.td                         |  8 +++
 3 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/llvm/docs/GlobalISel/MIRPatterns.md b/llvm/docs/GlobalISel/MIRPatterns.md
index e3873f9211ca2..fe9806f2042f7 100644
--- a/llvm/docs/GlobalISel/MIRPatterns.md
+++ b/llvm/docs/GlobalISel/MIRPatterns.md
@@ -482,12 +482,19 @@ def Bux : GICombineRule<
   (match (G_FOO $dst, $src)),
   (apply (G_CONSTANT $dst, (i32 0)))>;
 
+// Example output:
+//    %dst = G_FCONSTANT float 4.200000e+01
+def Baz : GICombineRule<
+  (defs root:$dst),
+  (match (G_FOO $dst, $src)),
+  (apply (G_FCONSTANT $dst, (f32 42)))>;
+
 // GITypeOf can be combined with this to reuse an already-matched register's
 // type instead of hardcoding one, which is handy when replacing the root:
 //
 // Example output:
 //    %dst = G_FCONSTANT float 0.0
-def Baz : GICombineRule<
+def Qux : GICombineRule<
   (defs root:$dst),
   (match (G_FOO $dst, $src)),
   (apply (G_FCONSTANT $dst, (GITypeOf<"$dst"> 0)))>;
diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td
index e0b802447ea2a..33f13625ec36b 100644
--- a/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/match-table-imms.td
@@ -26,20 +26,30 @@ def CImmInstTest1 : GICombineRule<
   (match (G_CONSTANT $a, (i32 0))),
   (apply (G_CONSTANT $a, (i32 42)))>;
 
+// emits a CFPImm because G_FCONSTANT is a special case, like G_CONSTANT. The
+// literal is interpreted as a floating-point value (the pattern grammar has
+// no fp literals), so 42 means 42.0 here.
+def FPImmInstTest1 : GICombineRule<
+  (defs root:$a),
+  (match (G_FCONSTANT $a, (f32 0))),
+  (apply (G_FCONSTANT $a, (f32 42)))>;
+
 def MyCombiner: GICombiner<"GenMyCombiner", [
   InstTest0,
   InstTest1,
-  CImmInstTest1
+  CImmInstTest1,
+  FPImmInstTest1
 ]>;
 
 //      CHECK: const uint8_t *GenMyCombiner::getMatchTable() const {
 // CHECK-NEXT:   constexpr static uint8_t MatchTable0[] = {
-// CHECK-NEXT:     GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2(20), GIMT_Encode2({{[0-9]+}}), /*)*//*default:*//*Label 3*/ GIMT_Encode4([[L579:[0-9]+]]),
-// CHECK-NEXT:     /*TargetOpcode::COPY*//*Label 0*/ GIMT_Encode4([[L462:[0-9]+]]), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0),
-// CHECK-NEXT:     /*TargetOpcode::G_CONSTANT*//*Label 1*/ GIMT_Encode4([[L493:[0-9]+]]), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0),
-// CHECK-NEXT:     /*TargetOpcode::G_ZEXT*//*Label 2*/ GIMT_Encode4({{[0-9]+}}),
-// CHECK-NEXT:     // Label 0: @[[L462]]
-// CHECK-NEXT:     GIM_Try, /*On fail goto*//*Label 4*/ GIMT_Encode4([[L492:[0-9]+]]), // Rule ID 0 //
+// CHECK-NEXT:     GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2(20), GIMT_Encode2({{[0-9]+}}), /*)*//*default:*//*Label 4*/ GIMT_Encode4([[L690:[0-9]+]]),
+// CHECK-NEXT:     /*TargetOpcode::COPY*//*Label 0*/ GIMT_Encode4([[L550:[0-9]+]]), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0),
+// CHECK-NEXT:     /*TargetOpcode::G_CONSTANT*//*Label 1*/ GIMT_Encode4([[L575:[0-9]+]]),
+// CHECK-NEXT:     /*TargetOpcode::G_FCONSTANT*//*Label 2*/ GIMT_Encode4([[L615:[0-9]+]]), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0), GIMT_Encode4(0),
+// CHECK-NEXT:     /*TargetOpcode::G_ZEXT*//*Label 3*/ GIMT_Encode4([[L655:[0-9]+]]),
+// CHECK-NEXT:     // Label 0: @[[L550]]
+// CHECK-NEXT:     GIM_Try, /*On fail goto*//*Label 5*/ GIMT_Encode4([[L574:[0-9]+]]), // Rule ID 0 //
 // CHECK-NEXT:       GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule0Enabled),
 // CHECK-NEXT:       GIM_RootCheckType, /*Op*/1, /*Type*/GILLT_s32,
 // CHECK-NEXT:       // MIs[0] a
@@ -50,10 +60,10 @@ def MyCombiner: GICombiner<"GenMyCombiner", [
 // CHECK-NEXT:       GIR_RootToRootCopy, /*OpIdx*/0, // a
 // CHECK-NEXT:       GIR_AddImm8, /*InsnID*/0, /*Imm*/0,
 // CHECK-NEXT:       GIR_EraseRootFromParent_Done,
-// CHECK-NEXT:     // Label 4: @[[L492]]
+// CHECK-NEXT:     // Label 5: @[[L574]]
 // CHECK-NEXT:     GIM_Reject,
-// CHECK-NEXT:     // Label 1: @[[L493]]
-// CHECK-NEXT:     GIM_Try, /*On fail goto*//*Label 5*/ GIMT_Encode4([[L538:[0-9]+]]), // Rule ID 2 //
+// CHECK-NEXT:     // Label 1: @[[L575]]
+// CHECK-NEXT:     GIM_Try, /*On fail goto*//*Label 6*/ GIMT_Encode4([[L614:[0-9]+]]), // Rule ID 2 //
 // CHECK-NEXT:       GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule2Enabled),
 // CHECK-NEXT:       GIM_RootCheckType, /*Op*/1, /*Type*/GILLT_s32,
 // CHECK-NEXT:       // MIs[0] a
@@ -64,10 +74,24 @@ def MyCombiner: GICombiner<"GenMyCombiner", [
 // CHECK-NEXT:       GIR_RootToRootCopy, /*OpIdx*/0, // a
 // CHECK-NEXT:       GIR_AddCImm, /*InsnID*/0, /*Type*/GILLT_s32, /*Imm*/GIMT_Encode8(42),
 // CHECK-NEXT:       GIR_EraseRootFromParent_Done,
-// CHECK-NEXT:     // Label 5: @[[L538]]
+// CHECK-NEXT:     // Label 6: @[[L614]]
+// CHECK-NEXT:     GIM_Reject,
+// CHECK-NEXT:     // Label 2: @[[L615]]
+// CHECK-NEXT:     GIM_Try, /*On fail goto*//*Label 7*/ GIMT_Encode4([[L654:[0-9]+]]), // Rule ID 3 //
+// CHECK-NEXT:       GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule3Enabled),
+// CHECK-NEXT:       GIM_RootCheckType, /*Op*/1, /*Type*/GILLT_s32,
+// CHECK-NEXT:       // MIs[0] a
+// CHECK-NEXT:       // No operand predicates
+// CHECK-NEXT:       GIM_CheckLiteralInt, /*MI*/0, /*Op*/1, GIMT_Encode8(0),
+// CHECK-NEXT:       // Combiner Rule #3: FPImmInstTest1
+// CHECK-NEXT:       GIR_BuildRootMI, /*Opcode*/GIMT_Encode2(TargetOpcode::G_FCONSTANT),
+// CHECK-NEXT:       GIR_RootToRootCopy, /*OpIdx*/0, // a
+// CHECK-NEXT:       GIR_AddCFPImm, /*InsnID*/0, /*Type*/GILLT_s32, /*Imm*/GIMT_Encode8(42),
+// CHECK-NEXT:       GIR_EraseRootFromParent_Done,
+// CHECK-NEXT:     // Label 7: @[[L654]]
 // CHECK-NEXT:     GIM_Reject,
-// CHECK-NEXT:     // Label 2: @{{[0-9]+}}
-// CHECK-NEXT:     GIM_Try, /*On fail goto*//*Label 6*/ GIMT_Encode4([[L578:[0-9]+]]), // Rule ID 1 //
+// CHECK-NEXT:     // Label 3: @[[L655]]
+// CHECK-NEXT:     GIM_Try, /*On fail goto*//*Label 8*/ GIMT_Encode4([[L689:[0-9]+]]), // Rule ID 1 //
 // CHECK-NEXT:       GIM_CheckSimplePredicate, GIMT_Encode2(GICXXPred_Simple_IsRule1Enabled),
 // CHECK-NEXT:       // MIs[0] a
 // CHECK-NEXT:       // No operand predicates
@@ -80,9 +104,9 @@ def MyCombiner: GICombiner<"GenMyCombiner", [
 // CHECK-NEXT:       GIR_RootToRootCopy, /*OpIdx*/0, // a
 // CHECK-NEXT:       GIR_AddSimpleTempRegister, /*InsnID*/0, /*TempRegID*/0,
 // CHECK-NEXT:       GIR_EraseRootFromParent_Done,
-// CHECK-NEXT:     // Label 6: @[[L578]]
+// CHECK-NEXT:     // Label 8: @[[L689]]
 // CHECK-NEXT:     GIM_Reject,
-// CHECK-NEXT:     // Label 3: @[[L579]]
+// CHECK-NEXT:     // Label 4: @[[L690]]
 // CHECK-NEXT:     GIM_Reject,
 // CHECK-NEXT:     }; // Size: {{[0-9]+}} bytes
 // CHECK-NEXT:   return MatchTable0;
diff --git a/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-errors.td b/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-errors.td
index 4f1b4283458ba..5abfd02b6ffee 100644
--- a/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-errors.td
+++ b/llvm/test/TableGen/GlobalISelCombinerEmitter/pattern-errors.td
@@ -174,6 +174,13 @@ def output_imm_must_be_typed : GICombineRule<
   (match (COPY $x, (i32 0)):$d),
   (apply (G_CONSTANT $x, 0):$d)>;
 
+// CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: 'G_FCONSTANT' immediate must be typed!
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: note: while emitting pattern 'd' (G_FCONSTANT)
+def output_fpimm_must_be_typed : GICombineRule<
+  (defs root:$x),
+  (match (COPY $x, (f32 0)):$d),
+  (apply (G_FCONSTANT $x, 0):$d)>;
+
 // CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: 'G_BUILD_VECTOR' expected at least 2 operands, got 1
 // CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(G_BUILD_VECTOR ?:$x)'
 def too_few_ops_for_variadic : GICombineRule<
@@ -339,6 +346,7 @@ def MyCombiner: GICombiner<"GenMyCombiner", [
   bad_imm_not_a_valuetype,
   output_imm_cannot_be_named,
   output_imm_must_be_typed,
+  output_fpimm_must_be_typed,
   too_few_ops_for_variadic,
   expected_op_name,
   bad_mo_type_not_a_valuetype,



More information about the llvm-commits mailing list