Folding nodes in instruction selection - please review

Jakob Stoklund Olesen stoklund at 2pi.dk
Thu Jul 11 09:21:07 PDT 2013


On Jul 11, 2013, at 6:04 AM, Demikhovsky, Elena <elena.demikhovsky at intel.com> wrote:

> I'm trying to do a slightly different thing, but not correctly explained myself.
> Let's forget about loads, I just have the following graph:
> 
>           A 
>           |
>           B
>      /       \
>    C1      C2
> 
> And I have the patterns:
> 
> def : Pat<( (C1 $src1, (B $src2, (A $src3))),
>            (D1 $src1, $src2, $src3)>;
> 
> def : Pat<( (C2 $src1, (B $src2, (A $src3))),
>            (D2 $src1, $src2, $src3)>;
> 
> (C1 (B ..(A))) may be replaced with D1
> (C2 (B ..(A))) may be replaced with D2
> 
> How does  it work? 
> At OPC_CheckFoldableChainNode it checks whether A may be folded in D1. But B has multiple uses and the automatic answer in this case is "not". 
> I want to take "HasMultipleUses" to target specific analysis and check opcodes there. The default behavior will not be changed.
> 
>    case OPC_CheckFoldableChainNode: {
>      assert(NodeStack.size() != 1 && "No parent node");
>      // Verify that all intermediate nodes between the root and this one have
>      // a single use.
>      bool HasMultipleUses = false;
>      for (unsigned i = 1, e = NodeStack.size()-1; i != e; ++i)
>        if (!NodeStack[i].hasOneUse()) {
>          HasMultipleUses = true;
>          break;
>        }
>      if (HasMultipleUses) break;  // << I want to replace this "break" with more deep target specific analysis.

Hi Elena,

This transformation is not safe. If any of those chained nodes have multiple uses, they are going to be duplicated when the other uses are matched. That causes the DAG chains to become inconsistent, and the DAG is no longer correct.

The check for multiple uses is not an optimization, it is for correctness.

Thanks,
/jakob




More information about the llvm-commits mailing list