[PATCH] D111506: [GlobalISel][Tablegen] Fix SameOperandMatcher's isIdentical check

Konstantin Schwarz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 22 07:55:35 PDT 2021


kschwarz added inline comments.


================
Comment at: llvm/test/TableGen/GlobalISelEmitterMatchTableOptimizerSameOperand-invalid.td:16
+// CHECK-NEXT:        GIM_CheckRegBankForClass, /*MI*/0, /*Op*/0, /*RC*/MyTarget::GPR32RegClassID,
+// CHECK-NEXT:        GIM_CheckIsSameOperand, /*MI*/0, /*OpIdx*/3, /*OtherMI*/2, /*OtherOpIdx*/2,
+// CHECK-NEXT:        GIM_Try, /*On fail goto*//*Label 2*/ 108, // Rule ID 1 //
----------------
Even with the fix for the `isSameOperand` predicate, we can still have a situation where hoisting the check is not correct.

In this case, the optimizer finds that the operand checks are indeed identical, and hoists the check into a common block.
However, the check will unconditionally access operand index 2 of `/*OtherMI*/2`.
If the input GMIR does not have three operands in `/*OtherMI*/2`, this will crash.

The safest way would be to forbid hoisting `SameOperandMatcher`s altogether.
Anyone have a better idea?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111506/new/

https://reviews.llvm.org/D111506



More information about the llvm-commits mailing list