Skip to content

Commit 770516e

Browse files
author
Eli Friedman
committed
[ARM] Use preferred alignment for constants in promoteToConstantPool.
This mostly affects IR generated by non-clang frontends because clang generally sets the alignment of globals explicitly. Fixes https://bugs.llvm.org//show_bug.cgi?id=32394 . (-arm-promote-constant is currently off by default, and it stays off with this patch. I'll look into turning it on again when all the known issues are fixed.) Differential Revision: https://reviews.llvm.org/D51469 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343359 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 3bd24cd commit 770516e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3148,7 +3148,7 @@ static SDValue promoteToConstantPool(const GlobalValue *GV, SelectionDAG &DAG,
31483148
// that are strings for simplicity.
31493149
auto *CDAInit = dyn_cast<ConstantDataArray>(Init);
31503150
unsigned Size = DAG.getDataLayout().getTypeAllocSize(Init->getType());
3151-
unsigned Align = GVar->getAlignment();
3151+
unsigned Align = DAG.getDataLayout().getPreferredAlignment(GVar);
31523152
unsigned RequiredPadding = 4 - (Size % 4);
31533153
bool PaddingPossible =
31543154
RequiredPadding == 4 || (CDAInit && CDAInit->isString());

test/CodeGen/ARM/constantpool-promote.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@.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
2323
@.arr4 = private unnamed_addr constant [2 x i16] [i16 3, i16 4], align 16
2424
@.zerosize = private unnamed_addr constant [0 x i16] zeroinitializer, align 4
25+
@implicit_alignment_vector = private unnamed_addr constant <4 x i32> <i32 1, i32 2, i32 3, i32 4>
2526

2627
; CHECK-LABEL: @test1
2728
; CHECK: adr r0, [[x:.*]]
@@ -178,9 +179,19 @@ define void @test11(i16* %a) local_unnamed_addr #0 {
178179
ret void
179180
}
180181

182+
; Promotion only works with globals with alignment 4 or less; a vector has
183+
; implicit alignment 16.
184+
; CHECK-LABEL: @test12
185+
; CHECK-NOT: adr
186+
define void @test12() local_unnamed_addr #0 {
187+
call void @d(<4 x i32>* @implicit_alignment_vector)
188+
ret void
189+
}
190+
181191

182192
declare void @b(i8*) #1
183193
declare void @c(i16*) #1
194+
declare void @d(<4 x i32>*) #1
184195
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i1)
185196
declare void @llvm.memmove.p0i8.p0i8.i32(i8*, i8*, i32, i1) local_unnamed_addr
186197
declare void @llvm.memmove.p0i16.p0i16.i32(i16*, i16*, i32, i1) local_unnamed_addr

0 commit comments

Comments
 (0)