[PATCH] D118676: [RS4GC] Extract rematerilazable candidate search. NFC.

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 2 02:10:26 PST 2022


skatkov added a comment.

Hi Philip, I've tried to consider re-materialization of derived pointers from live range profitability.
Let's our dp = base + Idx *scale + offset.
Let's disp = dp - base = Idx *scale + offset. (this is about your potential proposal to remat all as I've understood it).

Let's we have the following points in a program:
0 Def of Idx and Off
1 Def of dp and probably disp if we consider this case.
2 Call site with statepoint (dp and base should ba alive here)
2.2 Remat of dp close to call site. (If we do re-materialization)
2.8 Remat of dp close to use. (If we do re-materialization)
3 Use of dp.

Now consider 5 scenarios of re-materialization:
A. No re-materialization at all.
B. Remat at call site
C. Remat at use
D. Remat at call site with disp pre-computerd.
E. Remat at call site with disp at use.

What live in different ranges?
[0,1) - Idx and off for A, B, C, D, E.
[1,2) -
A: base, dp
B: Off, Idx, base
C: Off, Idx, base
D: base, disp
E: base, disp
[2, 2.2) - 
A: dp
B: Off, Idx, base
C: Off, Idx, base
D: base, disp
E: base, disp
[2.2, 2.8) - 
A: dp
B: dp
C: Off, Idx, base
D: dp
E: base, disp
[2.8, 3) - only dp for A, B, C, D, E.

So in general case, in terms of liveness, no re-materialization is better than any re-materialization.
And disp case is better than Idx + Off in case both of them are not constant.
But if Idx and Off are constant and disp as a result we get
[0,1) - none
[1,2) -
A: base, dp
B: base
C: base
D: base
E: base
[2, 2.2) - 
A: dp
B: base
C: base
D: base
E: base
[2.2, 2.8) - 
A: dp
B: dp
C: base
D: dp
E: base
[2.8, 3) - only dp for A, B, C, D, E.
So any kind of re-materialization is better than no re-materialization.

So in terms of liveness, re-materialization is profitable if Idx and Off are constants.

However re-materialization has some additional effects.
First of all dp computation may potentially be folded into use and in the case re-materialization may be positive in spite of extend of live range due to we eliminate the derived pointer computation.

Additionally even if do not fold derived pointer into all users we may move the derived pointer computation from hot block to cold one (positive impact) or from cold block to hot block (negative impact).

Taking all above (which possibly misses some corner cases) I would say that re-materialization is profitable if

1. We can fold address computation to all users and Idx and Off are constants.
2. Rematerialization insert point is colder that original derived point computation and Idx and Off are constants.
3. If Idx and Off are not constants, think three times before moving to colder block.

Any thoguhts? Would be very glad to consider this from other angles and continue discussion.
For a while we can land this re-factoring due to it change nothing - NFC.

Sorry for the long comment.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118676/new/

https://reviews.llvm.org/D118676



More information about the llvm-commits mailing list