diff options
| author | Chris Lattner <sabre@nondot.org> | 2007-01-05 02:17:46 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2007-01-05 02:17:46 +0000 |
| commit | 23eb8ec78b4a699540cda7da6c3bdc331caa8eeb (patch) | |
| tree | dc6292cc1e0bdabbdf0cfc0eddc9130b72288eff /llvm/lib/Transforms | |
| parent | ce0f91ebd627717841e418d92cd00f2eb88fd3bb (diff) | |
| download | bcm5719-llvm-23eb8ec78b4a699540cda7da6c3bdc331caa8eeb.tar.gz bcm5719-llvm-23eb8ec78b4a699540cda7da6c3bdc331caa8eeb.zip | |
Compile X + ~X to -1. This implements Instcombine/add.ll:test34
llvm-svn: 32890
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 925db6837cf..aba50dca3e7 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -1871,10 +1871,16 @@ FoundSExt: if (dyn_castFoldableMul(RHS, C2) == LHS) return BinaryOperator::createMul(LHS, AddOne(C2)); + // X + ~X --> -1 since ~X = -X-1 + if (dyn_castNotVal(LHS) == RHS || + dyn_castNotVal(RHS) == LHS) + return ReplaceInstUsesWith(I, ConstantInt::getAllOnesValue(I.getType())); + // (A & C1)+(B & C2) --> (A & C1)|(B & C2) iff C1&C2 == 0 if (match(RHS, m_And(m_Value(), m_ConstantInt(C2)))) - if (Instruction *R = AssociativeOpt(I, AddMaskingAnd(C2))) return R; + if (Instruction *R = AssociativeOpt(I, AddMaskingAnd(C2))) + return R; if (ConstantInt *CRHS = dyn_cast<ConstantInt>(RHS)) { Value *X = 0; |

