[PATCH] Implement ADRP CSE for global symbols

Jiangning Liu liujiangning1 at gmail.com
Sun Apr 27 20:48:08 PDT 2014


Hi Quentin,

> Is in fact, syntax A
> adrp r0, MergedGlobal at PAGE
> load [r0, MergedGlobal at PAGEOFF+var1_offset]
> load [r0, MergedGlobal at PAGEOFF+var2_offset]
> load [r0, MergedGlobal at PAGEOFF+var3_offset]
>
> Or put another way, syntax B
> adrp r0, MergedGlobal at PAGE
> load [r0, MergedGlobal_var1 at PAGEOFF]
> load [r0, MergedGlobal_var2 at PAGEOFF]
> load [r0, MergedGlobal_var3 at PAGEOFF]
>
> For syntax A to be valid, you need to be sure that MergedGlobal at PAGEOFF+varX_offset fits the encoding space.
> For syntax B to be valid, you need to be sure that MergedGlobal at PAGE == MergedGlobal_varX at PAGE.
>
> Thus, in both cases, this is not generally correct.

If we don't set MergedGlobal's alignment to RoundUpToPowerOfTwo(sizeof(MergedGlobal)), both syntax A and B are incorrect.

But if we set MergedGlobal's alignment to RoundUpToPowerOfTwo(sizeof(MergedGlobal)), both syntax A and B should be correct. i.e. For syntax A, it can guarantee  (MergedGlobal at PAGEOFF+varX_offset)<4096, which meet the encoding requirement of load/store instructions. For syntax B, it can guarantee MergedGlobal at PAGE==MergedGlobal_varX at PAGE is true. 

>
> To increase the likelihood of this being correct, you’ll need to align the thing on a PAGE, and make sure that the reachable fields are within the encoding space (this should be fine, because of the get max offset thing). I’d say that is not desirable.

We don't really need to make MergedGlobal aligned to a PAGE, but asking MergedGlobal aligned to RoundUpToPowerOfTwo(sizeof(MergedGlobal)) is enough.
If you don't think this is true, can you give me a negative example?

Thanks,
-Jiangning

>
> Therefore, I think we need to go for approach #1.
> That said, if we can set an alignment that makes sense, that sounds good. In fact, for external globals, we may have to produce an accurate alignment for external users to get what they expect based on the original alignment of each field.

http://reviews.llvm.org/D3432






More information about the llvm-commits mailing list