From a734e288727e99ec0c77087ed89f18b828b2209d Mon Sep 17 00:00:00 2001 From: Vadzim Dambrouski Date: Mon, 20 Mar 2017 22:59:57 +0000 Subject: [PATCH] [ARM] Fix PR32130: Handle promotion of zero sized constants. The special case of zero sized values was previously not handled correctly. This patch handles this by not promoting if the size is zero. Patch by Tim Neumann. Differential Revision: https://reviews.llvm.org/D31116 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298320 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/ARMISelLowering.cpp | 3 ++- test/CodeGen/ARM/constantpool-promote.ll | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Target/ARM/ARMISelLowering.cpp b/lib/Target/ARM/ARMISelLowering.cpp index c988e1693f8..47885467d1f 100644 --- a/lib/Target/ARM/ARMISelLowering.cpp +++ b/lib/Target/ARM/ARMISelLowering.cpp @@ -3063,7 +3063,8 @@ static SDValue promoteToConstantPool(const GlobalValue *GV, SelectionDAG &DAG, unsigned RequiredPadding = 4 - (Size % 4); bool PaddingPossible = RequiredPadding == 4 || (CDAInit && CDAInit->isString()); - if (!PaddingPossible || Align > 4 || Size > ConstpoolPromotionMaxSize) + if (!PaddingPossible || Align > 4 || Size > ConstpoolPromotionMaxSize || + Size == 0) return SDValue(); unsigned PaddedSize = Size + ((RequiredPadding == 4) ? 0 : RequiredPadding); diff --git a/test/CodeGen/ARM/constantpool-promote.ll b/test/CodeGen/ARM/constantpool-promote.ll index 0d735a4698f..8df7e100c05 100644 --- a/test/CodeGen/ARM/constantpool-promote.ll +++ b/test/CodeGen/ARM/constantpool-promote.ll @@ -21,6 +21,7 @@ @.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 @.arr4 = private unnamed_addr constant [2 x i16] [i16 3, i16 4], align 16 +@.zerosize = private unnamed_addr constant [0 x i16] zeroinitializer, align 4 ; CHECK-LABEL: @test1 ; CHECK: adr r0, [[x:.*]] @@ -139,6 +140,14 @@ define void @test9() #0 { ret void } +; Ensure that zero sized values are supported / not promoted. +; CHECK-LABEL: @pr32130 +; CHECK-NOT: adr +define void @pr32130() #0 { + tail call void @c(i16* getelementptr inbounds ([0 x i16], [0 x i16]* @.zerosize, i32 0, i32 0)) #2 + ret void +} + ; CHECK-LABEL: @test10 ; CHECK-V6M: adr r{{[0-9]*}}, [[x:.*]] ; CHECK-V6M: [[x]]: -- 2.11.0