From f78df7c14d0db1e73f7f232447298ea6c1c48db3 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 26 Feb 2006 19:57:54 +0000 Subject: [PATCH] Fold (X|C1)^C2 -> X^(C1|C2) when possible. This implements InstCombine/or.ll:test23. llvm-svn: 26385 --- .../lib/Transforms/Scalar/InstructionCombining.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index b98228c0923a..99677cc5de63 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; + } } }