[GlobalISel] Predicated TImmLeafs in patterns


I'm trying to use predicated TImmLeafs in TableGen patterns with GlobalISel to select intrinsics with immediate operands. While this is working so far, contrary to ImmLeafs the predicate does not seem to get checked. Is this not supported yet?

This is the pattern in question:

def tuimm9 : TImmLeaf<i32, [{ return isUInt<9>(Imm); }]>;
def : Pat<(int_target_foo tuimm9:$mask), (FOO tuimm9:$mask)>;

Match table when using TImmLeaf:


Match table when using ImmLeaf:

GIM_CheckOpcode, /*MI*/1, TargetOpcode::G_CONSTANT,
GIM_CheckI64ImmPredicate, /*MI*/1, /*Predicate*/GIPFP_I64_Predicate_uimm9,

Basically I'm wondering how I can make TableGen generate the GIM_CheckI64ImmPredicate when using TImmLeafs.



Hi Dominik,

Are you sure that Pat is being imported? TImmLeaf is a subclass of ImmLeaf/PatFrag/PatFrags so there needs to be an equivalent predicate check in the GISelPredicateCode field to be imported. IntImmLeaf/FPImmLeaf on the other hand can share the same code for DAGISel and GlobalISel because the difference between the two ISel's were abstracted out for those classes.

Hi Daniel,

yep the pattern is being imported. When I investigated this further I noticed that the GISel backend is able to handle TImms, but is not creating any predicates for them. I created https://reviews.llvm.org/D91703 to teach the backend how to create those predicates.



Hmm, it's not immediately obvious why it would be different from PatFrag and the others that already check the predicates. I'll have a look at the patch.