[llvm] r286107 - [Thumb1] Move padding earlier when synthesizing TBBs off of the PC

James Molloy via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 7 05:38:21 PST 2016


Author: jamesm
Date: Mon Nov  7 07:38:21 2016
New Revision: 286107

URL: http://llvm.org/viewvc/llvm-project?rev=286107&view=rev
Log:
[Thumb1] Move padding earlier when synthesizing TBBs off of the PC

When the base register (register pointing to the jump table) is the PC, we expect the jump table to directly follow the jump sequence with no intervening padding.

If there is intervening padding, the calculated offsets will not be correct. One solution would be to account for any padding in the emitted LDRB instruction, but at the moment we don't support emitting MCExprs for the load offset.

In the meantime, it's correct and only a slight amount worse to just move the padding up, from just before the jump table to just before the jump instruction sequence. We can do that by emitting code alignment before the jump sequence, as we know the number of instructions in the sequence is always 4.

Modified:
    llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp
    llvm/trunk/test/CodeGen/ARM/arm-position-independence-jump-table.ll

Modified: llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp?rev=286107&r1=286106&r2=286107&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMAsmPrinter.cpp Mon Nov  7 07:38:21 2016
@@ -1741,6 +1741,14 @@ void ARMAsmPrinter::EmitInstruction(cons
       //    LSLS idx, #1
       //    ADDS pc, pc, idx
 
+      // When using PC as the base, it's important that there is no padding
+      // between the last ADDS and the start of the jump table. The jump table
+      // is 4-byte aligned, so we ensure we're 4 byte aligned here too.
+      //
+      // FIXME: Ideally we could vary the LDRB index based on the padding
+      // between the sequence and jump table, however that relies on MCExprs
+      // for load indexes which are currently not supported.
+      OutStreamer->EmitCodeAlignment(4);
       EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr)
                                        .addReg(Idx)
                                        .addReg(Idx)

Modified: llvm/trunk/test/CodeGen/ARM/arm-position-independence-jump-table.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/arm-position-independence-jump-table.ll?rev=286107&r1=286106&r2=286107&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/arm-position-independence-jump-table.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/arm-position-independence-jump-table.ll Mon Nov  7 07:38:21 2016
@@ -85,7 +85,7 @@ lab4:
 ; THUMB2: [[LBB4]]
 ; THUMB2-NEXT: b exit4
 
-
+; THUMB1: .p2align 2
 ; THUMB1: add     r[[x:[0-9]+]], pc
 ; THUMB1: ldrb    r[[x]], [r[[x]], #4]
 ; THUMB1: lsls    r[[x]], r[[x]], #1




More information about the llvm-commits mailing list