Index: llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp =================================================================== --- llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp +++ llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp @@ -423,6 +423,10 @@ 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(); Index: llvm/trunk/test/CodeGen/ARM/thumb-alignment.ll =================================================================== --- llvm/trunk/test/CodeGen/ARM/thumb-alignment.ll +++ llvm/trunk/test/CodeGen/ARM/thumb-alignment.ll @@ -13,3 +13,42 @@ define i32* @bar() { ret i32* zeroinitializer } + +@a = external global i32 +@b = external global i32 +@c = external global i32 +@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 + ] + +;