This is an archive of the discontinued LLVM Phabricator instance.

SelectionDAG: Match min/max if the scalar operation is legal
ClosedPublic

Authored by arsenm on Oct 23 2015, 8:27 PM.

Diff Detail

Event Timeline

arsenm updated this revision to Diff 38293.Oct 23 2015, 8:27 PM
arsenm retitled this revision from to SelectionDAG: Match min/max if the scalar operation is legal.
arsenm updated this object.
arsenm added a reviewer: jmolloy.
arsenm added a subscriber: llvm-commits.

Can you please explain the logic behind this change?

Can you please explain the logic behind this change?

This min/max pattern matching is weird because it's done in SelectionDAGBuilder. It won't match for any vector if the vector operation isn't legal. AMDGPU only has vector loads and stores, and every operation is scalar, so we only care about the legality of the scalar operations.

Can you please explain the logic behind this change?

This min/max pattern matching is weird because it's done in SelectionDAGBuilder. It won't match for any vector if the vector operation isn't legal. AMDGPU only has vector loads and stores, and every operation is scalar, so we only care about the legality of the scalar operations.

Okay, I think this makes sense: You have legal vector types, but few legal vector operations (only memory accesses). We do MIN/MAX matching during SDAGBuilder, and so if you don't have a vector MIN/MAX operation, but you have vector operations representing a MIN/MAX operation, and you do have a MIN/MAX on the scalar types, then it will be scalarized regardless, and you want it to be scalarized into scalar MINs/MAXs, instead of being scalarized into some collection of other operations.

Please add more-verbose commentary explaining what is going on. Also, I think the implementation needs to deal with promotions in order to work as intended in all cases. The question you're asking is: Is the operation on this type legal, or will it be legal after the operation is legalized. To do this, you need to call getOperationAction, and if you get back Promote, call it again with the promoted-to type. You can get the type by calling getTypeToPromoteTo.

arsenm updated this revision to Diff 42493.Dec 10 2015, 7:12 PM

Change existing loop with getTypeToTransformTo to find final type. Try to use the scalar operation if VSELECT is illegal.

hfinkel accepted this revision.Dec 10 2015, 7:18 PM
hfinkel added a reviewer: hfinkel.

LGTM.

This revision is now accepted and ready to land.Dec 10 2015, 7:18 PM
arsenm closed this revision.Dec 11 2015, 3:20 PM

r255388