The linker optimization for pcrel load/store compiler side change has been added by D79864. However, we still failed to perform this optimization for some simple case:
pld 3, m@got@pcrel(0), 1 li 4, 4 stw 4, 0(3) blr
And this is what linker want to do:
10010600: 02 00 10 06 pstw r4,132008 10010604: 04 00 80 38 li r4,4 10010608: a8 03 80 90 1001060c: 00 00 00 60 nop 10010610: 20 00 80 4e blr
The li 4, 4 here disable the optimization as the above transformation is wrong because we are define the r4 in betwwen pld and stw. So, we want to schedule such kind of instructions before the pld to avoid this happens.
It seems to me like this function could be documented a bit better to explain not only what we are doing but why. Of course, this may just be because I am not familiar with the scheduler so the code isn't self-documenting to me.