[PATCH] Reassociate: cannot negate a INT_MIN value
Mehdi AMINI
mehdi.amini at apple.com
Thu Jan 29 17:10:58 PST 2015
Hi mcrosier,
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.
http://reviews.llvm.org/D7286
Files:
lib/Transforms/Scalar/Reassociate.cpp
test/Transforms/Reassociate/min_int.ll
Index: lib/Transforms/Scalar/Reassociate.cpp
===================================================================
--- lib/Transforms/Scalar/Reassociate.cpp
+++ lib/Transforms/Scalar/Reassociate.cpp
@@ -1991,7 +1991,7 @@
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())
Index: test/Transforms/Reassociate/min_int.ll
===================================================================
--- /dev/null
+++ 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
+}
+
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7286.19015.patch
Type: text/x-patch
Size: 1030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150130/1ae47bbc/attachment.bin>
More information about the llvm-commits
mailing list