Skip to content

Commit

Permalink
Align newly created arrays to the first level cache line boundary
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gareevroman committed Dec 21, 2016
1 parent 7116dc9 commit bd5c603
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions polly/lib/CodeGen/IslNodeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit bd5c603

Please sign in to comment.