diff options
author | Duncan Sands <baldrick@free.fr> | 2010-12-22 13:36:08 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2010-12-22 13:36:08 +0000 |
commit | 37bf92b5238434b00fde79347ba5336e7554e562 (patch) | |
tree | e0594f4d7ad0969d3807ec13dc85a8b50e0381f8 /lib/Transforms/InstCombine/InstCombineAddSub.cpp | |
parent | fc7072c3c4db03555a0a62220d61a2b85acd01fd (diff) |
Add a generic expansion transform: A op (B op' C) -> (A op B) op' (A op C)
if both A op B and A op C simplify. This fires fairly often but doesn't
make that much difference. On gcc-as-one-file it removes two "and"s and
turns one branch into a select.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122399 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineAddSub.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 98d6550201..c4132b2435 100644 --- a/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -91,9 +91,10 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { I.hasNoUnsignedWrap(), TD)) return ReplaceInstUsesWith(I, V); - if (Instruction *NV = SimplifyByFactorizing(I)) // (A*B)+(A*C) -> A*(B+C) - return NV; - + // (A*B)+(A*C) -> A*(B+C) etc + if (Value *V = SimplifyUsingDistributiveLaws(I)) + return ReplaceInstUsesWith(I, V); + if (Constant *RHSC = dyn_cast<Constant>(RHS)) { if (ConstantInt *CI = dyn_cast<ConstantInt>(RHSC)) { // X + (signbit) --> X ^ signbit @@ -535,9 +536,10 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { I.hasNoUnsignedWrap(), TD)) return ReplaceInstUsesWith(I, V); - if (Instruction *NV = SimplifyByFactorizing(I)) // (A*B)-(A*C) -> A*(B-C) - return NV; - + // (A*B)-(A*C) -> A*(B-C) etc + if (Value *V = SimplifyUsingDistributiveLaws(I)) + return ReplaceInstUsesWith(I, V); + // If this is a 'B = x-(-A)', change to B = x+A. This preserves NSW/NUW. if (Value *V = dyn_castNegVal(Op1)) { BinaryOperator *Res = BinaryOperator::CreateAdd(Op0, V); |