[llvm] r236327 - ARM: Align functions containing Thumb-2 jump tables to 4 bytes.

Peter Collingbourne peter at pcc.me.uk
Fri May 1 11:05:59 PDT 2015


Author: pcc
Date: Fri May  1 13:05:59 2015
New Revision: 236327

URL: http://llvm.org/viewvc/llvm-project?rev=236327&view=rev
Log:
ARM: Align functions containing Thumb-2 jump tables to 4 bytes.

Functions with jump tables need an alignment of 4 because they use the ADR
instruction, which aligns the PC to 4 bytes before adding an offset.

Differential Revision: http://reviews.llvm.org/D9424

Modified:
    llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp
    llvm/trunk/test/CodeGen/ARM/thumb-alignment.ll

Modified: llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp?rev=236327&r1=236326&r2=236327&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp Fri May  1 13:05:59 2015
@@ -423,6 +423,10 @@ bool ARMConstantIslands::runOnMachineFun
   CPEMIs.clear();
   DEBUG(dumpBBs());
 
+  // Functions with jump tables need an alignment of 4 because they use the ADR
+  // instruction, which aligns the PC to 4 bytes before adding an offset.
+  if (!T2JumpTables.empty())
+    MF->ensureAlignment(2);
 
   /// Remove dead constant pool entries.
   MadeChange |= removeUnusedCPEntries();

Modified: llvm/trunk/test/CodeGen/ARM/thumb-alignment.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/thumb-alignment.ll?rev=236327&r1=236326&r2=236327&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/thumb-alignment.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/thumb-alignment.ll Fri May  1 13:05:59 2015
@@ -13,3 +13,42 @@ define i32* @foo() {
 define i32* @bar() {
   ret i32* zeroinitializer
 }
+
+ at a = external global i32
+ at b = external global i32
+ at c = external global i32
+ at d = external global i32
+
+; Create a Thumb-2 jump table, which should force alignment to 4 bytes.
+
+; CHECK: .globl	baz
+; CHECK-NEXT: .align	2
+; CHECK: adr.w
+define i32 @baz() {
+  %1 = load i32, i32* @c, align 4
+  switch i32 %1, label %7 [
+    i32 1, label %2
+    i32 4, label %5
+    i32 9, label %5
+    i32 3, label %8
+  ]
+
+; <label>:2
+  %3 = load i32, i32* @a, align 4
+  %4 = tail call i32 bitcast (i32 (...)* @fn2 to i32 (i32 (...)*, i32, i32)*)(i32 (...)* bitcast (i32 ()* @baz to i32 (...)*), i32 0, i32 %3) #2
+  br label %8
+
+; <label>:5
+  %6 = load i32, i32* @d, align 4
+  store i32 %6, i32* @b, align 4
+  br label %8
+
+; <label>:7
+  br label %8
+
+; <label>:8
+  %e.0 = phi i32 [ 1, %7 ], [ 1, %2 ], [ 0, %0 ], [ 0, %5 ]
+  ret i32 %e.0
+}
+
+declare i32 @fn2(...)





More information about the llvm-commits mailing list