Adding i1 is always Xor.
authorNick Lewycky <nicholas@mxc.ca>
Sat, 31 May 2008 17:10:28 +0000 (17:10 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Sat, 31 May 2008 17:10:28 +0000 (17:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51816 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp
test/Transforms/InstCombine/2008-05-31-AddBool.ll [new file with mode: 0644]

index 74e6b6f6b060057627f6c7f8d1328f28ec4ae6d7..5199578b1f81667321d9d4805f092b71e7d8f273 100644 (file)
@@ -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<Constant>(RHS)) {
     // X + undef -> undef
     if (isa<UndefValue>(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 (file)
index 0000000..7008587
--- /dev/null
@@ -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
+}