[GlobalIsSel] Allow using PatFrags with multiple defs as the root of a combine rule

I had to tighten the restrictions on PatFrags a bit to make it consistent: instructions that
define the root of a PF can only have one def.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D157700

GitOrigin-RevId: 0a59e1a85c3bfd6e9d904899901d48458356cb0c
diff --git a/test/TableGen/GlobalISelCombinerMatchTableEmitter/patfrag-errors.td b/test/TableGen/GlobalISelCombinerMatchTableEmitter/patfrag-errors.td
index fba501c..008a066 100644
--- a/test/TableGen/GlobalISelCombinerMatchTableEmitter/patfrag-errors.td
+++ b/test/TableGen/GlobalISelCombinerMatchTableEmitter/patfrag-errors.td
@@ -257,6 +257,20 @@
   (match (TypedParams $dst, i64:$k):$broken),
   (apply (COPY $dst, (i32 0)))>;
 
+// CHECK: :[[@LINE+2]]:{{[0-9]+}}: error: all instructions that define root 'foo' in 'RootDefHasMultiDefs' can only have a single output operand
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Could not parse GICombinePatFrag 'RootDefHasMultiDefs'
+def RootDefHasMultiDefs: GICombinePatFrag<
+    (outs root:$foo),
+    (ins gi_imm:$cst),
+    [
+      (pattern (G_UNMERGE_VALUES $foo, $z, $y))
+    ]>;
+// CHECK: :[[@LINE+1]]:{{[0-9]+}}: error: Failed to parse pattern: '(RootDefHasMultiDefs ?:$root, (i32 10))'
+def root_def_has_multi_defs : GICombineRule<
+  (defs root:$root),
+  (match (RootDefHasMultiDefs $root, (i32 10))),
+  (apply (COPY $root, (i32 0)))>;
+
 // CHECK: error: Failed to parse one or more rules
 
 def MyCombiner: GICombinerHelper<"GenMyCombiner", [
@@ -278,5 +292,6 @@
   expected_mo_namedimm,
   patfrag_in_apply,
   patfrag_cannot_be_root,
-  inconsistent_arg_type
+  inconsistent_arg_type,
+  root_def_has_multi_defs
 ]>;