From 00b1a7e23e7e0804be5c1195d0cdef9974043049 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 23 Jul 2003 17:26:36 +0000 Subject: [PATCH] InstCombine: (X ^ 4) == 8 --> X == 12 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7260 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/InstructionCombining.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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); } }