diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2015-02-11 19:54:44 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2015-02-11 19:54:44 +0000 |
commit | 9730116bd6792a91eb965c9fcab19b8f5095b29e (patch) | |
tree | 37fe540d215c8cce04497a67cbf0cab4d910dd11 | |
parent | 349e0626953528454f2566bd56e6565ad5a4fd82 (diff) | |
download | bcm5719-llvm-9730116bd6792a91eb965c9fcab19b8f5095b29e.tar.gz bcm5719-llvm-9730116bd6792a91eb965c9fcab19b8f5095b29e.zip |
Reassociate: cannot negate a INT_MIN value
Summary:
When trying to canonicalize negative constants out of
multiplication expressions, we need to check that the
constant is not INT_MIN which cannot be negated.
Reviewers: mcrosier
Reviewed By: mcrosier
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D7286
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 228872
-rw-r--r-- | llvm/lib/Transforms/Scalar/Reassociate.cpp | 2 | ||||
-rw-r--r-- | llvm/test/Transforms/Reassociate/min_int.ll | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp index 0fd64e31dfe..98016b40c56 100644 --- a/llvm/lib/Transforms/Scalar/Reassociate.cpp +++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp @@ -1991,7 +1991,7 @@ Instruction *Reassociate::canonicalizeNegConstExpr(Instruction *I) { Constant *C = C0 ? C0 : C1; unsigned ConstIdx = C0 ? 0 : 1; if (auto *CI = dyn_cast<ConstantInt>(C)) { - if (!CI->isNegative()) + if (!CI->isNegative() || CI->isMinValue(true)) return nullptr; } else if (auto *CF = dyn_cast<ConstantFP>(C)) { if (!CF->isNegative()) diff --git a/llvm/test/Transforms/Reassociate/min_int.ll b/llvm/test/Transforms/Reassociate/min_int.ll new file mode 100644 index 00000000000..52dab3a531f --- /dev/null +++ b/llvm/test/Transforms/Reassociate/min_int.ll @@ -0,0 +1,13 @@ +; RUN: opt < %s -reassociate -dce -S | FileCheck %s + +; MIN_INT cannot be negated during reassociation + +define i32 @minint(i32 %i) { +; CHECK: %mul = mul i32 %i, -2147483648 +; CHECK-NEXT: %add = add i32 %mul, 1 +; CHECK-NEXT: ret i32 %add + %mul = mul i32 %i, -2147483648 + %add = add i32 %mul, 1 + ret i32 %add +} + |