During rule optimization, identical SameOperandMatchers are hoisted into a common group,
however previously only one operand index was considered.
Commutable patterns can introduce SameOperandMatcher checks where the second index is commuted,
resulting in a different check that cannot be hoisted.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/test/TableGen/GlobalISelEmitterMatchTableOptimizerSameOperand-invalid.td | ||
---|---|---|
17 | 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. The safest way would be to forbid hoisting SameOperandMatchers altogether. |
llvm/test/TableGen/GlobalISelEmitterMatchTableOptimizerSameOperand-invalid.td | ||
---|---|---|
17 | Just to make sure I understand correctly: what you're saying is this patch fixes one problem but there are others that need to be fixed as well, but this is orthogonal to this patch. Is that right? |
llvm/test/TableGen/GlobalISelEmitterMatchTableOptimizerSameOperand-invalid.td | ||
---|---|---|
17 | Exactly. This patch fixes the issue where two SameOperandMatchers are considered identical, although they are not. The other issue that is not addressed yet is that the table optimizer will hoist identical checks, even though it might not always be safe to do so. I'll try to come up with a patch for that in a follow-up. |
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 SameOperandMatchers altogether.
Anyone have a better idea?