- instcombine demorgan's law: and (not A), (not B) == not (or A, B)
authorChris Lattner <sabre@nondot.org>
Fri, 23 Aug 2002 18:32:43 +0000 (18:32 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 23 Aug 2002 18:32:43 +0000 (18:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3495 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 0f8ae0c6bdb9c927f4e12717d9ccbe2d97fcdf0b..14a13fe36373aff045c1d950d86bf89531636872 100644 (file)
@@ -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;
 }