From 9b8e2bd8ef852dd43d1f2c9778e76d17eca5a61f Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Tue, 18 Jan 2011 09:24:58 +0000 Subject: Simplify (X<<1)-X into X. According to my auto-simplier this is the most common missed simplification in fully optimized code. It occurs sporadically in the testsuite, and many times in 403.gcc: the final bitcode has 131 fewer subtractions after this change. The reason that the multiplies are not eliminated is the same reason that instcombine did not catch this: they are used by other instructions (instcombine catches this with a more general transform which in general is only profitable if the operands have only one use). llvm-svn: 123754 --- llvm/lib/Analysis/InstructionSimplify.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'llvm/lib') diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 1d4ff0fc9e0..f737354b36a 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -593,6 +593,12 @@ static Value *SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW, match(Op0, m_Add(m_Specific(Op1), m_Value(X)))) return X; + // (X*2) - X -> X + // (X<<1) - X -> X + if (match(Op0, m_Mul(m_Specific(Op1), m_ConstantInt<2>())) || + match(Op0, m_Shl(m_Specific(Op1), m_One()))) + return Op1; + // i1 sub -> xor. if (MaxRecurse && Op0->getType()->isIntegerTy(1)) if (Value *V = SimplifyXorInst(Op0, Op1, TD, DT, MaxRecurse-1)) -- cgit v1.2.3