This is an archive of the discontinued LLVM Phabricator instance.

[TableGen][SelectionDAG] Use ComplexPattern type for non-leaf nodes
ClosedPublic

Authored by jrtc27 on Aug 31 2021, 5:17 PM.

Details

Summary

When used as a non-leaf node, TableGen does not currently use the type
of a ComplexPattern for type inference, which also means it does not
check it doesn't conflict with the use. This differs from when used as a
leaf value, where the type is used for inference. This addresses that
discrepancy. The test case is not representative of most real-world uses
but is sufficient to demonstrate inference is working.

Some of these uses also make use of ValueTypeByHwMode rather than
SimpleValueType and so the existing type inference is extended to
support that alongside the new type inference.

There are also currently various cases of using ComplexPatterns with an
untyped type, but only for non-leaf nodes. For compatibility this is
permitted, and uses the old behaviour of not inferring for non-leaf
nodes, but the existing logic is still used for leaf values. This
remaining discrepancy should eventually be eliminated, either by
removing all such uses of untyped so the special case goes away (I
imagine Any, or a more specific type in certain cases, would be
perfectly sufficient), or by copying it to the leaf value case so
they're consistent with one another if this is something that does need
to keep being supported.

All non-experimental targets have been verified to produce bit-for-bit
identical TableGen output with this change applied, provided my existing
patches to fix the use of ComplexPatterns in the AArch64 and AMDGPU
backends are applied.

Diff Detail

Event Timeline

jrtc27 created this revision.Aug 31 2021, 5:17 PM
jrtc27 requested review of this revision.Aug 31 2021, 5:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2021, 5:17 PM
kparzysz added a comment.EditedSep 1 2021, 11:04 AM

Edit: this comment is about AArch64. I didn't try to see if there are any other compilation errors.

This fails to build because SVDup0 is a complex pattern defined with type i64, but it's used in places that require vectors:

def SVEDup0 : ComplexPattern<i64, 0, "SelectDupZero", []>;
def SVEDup0Undef : ComplexPattern<i64, 0, "SelectDupZeroOrUndef", []>;

and

multiclass SVE_SETCC_Pat_With_Zero<CondCode cc, CondCode invcc, ValueType predvt,
                                   ValueType intvt, Instruction cmp> {
  def : Pat<(predvt (AArch64setcc_z predvt:$Op1, intvt:$Op2, (SVEDup0), cc)),
            (cmp $Op1, $Op2)>;
  def : Pat<(predvt (AArch64setcc_z predvt:$Op1, (SVEDup0), intvt:$Op2, invcc)),
            (cmp $Op1, $Op2)>;
}

Looks good to me otherwise.

This fails to build because SVDup0 is a complex pattern defined with type i64, but it's used in places that require vectors:

def SVEDup0 : ComplexPattern<i64, 0, "SelectDupZero", []>;
def SVEDup0Undef : ComplexPattern<i64, 0, "SelectDupZeroOrUndef", []>;

and

multiclass SVE_SETCC_Pat_With_Zero<CondCode cc, CondCode invcc, ValueType predvt,
                                   ValueType intvt, Instruction cmp> {
  def : Pat<(predvt (AArch64setcc_z predvt:$Op1, intvt:$Op2, (SVEDup0), cc)),
            (cmp $Op1, $Op2)>;
  def : Pat<(predvt (AArch64setcc_z predvt:$Op1, (SVEDup0), intvt:$Op2, invcc)),
            (cmp $Op1, $Op2)>;
}

Looks good to me otherwise.

Yes, this turned up a bunch of cases where the types were wrong (as you would expect, though fewer than I feared); you'll need all 3 parent revisions listed under Stack for it to both build (the first AArch64 revision) and not crash in various CodeGen tests (the AMDGPU revision and other AArch64 one).

kparzysz accepted this revision.Sep 1 2021, 11:18 AM
This revision is now accepted and ready to land.Sep 1 2021, 11:18 AM
This revision was landed with ongoing or failed builds.Dec 2 2021, 11:05 PM
This revision was automatically updated to reflect the committed changes.