DAG optimization and lowering algorithm

Hi,

I'm trying to build code for very short function and I encounter with a problem (or bug) in DAG selection algotithm.
I have a node that was created in Combine(BeforeLegalizeTypes) and should be optimized in Combine(AfterLegalizeTypes). But LegalizeTypes() did not change anything and Combine(AfterLegalizeTypes) was not called.
Vector legalization that comes afterwards just scalarized the operation.

SelectionDAGISel::CodeGenAndEmitDAG()
..
   CurDAG->Combine(BeforeLegalizeTypes, *AA, OptLevel);

   bool Changed;
   Changed = CurDAG->LegalizeTypes();

   if (Changed) {
      CurDAG->Combine(AfterLegalizeTypes, *AA, OptLevel);
    }

The problem does not exist if the function is bigger and something was changed on LegalizeTypes() stage.

I think that Combine(AfterLegalizeTypes) should be called anyway, even if LegalizeTypes() did not change anything.

- Elena

We skip the extra run as a performance optimization... we really don't
want extra runs of DAGCombine if we can avoid it. If there is some
optimization that currently only runs after type legalization, perhaps
we can change it?

-Eli

At the beginning, I have the following chain: LOAD -> TRUNCATE -> ZERO_EXTEND.
After Combine(BeforeLegalizeTypes) the optimization of ZERO_EXTEND gives me the new chain LOAD -> ANY_EXTEND -> AND.

I want to optimize ANY_EXTEND but is not analyzed in the same Combine().

Combine(AfterLegalizeTypes) is no called at all.

- Elena

Hi Elena,

I'm trying to build code for very short function and I encounter with a problem (or bug) in DAG selection algotithm.
I have a node that was created in Combine(BeforeLegalizeTypes) and should be optimized in Combine(AfterLegalizeTypes).

why all these restrictions? What is the node, what created it, and what do you
want done with it?

Ciao, Duncan.

  But LegalizeTypes() did not change anything and Combine(AfterLegalizeTypes) was not called.

That sounds like it's just a matter of making sure we don't forget to
add the ANY_EXTEND to the worklist. We don't need a whole additional
DAGCombine run for that.

-Eli

One of possible solutions is running Combine() for full DAG cycle after cycle while anything is changed.

And remember that if we plan to optimize something after type legalization and before operation legalization
if (DCI.isBeforeLegalizeOps()) && !DCI.isBeforeLegalize()) {
..
}

The function may not be called at all.

- Elena