llvm-6502/lib
Hal Finkel 78ce816d3f [PowerPC] Add extra r2 read deps on @toc@l relocations
If some commits are happy, and some commits are sad, this is a sad commit. It
is sad because it restricts instruction scheduling to work around a binutils
linker bug, and moreover, one that may never be fixed. On 2012-05-21, GCC was
updated not to produce code triggering this bug, and now we'll do the same...

When resolving an address using the ELF ABI TOC pointer, two relocations are
generally required: one for the high part and one for the low part. Only
the high part generally explicitly depends on r2 (the TOC pointer). And, so,
we might produce code like this:

.Ltmp526:
        addis 3, 2, .LC12@toc@ha
.Ltmp1628:
        std 2, 40(1)
        ld 5, 0(27)
        ld 2, 8(27)
        ld 11, 16(27)
        ld 3, .LC12@toc@l(3)
        rldicl 4, 4, 0, 32
        mtctr 5
        bctrl
        ld 2, 40(1)

And there is nothing wrong with this code, as such, but there is a linker bug
in binutils (https://sourceware.org/bugzilla/show_bug.cgi?id=18414) that will
misoptimize this code sequence to this:
        nop
        std     r2,40(r1)
        ld      r5,0(r27)
        ld      r2,8(r27)
        ld      r11,16(r27)
        ld      r3,-32472(r2)
        clrldi  r4,r4,32
        mtctr   r5
        bctrl
        ld      r2,40(r1)
because the linker does not know (and does not check) that the value in r2
changed in between the instruction using the .LC12@toc@ha (TOC-relative)
relocation and the instruction using the .LC12@toc@l(3) relocation.
Because it finds these instructions using the relocations (and not by
scanning the instructions), it has been asserted that there is no good way
to detect the change of r2 in between. As a result, this bug may never be
fixed (i.e. it may become part of the definition of the ABI). GCC was
updated to add extra dependencies on r2 to instructions using the @toc@l
relocations to avoid this problem, and we'll do the same here.

This is done as a separate pass because:
 1. These extra r2 dependencies are not really properties of the
    instructions, but rather due to a linker bug, and maybe one day we'll be
    able to get rid of them when targeting linkers without this bug (and,
    thus, keeping the logic centralized here will make that
    straightforward).
 2. There are ISel-level peephole optimizations that propagate the @toc@l
    relocations to some user instructions, and so the exta dependencies do
    not apply only to a fixed set of instructions (without undesirable
    definition replication).

The test case was reduced with the help of bugpoint, with minimal cleaning. I'm
looking forward to our upcoming MI serialization support, and with that, much
better tests can be created.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237556 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-18 06:25:59 +00:00
..
Analysis Allow min/max detection to see through casts. 2015-05-15 16:04:50 +00:00
AsmParser [opaque pointer type] Use the value type of the GlobalVariable rather than accessing it through the pointee's type 2015-05-13 22:55:01 +00:00
Bitcode [BitcodeReader] Don't allow INSERTVAL/EXTRACTVAL with 0 indices 2015-05-16 00:33:12 +00:00
CodeGen MachineScheduler debug output clarity. 2015-05-17 23:40:31 +00:00
DebugInfo MC: MCCodeGenInfo naming update. NFC. 2015-05-15 19:13:31 +00:00
ExecutionEngine [RuntimeDyld] Use isInt to assert that a relocation didn't overflow 2015-05-15 20:32:25 +00:00
Fuzzer Code cleanup: Reindent Fuzzer::MutateAndTestOne. 2015-05-17 02:44:31 +00:00
IR While in GlobalValue fix the function(s) that don't follow the 2015-05-15 18:20:14 +00:00
IRReader
LineEditor
Linker While in GlobalValue fix the function(s) that don't follow the 2015-05-15 18:20:14 +00:00
LTO LTO: Add API to choose whether to embed uselists 2015-04-27 23:38:54 +00:00
MC MC: Use MCSymbol in RelAndSymbol, NFC 2015-05-16 01:14:19 +00:00
Object Remove MCAssembler.h include from MCStreamer.h and fix users of MCStreamer.h 2015-05-15 22:19:42 +00:00
Option Option parsing: properly handle flag aliases for joined options (PR23394) 2015-05-04 18:00:13 +00:00
Passes [PM] Fixup for r231556 where I missed a dependency on intrinsics 2015-03-07 09:08:20 +00:00
ProfileData InstrProf: Treat functions with a coverage map but no profile as unreached 2015-05-13 22:03:04 +00:00
Support YAML: Add support for literal block scalar I/O. 2015-05-14 23:08:22 +00:00
TableGen [TableGen] Change 'car' to 'head' and 'cdr' to 'tail' in assert comments. These were the old names for these operations long ago. NFC 2015-05-16 05:42:13 +00:00
Target [PowerPC] Add extra r2 read deps on @toc@l relocations 2015-05-18 06:25:59 +00:00
Transforms Reapply r237520 with another fix for infinite looping 2015-05-17 08:27:27 +00:00
CMakeLists.txt [PM] Create a separate library for high-level pass management code. 2015-03-07 09:02:36 +00:00
LLVMBuild.txt Reflow long lines of some LLVMBuild files 2015-05-14 15:38:27 +00:00
Makefile [PM] Create a separate library for high-level pass management code. 2015-03-07 09:02:36 +00:00