[X86] DAG Combine - VSELECT

Hi @ll,

I am wondering about the use of !isBeforeLegalize in PerformSELECTCombine in the X86 backend. This defers all VSELECT related DAG combines until after the Legalizer has run. If the IR has already only legal types the second round of DAG combines is skipped and no VSELECT specified optimizations are performed at all.

Is there a reason we don’t run the X86 DAG combiner before Type Legalization?

Thanks

Cheers,
Juergen

I think the code in question is using isBeforeLegalize as a shortcut for
"are all the operand and result types legal".

-Eli

I see. We still can use that shortcut to catch the simple case after type legalization, but we could also do a more elaborate type check before type legalization to enable it?

I see. We still can use that shortcut to catch the simple case after type
legalization, but we could also do a more elaborate type check before type
legalization to enable it?

If you're going to write the code to check the types anyway, it's probably
clearer to remove the isBeforeLegalize check.

-Eli

Can this optimization be moved to the lowering phase? LowerVSELECT() ?

  • Elena

Unfortunately not :frowning: By that time SETCC has already been lowered to a sequence of several instructions and a target specific X86ISD Compare Node. Finding the SETCC/VSELECT pattern early on in DAG Combine before SETCC has been lowered is easier and also simpler to match.

Cheers,
Juergen

Sorry, took me a little longer to come back to this.

The attached patch enables X86 VSELECT DAG combines before DAG type legalization.

Cheers,
Juergen

X86DAGCombine.diff (3.69 KB)