diff options
| author | Chris Lattner <sabre@nondot.org> | 2002-08-23 18:32:43 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2002-08-23 18:32:43 +0000 |
| commit | 65217ff294f60fbcc0f22fbdfe432167dc94110b (patch) | |
| tree | 1143b2d510ef03f496cf40d40b968c39139da448 /llvm/lib/Transforms | |
| parent | ad1e0535e2781175de659330f67bb05c197d69ca (diff) | |
| download | bcm5719-llvm-65217ff294f60fbcc0f22fbdfe432167dc94110b.tar.gz bcm5719-llvm-65217ff294f60fbcc0f22fbdfe432167dc94110b.zip | |
- instcombine demorgan's law: and (not A), (not B) == not (or A, B)
llvm-svn: 3495
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 0f8ae0c6bdb..14a13fe3637 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -81,6 +81,8 @@ namespace { // in the program. Add the new instruction to the worklist. // void InsertNewInstBefore(Instruction *New, Instruction &Old) { + assert(New && New->getParent() == 0 && + "New instruction already inserted into a basic block!"); BasicBlock *BB = Old.getParent(); BB->getInstList().insert(&Old, New); // Insert inst WorkList.push_back(New); // Add to worklist @@ -292,6 +294,16 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) { if (RHS->isAllOnesValue()) return ReplaceInstUsesWith(I, Op0); + // and (not A), (not B) == not (or A, B) + if (Op0->use_size() == 1 && Op1->use_size() == 1) + if (Value *A = dyn_castNotInst(Op0)) + if (Value *B = dyn_castNotInst(Op1)) { + Instruction *Or = BinaryOperator::create(Instruction::Or, A, B, + I.getName()+".demorgan"); + InsertNewInstBefore(Or, I); + return BinaryOperator::createNot(Or, I.getName()); + } + return Changed ? &I : 0; } |

