diff options
author | Chris Lattner <sabre@nondot.org> | 2006-02-26 19:57:54 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-02-26 19:57:54 +0000 |
commit | f78df7c14d0db1e73f7f232447298ea6c1c48db3 (patch) | |
tree | 0b6c9d55a14158f2c40616601b5dd706eecafab2 /llvm/lib | |
parent | 69c68c3c3e0b9e98d34738afdf9fa19b9275d551 (diff) | |
download | bcm5719-llvm-f78df7c14d0db1e73f7f232447298ea6c1c48db3.tar.gz bcm5719-llvm-f78df7c14d0db1e73f7f232447298ea6c1c48db3.zip |
Fold (X|C1)^C2 -> X^(C1|C2) when possible. This implements
InstCombine/or.ll:test23.
llvm-svn: 26385
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index b98228c0923..99677cc5de6 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2846,6 +2846,20 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { 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; + } } } |