diff options
author | Tobias Grosser <tobias@grosser.es> | 2016-08-26 12:01:07 +0000 |
---|---|---|
committer | Tobias Grosser <tobias@grosser.es> | 2016-08-26 12:01:07 +0000 |
commit | 437200089d5712d3714880ee2eb64d855dfc60a6 (patch) | |
tree | 4e1827d3ff82df558ffd2660e438e78d654e61d6 /polly/lib/Support/GICHelper.cpp | |
parent | 0a1986790c29118b756df41212bd45a2d2712770 (diff) | |
download | bcm5719-llvm-437200089d5712d3714880ee2eb64d855dfc60a6.tar.gz bcm5719-llvm-437200089d5712d3714880ee2eb64d855dfc60a6.zip |
Improve documentation and testing for isl_valFromAPInt
The recent unit tests we gained made clear that the semantics of
isl_valFromAPInt are not clear, due to missing documentation. In this change we
document both the calling interface as well as the implementation of
isl_valFromAPInt.
We also make the implementation easier to read by removing integer wrappig in
abs() when passing in the minimal integer value for a given bitwidth. Even
though wrapping and subsequently interpreting the result as unsigned value gives
the correct result, this is far from obvious. Instead, we explicitly add one
more bit to the input type to ensure that abs will never wrap. This change did
not uncover a bug in the old implementation, but was introduced to increase
readability.
We update the tests to add a test case for this special case and use this
opportunity to also test a number larger than 64 bit. Finally, we order the
arguments of the test cases to make sure the expected output is first. This
helps readability in case of failing test cases as gtest assumes the first value
to be the exected value.
Reviewed-by: Michael Kruse <llvm@meinersbur.de>
Differential Revision: https://reviews.llvm.org/D23917
llvm-svn: 279815
Diffstat (limited to 'polly/lib/Support/GICHelper.cpp')
-rw-r--r-- | polly/lib/Support/GICHelper.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/polly/lib/Support/GICHelper.cpp b/polly/lib/Support/GICHelper.cpp index 48b601334d1..e3a59993aec 100644 --- a/polly/lib/Support/GICHelper.cpp +++ b/polly/lib/Support/GICHelper.cpp @@ -30,8 +30,19 @@ __isl_give isl_val *polly::isl_valFromAPInt(isl_ctx *Ctx, const APInt Int, APInt Abs; isl_val *v; + // As isl is interpreting the input always as unsigned value, we need some + // additional pre and post processing to import signed values. The approach + // we take is to first obtain the absolute value of Int and then negate the + // value after it has been imported to isl. + // + // It should be noted that the smallest integer value represented in two's + // complement with a certain amount of bits does not have a corresponding + // positive representation in two's complement representation with the same + // number of bits. E.g. 110 (-2) does not have a corresponding value for (2). + // To ensure that there is always a corresponding value available we first + // sign-extend the input by one bit and only then take the absolute value. if (IsSigned) - Abs = Int.abs(); + Abs = Int.sext(Int.getBitWidth() + 1).abs(); else Abs = Int; |