diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -1053,9 +1053,8 @@ switch (static_cast(Opcode)) { case Instruction::Xor: if (isa(C1) && isa(C2)) - // Handle undef ^ undef -> 0 special case. This is a common - // idiom (misuse). - return Constant::getNullValue(C1->getType()); + // undef ^ undef -> undef + return C1; LLVM_FALLTHROUGH; case Instruction::Add: case Instruction::Sub: diff --git a/llvm/test/Analysis/ConstantFolding/vscale.ll b/llvm/test/Analysis/ConstantFolding/vscale.ll --- a/llvm/test/Analysis/ConstantFolding/vscale.ll +++ b/llvm/test/Analysis/ConstantFolding/vscale.ll @@ -159,7 +159,7 @@ define @xor() { ; CHECK-LABEL: @xor( -; CHECK-NEXT: ret zeroinitializer +; CHECK-NEXT: ret undef ; %r = xor undef, undef ret %r diff --git a/llvm/test/Transforms/InstCombine/xor-undef.ll b/llvm/test/Transforms/InstCombine/xor-undef.ll --- a/llvm/test/Transforms/InstCombine/xor-undef.ll +++ b/llvm/test/Transforms/InstCombine/xor-undef.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -instcombine -S | grep zeroinitializer +; RUN: opt < %s -instcombine -S | grep "ret <2 x i64> undef" define <2 x i64> @f() { %tmp = xor <2 x i64> undef, undef