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

Chris Lattner lattner at cs.uiuc.edu
Sun Feb 26 11:58:07 PST 2006



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.438 -> 1.439
---
Log message:

Fold (X|C1)^C2 -> X^(C1|C2) when possible.  This implements 
InstCombine/or.ll:test23.



---
Diffs of the changes:  (+14 -0)

 InstructionCombining.cpp |   14 ++++++++++++++
 1 files changed, 14 insertions(+)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.438 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.439
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.438	Fri Feb 24 12:05:58 2006
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Sun Feb 26 13:57:54 2006
@@ -2846,6 +2846,20 @@
                                              ConstantInt::get(I.getType(), 1)),
                                           Op0I->getOperand(0));
           }
+        } else if (Op0I->getOpcode() == Instruction::Or) {
+          // (X|C1)^C2 -> X^(C1|C2) iff X&~C1 == 0
+          if (MaskedValueIsZero(Op0I->getOperand(0), Op0CI->getZExtValue())) {
+            Constant *NewRHS = ConstantExpr::getOr(Op0CI, RHS);
+            // Anything in both C1 and C2 is known to be zero, remove it from
+            // NewRHS.
+            Constant *CommonBits = ConstantExpr::getAnd(Op0CI, RHS);
+            NewRHS = ConstantExpr::getAnd(NewRHS, 
+                                          ConstantExpr::getNot(CommonBits));
+            WorkList.push_back(Op0I);
+            I.setOperand(0, Op0I->getOperand(0));
+            I.setOperand(1, NewRHS);
+            return &I;
+          }
         }
     }
 






More information about the llvm-commits mailing list