[PATCH] D32563: Improve code placement algorithm in Reassociate pass.

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 27 17:01:35 PDT 2017


Dehao mentioned to me that the patch does reorder the operands -- I think
this part of the change is wrong -- as it defeats the original purpose of
reassociation.

On Thu, Apr 27, 2017 at 4:42 PM, Daniel Berlin <dberlin at dberlin.org> wrote:

>
>> > Maybe?
>> >
>> > Remember that this reassociate has *zero* global view of expressions.
>> > It only makes locally good choices.
>> >
>> > IE given:
>> >      bar(a + b);
>> >      bar((a + 2) + b);
>> >
>> >
>> > This reassociate will process the a + b and a + 2 + b separately,
>>
>> This patch will not change the original handling of this case because
>> both a and b has >1 uses.
>>
>>
> Sure, i was just pointing out it is only handling local tree-level stuff,
> and the way it forms trees will not necessarily guarantee that the overall
> live range of the values is reduced (precisely because the trees it forms
> do not contain all uses).
>
> IE it is guaranteed to try to shrink a live range locally, and either
> succeed or do nothing.
> That may or may not shrink a live range globally, and may increase the
> live range locally.
>
>
> IE
>        A
>         |
> A     |
> |       |
> |       |
> A      A
>
> A
> |
> |
> A
>
> ->
>
> A
> |
> |
> A   A
>       |
>       |
> A   A
> |
> |
> A
>
>
> This has shrunk the live range of A locally, but made it worse globally.
>
>

But at any program point, the max register pressure of the before case is
2, the after case is 1?

The placement part of the patch does this

before

o1     o2
 |      |
 |      |
 |      |   o3  o4
 |      |    |   |
 |      |    |   |    o5   o6
 |      |    |   |    |    |
    C1       |   |    |    |
    |        |   |    |    |
    |          C2       C3
    |           |        |
                I

After

  o1   o2
   |   |
     C1
     |    o3   o4
     |     |    |
     |       C2    o5    o6
     |        |    |      |
     |        |       C3
     |        |        |
     |        |        |
     |        |        |
              I

The max register pressure is reduced from 6 to 4 in this region.

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170427/57f322bd/attachment.html>


More information about the llvm-commits mailing list