[llvm-dev] GlobalISel and commutative binops in Pat?

Björn Pettersson A via llvm-dev llvm-dev at lists.llvm.org
Wed Apr 21 03:08:31 PDT 2021


Hi!

I'm working on porting an OOT-target to use GlobalISel.

One thing that I've noticed is that if I for example have a Pat like this

  def : Pat<(add i16:$reg, MyImmLeaf:$imm), (add16 i16:$src, imm:$imm)>;

it only matches if the G_ADD has the immediate operand as the second operand.


Here are some questions related to that:

1) I've been trying to use the generic pre/post legalize combiner, but I can't see that any canonicalization related to putting the immediate as second operand happens (I think it is something that the DAGCombiner would do).
Is this something not-yet-implemented that we want to do?

2) Isn't the old SelectionDAG ISel automatically handling matching during selection for commutative SDNodes? So even without any prior canonicalization the matcher should handle this. I mean, in general a commutative operation could take two predicated non-leaf operands, so we can't solve all kinds combinations using canonicalization.
Is this something not-yet-implemented in the GISel matcher that we want to do?


Maybe I've simply missed something, or is doing something wrong as this currently fails for me. Adding all the commutative patterns as new definitions might be a lot of work for any target, so I suppose this should work out-of-the-box somehow.

/Björn


More information about the llvm-dev mailing list