From fd12a0b20b12b0199011fb3903aa1f8ca4b387f5 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Sat, 31 May 2008 17:10:28 +0000 Subject: [PATCH] Adding i1 is always Xor. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51816 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/InstructionCombining.cpp | 3 +++ test/Transforms/InstCombine/2008-05-31-AddBool.ll | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 test/Transforms/InstCombine/2008-05-31-AddBool.ll diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 74e6b6f6b06..5199578b1f8 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2551,6 +2551,9 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { bool Changed = SimplifyCommutative(I); Value *LHS = I.getOperand(0), *RHS = I.getOperand(1); + if (I.getType() == Type::Int1Ty) + return BinaryOperator::CreateXor(LHS, RHS); + if (Constant *RHSC = dyn_cast(RHS)) { // X + undef -> undef if (isa(RHS)) diff --git a/test/Transforms/InstCombine/2008-05-31-AddBool.ll b/test/Transforms/InstCombine/2008-05-31-AddBool.ll new file mode 100644 index 00000000000..7008587c40d --- /dev/null +++ b/test/Transforms/InstCombine/2008-05-31-AddBool.ll @@ -0,0 +1,7 @@ +; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep {xor} +; PR2389 + +define i1 @test(i1 %a, i1 %b) { + %A = add i1 %a, %b + ret i1 %A +}