[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Jul 23 13:30:02 PDT 2003


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.101 -> 1.102

---
Log message:

IC: (X & C1) | C2 --> (X | C2) & (C1|C2)
IC: (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)

We are now guaranteed that all 'or's will be inside of 'and's, and all 'and's 
will be inside of 'xor's, if the second operands are constants.


---
Diffs of the changes:

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.101 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.102
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.101	Wed Jul 23 12:57:01 2003
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Wed Jul 23 13:29:44 2003
@@ -538,9 +538,34 @@
     return ReplaceInstUsesWith(I, Op0);
 
   // or X, -1 == -1
-  if (ConstantIntegral *RHS = dyn_cast<ConstantIntegral>(Op1))
+  if (ConstantIntegral *RHS = dyn_cast<ConstantIntegral>(Op1)) {
     if (RHS->isAllOnesValue())
       return ReplaceInstUsesWith(I, Op1);
+
+    if (Instruction *Op0I = dyn_cast<Instruction>(Op0)) {
+      // (X & C1) | C2 --> (X | C2) & (C1|C2)
+      if (Op0I->getOpcode() == Instruction::And && isOnlyUse(Op0))
+        if (ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1))) {
+          std::string Op0Name = Op0I->getName(); Op0I->setName("");
+          Instruction *Or = BinaryOperator::create(Instruction::Or,
+                                                   Op0I->getOperand(0), RHS,
+                                                   Op0Name);
+          InsertNewInstBefore(Or, I);
+          return BinaryOperator::create(Instruction::And, Or, *RHS | *Op0CI);
+        }
+
+      // (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
+      if (Op0I->getOpcode() == Instruction::Xor && isOnlyUse(Op0))
+        if (ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1))) {
+          std::string Op0Name = Op0I->getName(); Op0I->setName("");
+          Instruction *Or = BinaryOperator::create(Instruction::Or,
+                                                   Op0I->getOperand(0), RHS,
+                                                   Op0Name);
+          InsertNewInstBefore(Or, I);
+          return BinaryOperator::create(Instruction::Xor, Or, *Op0CI & *~*RHS);
+        }
+    }
+  }
 
   Value *Op0NotVal = dyn_castNotVal(Op0);
   Value *Op1NotVal = dyn_castNotVal(Op1);





More information about the llvm-commits mailing list