Align newly created arrays to the first level cache line boundary

Aligning data to cache lines boundaries helps to avoid overheads related to
an access to it ([1]). This patch aligns newly created arrays and adds an
option to specify the first level cache line size. By default we use 64 bytes,
which is a typical cache-line size ([2]).

In case of Intel Core i7-3820 SandyBridge and the following options,

clang -O3 gemm.c -I utilities/ utilities/polybench.c -DPOLYBENCH_TIME
-march=native -mllvm -polly -mllvm -polly-pattern-matching-based-opts=true
-DPOLYBENCH_USE_SCALAR_LB -mllvm -polly-target-cache-level-associativity=8,8
-mllvm -polly-target-cache-level-sizes=32768,262144 -mllvm
-polly-target-latency-vector-fma=8

it helps to improve the performance from 11.303 GFlops/sec (39,247% of
theoretical peak) to 12.63 GFlops/sec (43,8542% of theoretical peak).

Refs.:

[1] - http://www.alexonlinux.com/aligned-vs-unaligned-memory-access
[2] - http://igoro.com/archive/gallery-of-processor-cache-effects/

Differential Revision: https://reviews.llvm.org/D28020

Reviewed-by: Tobias Grosser <tobias@grosser.es>
llvm-svn: 290253
This commit is contained in:
Roman Gareev 2016-12-21 12:37:36 +00:00
parent 7116dc908c
commit bd5c6039c6
1 changed files with 7 additions and 2 deletions

View File

@ -74,6 +74,11 @@ static cl::opt<bool> PollyGenerateExpressions(
cl::desc("Generate AST expressions for unmodified and modified accesses"),
cl::Hidden, cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
static cl::opt<int> PollyTargetFirstLevelCacheLineSize(
"polly-target-first-level-cache-line-size",
cl::desc("The size of the first level cache line size specified in bytes."),
cl::Hidden, cl::init(64), cl::ZeroOrMore, cl::cat(PollyCategory));
__isl_give isl_ast_expr *
IslNodeBuilder::getUpperBound(__isl_keep isl_ast_node *For,
ICmpInst::Predicate &Predicate) {
@ -1269,8 +1274,8 @@ void IslNodeBuilder::allocateNewArrays() {
auto InstIt =
Builder.GetInsertBlock()->getParent()->getEntryBlock().getTerminator();
Value *CreatedArray =
new AllocaInst(NewArrayType, SAI->getName(), &*InstIt);
auto *CreatedArray = new AllocaInst(NewArrayType, SAI->getName(), &*InstIt);
CreatedArray->setAlignment(PollyTargetFirstLevelCacheLineSize);
SAI->setBasePtr(CreatedArray);
}
}