Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CodeGen] Use the zero initializer instead of storing an all zero rep…
…resentation. 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
- Loading branch information
Matt Davis
authored and
Matt Davis
committed
Feb 9, 2018
1 parent
95a0f39
commit 2930d76
Showing
2 changed files
with
22 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}; | ||
} |