Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22272

Why do GCC and Clang stop using RIP relative loads for arrays bigger than 16MB?

$
0
0

My understanding is that RIP relative addressing should work for offsets up to 2GB in size, but for some reason GCC (14.2) and Clang (19.1.0) stop using it when grabbing values more than 16MB away.

Given this code:

const int size = 1 << 22;int small_array[size];// 6 byte movint load_small_arry() {    return small_array[(sizeof(small_array)/sizeof(int)-1)];}int big_array[size + 1];// 5 byte mov + 6 byte mov in clang// 9 byte mov in gccint load_big_arry() {    return big_array[(sizeof(big_array)/sizeof(int)-1)];}

I get this assembly from GCC (see clang results in godbolt link, different but still switches away from rip relative):

load_small_arry(): mov    eax,DWORD PTR [rip+0x0]        # 6 <load_small_arry()+0x6>    R_X86_64_PC32 small_array+0xfffff8 ret nop    WORD PTR [rax+rax*1+0x0]load_big_arry(): movabs eax,ds:0x0    R_X86_64_64 big_array+0x1000000 ret

This is a larger encoding so I'm not sure why it would be preferred.

Godbolt link


Viewing all articles
Browse latest Browse all 22272

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>