summaryrefslogtreecommitdiffstats
path: root/polly/lib/Transform/ScheduleOptimizer.cpp
diff options
context:
space:
mode:
authorSiddharth Bhat <siddu.druid@gmail.com>2017-04-06 08:20:22 +0000
committerSiddharth Bhat <siddu.druid@gmail.com>2017-04-06 08:20:22 +0000
commit5eeb1dd42ef304c6a2f85d3fb9eda03c932f1fe0 (patch)
treea50e559ddb933e1af67f025be1da375f55634d96 /polly/lib/Transform/ScheduleOptimizer.cpp
parente6b81315f718d161d740cf2157b9840c4c429473 (diff)
downloadbcm5719-llvm-5eeb1dd42ef304c6a2f85d3fb9eda03c932f1fe0.tar.gz
bcm5719-llvm-5eeb1dd42ef304c6a2f85d3fb9eda03c932f1fe0.zip
[Polly] [ScheduleOptimizer] Prevent incorrect tile size computation
Because Polly exposes parameters that directly influence tile size calculations, one can setup situations like divide-by-zero. Check against a possible divide-by-zero in getMacroKernelParams and return early. Also assert at the end of getMacroKernelParams that the block sizes computed for matrices are positive (>= 1). Tags: #polly Differential Revision: https://reviews.llvm.org/D31708 llvm-svn: 299633
Diffstat (limited to 'polly/lib/Transform/ScheduleOptimizer.cpp')
-rw-r--r--polly/lib/Transform/ScheduleOptimizer.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/polly/lib/Transform/ScheduleOptimizer.cpp b/polly/lib/Transform/ScheduleOptimizer.cpp
index 83c97d12641..ba1373e7be2 100644
--- a/polly/lib/Transform/ScheduleOptimizer.cpp
+++ b/polly/lib/Transform/ScheduleOptimizer.cpp
@@ -1014,6 +1014,14 @@ getMacroKernelParams(const MicroKernelParamsTy &MicroKernelParams,
int Car = floor(
(FirstCacheLevelAssociativity - 1) /
(1 + static_cast<double>(MicroKernelParams.Nr) / MicroKernelParams.Mr));
+
+ // Car can be computed to be zero since it is floor to int.
+ // On Mac OS, division by 0 does not raise a signal. This causes negative
+ // tile sizes to be computed. Prevent division by 0 Cac by early returning
+ // if this happens.
+ if (Car == 0)
+ return {1, 1, 1};
+
auto ElementSize = getMatMulAlignTypeSize(MMI);
assert(ElementSize > 0 && "The element size of the matrix multiplication "
"operands should be greater than zero.");
@@ -1024,6 +1032,9 @@ getMacroKernelParams(const MicroKernelParamsTy &MicroKernelParams,
SecondCacheLevelSize;
int Mc = floor((SecondCacheLevelAssociativity - 2) / Cac);
int Nc = PollyPatternMatchingNcQuotient * MicroKernelParams.Nr;
+
+ assert(Mc > 0 && Nc > 0 && Kc > 0 &&
+ "Matrix block sizes should be greater than zero");
return {Mc, Nc, Kc};
}
OpenPOWER on IntegriCloud