[PATCH] Don't access items in .sdata section using gp-relative addressing when target is NaCl.

Sasa Stankovic Sasa.Stankovic at imgtec.com
Tue Jun 17 16:31:48 PDT 2014


> Would it make sense to turn off use of sdata by default, and have it only enabled by a compiler flag or llc flag?  That would be cleaner and is not very difficult to do.  It should come with a warning like "this is an optimisation that might cause moderate-sized programs to fail to link".

This is what Mips gcc for Linux does - gp-relative addressing is not enabled by default, but it can be requested at command line (gcc doesn't issue a warning though). I also tested a bare-metal Mips gcc toolchain, and it has different behavior - gp-relative addressing is enabled by default. I'll ask Daniel Sanders (LLVM code owner for MIPS backend) whether we should add a command line flag for this.

> BTW, have you looked at the GlobalMerge pass (lib/Transforms/Scalar/GlobalMerge.cpp)?  That is used on ARM and gives a similar kind of optimisation to the MIPS sdata section.  It will reuse the computation of a base address within the data segment for multiple variables, rather than computing a data segment address for each variable that's referenced.  GlobalMerge is a more robust way of doing this optimisation than sdata, though it only works when the referenced variables are within the same compilation unit being compiled by llc.

I enabled this pass for Mips and experimented with it by running some tests. When the pass changes the code, it usually does create smaller code. But there are also cases when the pass actually produces larger code. I'll do more investigation on this.

http://reviews.llvm.org/D4069






More information about the llvm-commits mailing list