[llvm-commits] [llvm] r124560 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp test/Transforms/InstSimplify/2010-12-20-Reassociate.ll
Duncan Sands
baldrick at free.fr
Sun Jan 30 10:03:50 PST 2011
Author: baldrick
Date: Sun Jan 30 12:03:50 2011
New Revision: 124560
URL: http://llvm.org/viewvc/llvm-project?rev=124560&view=rev
Log:
Transform (X/Y)*Y into X if the division is exact. Instcombine already knows how
to do this and more, but would only do it if X/Y had only one use. Spotted as the
most common missed simplification in SPEC by my auto-simplifier, now that it knows
about nuw/nsw/exact flags. This removes a bunch of multiplications from 447.dealII
and 483.xalancbmk. It also removes a lot from tramp3d-v4, which results in much
more inlining.
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=124560&r1=124559&r2=124560&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Sun Jan 30 12:03:50 2011
@@ -710,6 +710,15 @@
if (match(Op1, m_One()))
return Op0;
+ // (X / Y) * Y -> X if the division is exact.
+ Value *X = 0, *Y = 0;
+ if ((match(Op0, m_SDiv(m_Value(X), m_Value(Y))) && Y == Op1) || // (X / Y) * Y
+ (match(Op1, m_SDiv(m_Value(X), m_Value(Y))) && Y == Op0)) { // Y * (X / Y)
+ BinaryOperator *SDiv = cast<BinaryOperator>(Y == Op1 ? Op0 : Op1);
+ if (SDiv->isExact())
+ return X;
+ }
+
// i1 mul -> and.
if (MaxRecurse && Op0->getType()->isIntegerTy(1))
if (Value *V = SimplifyAndInst(Op0, Op1, TD, DT, MaxRecurse-1))
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=124560&r1=124559&r2=124560&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/2010-12-20-Reassociate.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/2010-12-20-Reassociate.ll Sun Jan 30 12:03:50 2011
@@ -119,6 +119,24 @@
; CHECK: ret i32 0
}
+define i32 @sdiv4(i32 %x, i32 %y) {
+; CHECK: @sdiv4
+; (X / Y) * Y -> X if the division is exact
+ %div = sdiv exact i32 %x, %y
+ %mul = mul i32 %div, %y
+ ret i32 %mul
+; CHECK: ret i32 %x
+}
+
+define i32 @sdiv5(i32 %x, i32 %y) {
+; CHECK: @sdiv5
+; Y * (X / Y) -> X if the division is exact
+ %div = sdiv exact i32 %x, %y
+ %mul = mul i32 %y, %div
+ ret i32 %mul
+; CHECK: ret i32 %x
+}
+
define i32 @udiv1(i32 %x, i32 %y) {
; CHECK: @udiv1
; (no overflow X * Y) / Y -> X
More information about the llvm-commits
mailing list