summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGen/array-init.c
diff options
context:
space:
mode:
authorMatt Davis <Matthew.Davis@sony.com>2018-02-09 22:10:09 +0000
committerMatt Davis <Matthew.Davis@sony.com>2018-02-09 22:10:09 +0000
commit2930d7662e9c7a90976d41be9086298c5305d7a6 (patch)
tree8b889241b26e394baa5e9ce16e8bfc13a2f89dd5 /clang/test/CodeGen/array-init.c
parent95a0f39e35040e7385cfde680721c1ea578a1d0f (diff)
downloadbcm5719-llvm-2930d7662e9c7a90976d41be9086298c5305d7a6.tar.gz
bcm5719-llvm-2930d7662e9c7a90976d41be9086298c5305d7a6.zip
[CodeGen] Use the zero initializer instead of storing an all zero representation.
Summary: This change avoids the overhead of storing, and later crawling, an initializer list of all zeros for arrays. When LLVM visits this (llvm/IR/Constants.cpp) ConstantArray::getImpl() it will scan the list looking for an array of all zero. We can avoid the store, and short-cut the scan, by detecting all zeros when clang builds-up the initialization representation. This was brought to my attention when investigating PR36030 Reviewers: majnemer, rjmccall Reviewed By: rjmccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D42549 llvm-svn: 324776
Diffstat (limited to 'clang/test/CodeGen/array-init.c')
-rw-r--r--clang/test/CodeGen/array-init.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/test/CodeGen/array-init.c b/clang/test/CodeGen/array-init.c
new file mode 100644
index 00000000000..fa54994acc3
--- /dev/null
+++ b/clang/test/CodeGen/array-init.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -O0 -triple x86_64-unknown-linux-gnu -emit-llvm -o - | FileCheck %s
+
+// CHECK: @{{.*}}.a1 = internal constant [5 x i32] [i32 0, i32 1, i32 2, i32 0, i32 0]
+// CHECK: @{{.*}}.a2 = internal constant [5 x i32] zeroinitializer
+// CHECK: @{{.*}}.a3 = internal constant [5 x i32] zeroinitializer
+
+void testConstArrayInits(void)
+{
+ const int a1[5] = {0,1,2};
+ const int a2[5] = {0,0,0};
+ const int a3[5] = {0};
+}
OpenPOWER on IntegriCloud