Index: lib/Transforms/Scalar/SCCP.cpp =================================================================== --- lib/Transforms/Scalar/SCCP.cpp +++ lib/Transforms/Scalar/SCCP.cpp @@ -918,6 +918,15 @@ // Otherwise, one of our operands is overdefined. Try to produce something // better than overdefined with some tricks. + // If this is a xor %blah, %blah, it doesn't matter if %blah is overdefined, + // we can just mark that constant. + if (I.getOpcode() == Instruction::Xor) { + if (I.getOperand(0) == I.getOperand(1)) { + markConstant(IV, &I, Constant::getNullValue(I.getType())); + return; + } + } + // If this is an AND or OR with 0 or -1, it doesn't matter that the other // operand is overdefined. if (I.getOpcode() == Instruction::And || I.getOpcode() == Instruction::Or) { Index: test/Transforms/SCCP/xor.ll =================================================================== --- /dev/null +++ test/Transforms/SCCP/xor.ll @@ -0,0 +1,10 @@ +; RUN: opt -S -sccp %s | FileCheck %s + +define i32 @myxor(i32 %x) { + %patatino = xor i32 %x, %x + ret i32 %patatino +} + +; CHECK: define i32 @myxor(i32 %x) { +; CHECK-NEXT: ret i32 0 +; CHECK-NEXT: }