[llvm] r283423 - [ARM] Constant pool promotion - fix alignment calculation

James Molloy via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 6 00:56:01 PDT 2016


Author: jamesm
Date: Thu Oct  6 02:56:00 2016
New Revision: 283423

URL: http://llvm.org/viewvc/llvm-project?rev=283423&view=rev
Log:
[ARM] Constant pool promotion - fix alignment calculation

Global variables are GlobalValues, so they have explicit alignment. Querying
DataLayout for the alignment was incorrect.

Testcase added.

Modified:
    llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp
    llvm/trunk/test/CodeGen/ARM/constantpool-promote.ll

Modified: llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp?rev=283423&r1=283422&r2=283423&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMISelLowering.cpp Thu Oct  6 02:56:00 2016
@@ -3084,7 +3084,7 @@ static SDValue promoteToConstantPool(con
   // that are strings for simplicity.
   auto *CDAInit = dyn_cast<ConstantDataArray>(Init);
   unsigned Size = DAG.getDataLayout().getTypeAllocSize(Init->getType());
-  unsigned Align = DAG.getDataLayout().getABITypeAlignment(Init->getType());
+  unsigned Align = GVar->getAlignment();
   unsigned RequiredPadding = 4 - (Size % 4);
   bool PaddingPossible =
     RequiredPadding == 4 || (CDAInit && CDAInit->isString());

Modified: llvm/trunk/test/CodeGen/ARM/constantpool-promote.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/constantpool-promote.ll?rev=283423&r1=283422&r2=283423&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/constantpool-promote.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/constantpool-promote.ll Thu Oct  6 02:56:00 2016
@@ -15,6 +15,7 @@ target triple = "armv7--linux-gnueabihf"
 @.arr2 = private unnamed_addr constant [2 x i16] [i16 7, i16 8], align 2
 @.arr3 = private unnamed_addr constant [2 x i16*] [i16* null, i16* null], align 4
 @.ptr = private unnamed_addr constant [2 x i16*] [i16* getelementptr inbounds ([2 x i16], [2 x i16]* @.arr2, i32 0, i32 0), i16* null], align 2
+ at .arr4 = private unnamed_addr constant [2 x i16] [i16 3, i16 4], align 16
 
 ; CHECK-LABEL: @test1
 ; CHECK: adr r0, [[x:.*]]
@@ -125,6 +126,15 @@ entry:
   ret void
 }
 
+; This shouldn't be promoted, as the global requires >4 byte alignment.
+; CHECK-LABEL: @test9
+; CHECK-NOT: adr
+define void @test9() #0 {
+  tail call void @c(i16* getelementptr inbounds ([2 x i16], [2 x i16]* @.arr4, i32 0, i32 0)) #2
+  ret void
+}
+
+
 declare void @b(i8*) #1
 declare void @c(i16*) #1
 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i32, i1)




More information about the llvm-commits mailing list