From: Chris Lattner Date: Wed, 23 Jul 2003 17:26:36 +0000 (+0000) Subject: InstCombine: (X ^ 4) == 8 --> X == 12 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=00b1a7e23e7e0804be5c1195d0cdef9974043049;p=oota-llvm.git InstCombine: (X ^ 4) == 8 --> X == 12 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7260 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index d9c6ccee8d4..4e369272003 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -711,7 +711,7 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) { return BinaryOperator::createNot(Val, I.getName()); } - // If the first operand is (and|or) with a constant, and the second + // If the first operand is (and|or|xor) with a constant, and the second // operand is a constant, simplify a bit. if (BinaryOperator *BO = dyn_cast(Op0)) if (ConstantInt *BOC = dyn_cast(BO->getOperand(1))) @@ -725,6 +725,11 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) { // comparison can never succeed! if (!(*CI & *~*BOC)->isNullValue()) return ReplaceInstUsesWith(I, ConstantBool::get(isSetNE)); + } else if (BO->getOpcode() == Instruction::Xor) { + // For the xor case, we can always just xor the two constants + // together, potentially eliminating the explicit xor. + return BinaryOperator::create(I.getOpcode(), BO->getOperand(0), + *CI ^ *BOC); } }