Folding nodes in instruction selection - please review

Demikhovsky, Elena elena.demikhovsky at intel.com
Sun Jul 14 00:19:25 PDT 2013


Hi Jakob,

Thank you for the explanations. Does it mean that such optimization I can do only on PeepholeOptimizer?


-  Elena


-----Original Message-----
From: Jakob Stoklund Olesen [mailto:stoklund at 2pi.dk] 
Sent: Thursday, July 11, 2013 19:21
To: Demikhovsky, Elena
Cc: llvm-commits at cs.uiuc.edu; Nadav Rotem
Subject: Re: Folding nodes in instruction selection - please review


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

---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.





More information about the llvm-commits mailing list