[llvm-commits] [llvm] r124746 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp test/Transforms/InstSimplify/2010-12-20-Reassociate.ll
Duncan Sands
baldrick at free.fr
Wed Feb 2 12:52:00 PST 2011
Author: baldrick
Date: Wed Feb 2 14:52:00 2011
New Revision: 124746
URL: http://llvm.org/viewvc/llvm-project?rev=124746&view=rev
Log:
Reenable the transform "(X*Y)/Y->X" when the multiplication is known not to
overflow (nsw flag), which was disabled because it breaks 254.gap. I have
informed the GAP authors of the mistake in their code, and arranged for the
testsuite to use -fwrapv when compiling this benchmark.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/2010-12-20-Reassociate.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=124746&r1=124745&r2=124746&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Wed Feb 2 14:52:00 2011
@@ -798,11 +798,11 @@
Value *X = 0, *Y = 0;
if (match(Op0, m_Mul(m_Value(X), m_Value(Y))) && (X == Op1 || Y == Op1)) {
if (Y != Op1) std::swap(X, Y); // Ensure expression is (X * Y) / Y, Y = Op1
-// BinaryOperator *Mul = cast<BinaryOperator>(Op0);
-// // If the Mul knows it does not overflow, then we are good to go.
-// if ((isSigned && Mul->hasNoSignedWrap()) ||
-// (!isSigned && Mul->hasNoUnsignedWrap()))
-// return X;
+ BinaryOperator *Mul = cast<BinaryOperator>(Op0);
+ // If the Mul knows it does not overflow, then we are good to go.
+ if ((isSigned && Mul->hasNoSignedWrap()) ||
+ (!isSigned && Mul->hasNoUnsignedWrap()))
+ return X;
// If X has the form X = A / Y then X * Y cannot overflow.
if (BinaryOperator *Div = dyn_cast<BinaryOperator>(X))
if (Div->getOpcode() == Opcode && Div->getOperand(1) == Y)
Modified: llvm/trunk/test/Transforms/InstSimplify/2010-12-20-Reassociate.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/2010-12-20-Reassociate.ll?rev=124746&r1=124745&r2=124746&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/2010-12-20-Reassociate.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/2010-12-20-Reassociate.ll Wed Feb 2 14:52:00 2011
@@ -92,10 +92,12 @@
}
define i32 @sdiv1(i32 %x, i32 %y) {
+; CHECK: @sdiv1
; (no overflow X * Y) / Y -> X
%mul = mul nsw i32 %x, %y
%r = sdiv i32 %mul, %y
ret i32 %r
+; CHECK: ret i32 %x
}
define i32 @sdiv2(i32 %x, i32 %y) {
@@ -136,10 +138,12 @@
}
define i32 @udiv1(i32 %x, i32 %y) {
+; CHECK: @udiv1
; (no overflow X * Y) / Y -> X
%mul = mul nuw i32 %x, %y
%r = udiv i32 %mul, %y
ret i32 %r
+; CHECK: ret i32 %x
}
define i32 @udiv2(i32 %x, i32 %y) {
More information about the llvm-commits
mailing list