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 @@ -1116,8 +1116,12 @@ return C1; // undef << X -> 0 return Constant::getNullValue(C1->getType()); - case Instruction::FAdd: case Instruction::FSub: + // -0.0 - undef --> undef (consistent with "fneg undef") + if (match(C1, m_NegZeroFP()) && isa(C2)) + return C2; + LLVM_FALLTHROUGH; + case Instruction::FAdd: case Instruction::FMul: case Instruction::FDiv: case Instruction::FRem: diff --git a/llvm/test/Analysis/ConstantFolding/fp-undef.ll b/llvm/test/Analysis/ConstantFolding/fp-undef.ll --- a/llvm/test/Analysis/ConstantFolding/fp-undef.ll +++ b/llvm/test/Analysis/ConstantFolding/fp-undef.ll @@ -235,7 +235,7 @@ define double @fsub_undef_op1_constant_neg0(double %x) { ; CHECK-LABEL: @fsub_undef_op1_constant_neg0( -; CHECK-NEXT: ret double 0x7FF8000000000000 +; CHECK-NEXT: ret double undef ; %r = fsub double 0x8000000000000000, undef ret double %r