[PATCH] D38333: [X86] Fix using the SJLJ jump table on x86_64

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 28 13:59:33 PDT 2017


mstorsjo added inline comments.


================
Comment at: lib/Target/X86/X86ISelLowering.cpp:26605
+          .addImm(4)
+          .addReg(IReg64)
+          .addImm(0)
----------------
mstorsjo wrote:
> If building with optimizations, this works as intended. If building without optimizations, this actually uses another, uninitialized register here instead of IReg expanded to 64 bit (as done with `TargetOpcode::COPY` above). Does anybody happen to have a hint about why that happens?
In particular, this issue seems to happen when the value gets spilled onto the stack. Originally the value (IReg) was loaded in eax, but then was spilled onto the stack, reloaded in ecx, but then IReg64 is used as rdx, which actually doesn't contain the intended value.

So without optimization, this gets compiled into:

```
        movl    -304(%rbp), %eax
        cmpl    $9, %eax
        movl    %eax, -448(%rbp)        # 4-byte Spill
        jae     .LBB4_26
# BB#25:                                #   in Loop: Header=BB4_24 Depth=1
        leaq    .LJTI4_0(%rip), %rax    
        movl    -448(%rbp), %ecx        # 4-byte Reload - into ecx now
        movl    (%rax,%rdx,4), %ecx   # This uses rdx instead of rcx which contains the value we want
        movslq  %ecx, %rdx
        addq    %rax, %rdx
        movl    %ecx, -448(%rbp)        # 4-byte Spill
        jmpq    *%rdx
```


https://reviews.llvm.org/D38333





More information about the llvm-commits mailing list