[llvm] r228872 - Reassociate: cannot negate a INT_MIN value

Mehdi Amini mehdi.amini at apple.com
Wed Feb 11 11:54:45 PST 2015


Author: mehdi_amini
Date: Wed Feb 11 13:54:44 2015
New Revision: 228872

URL: http://llvm.org/viewvc/llvm-project?rev=228872&view=rev
Log:
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 at apple.com>

Added:
    llvm/trunk/test/Transforms/Reassociate/min_int.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=228872&r1=228871&r2=228872&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Wed Feb 11 13:54:44 2015
@@ -1991,7 +1991,7 @@ Instruction *Reassociate::canonicalizeNe
   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())

Added: llvm/trunk/test/Transforms/Reassociate/min_int.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Reassociate/min_int.ll?rev=228872&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/Reassociate/min_int.ll (added)
+++ llvm/trunk/test/Transforms/Reassociate/min_int.ll Wed Feb 11 13:54:44 2015
@@ -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
+}
+





More information about the llvm-commits mailing list