Index: llvm/lib/IR/ConstantFold.cpp =================================================================== --- llvm/lib/IR/ConstantFold.cpp +++ llvm/lib/IR/ConstantFold.cpp @@ -169,7 +169,12 @@ return V; // See note below regarding the PPC_FP128 restriction. - if (DestTy->isFloatingPointTy() && !DestTy->isPPC_FP128Ty()) + // Also disable for x86_fp80 to avoid turning unnormals, a pseudo-denormals + // or pseudo-infinities into a nan which we can't convert back to the + // original value if it gets casted back to integer. + // FIXME: Can we preserve this information in APFloat? + if (DestTy->isFloatingPointTy() && !DestTy->isPPC_FP128Ty() && + !DestTy->isX86_FP80Ty()) return ConstantFP::get(DestTy->getContext(), APFloat(DestTy->getFltSemantics(), CI->getValue())); Index: llvm/test/Transforms/InstCombine/X86/2009-03-23-i80-fp80.ll =================================================================== --- llvm/test/Transforms/InstCombine/X86/2009-03-23-i80-fp80.ll +++ llvm/test/Transforms/InstCombine/X86/2009-03-23-i80-fp80.ll @@ -13,7 +13,7 @@ define x86_fp80 @to() { ; CHECK-LABEL: @to( -; CHECK-NEXT: ret x86_fp80 0xK40018000000000000000 +; CHECK-NEXT: ret x86_fp80 bitcast (i80 302259125019767858003968 to x86_fp80) ; %tmp = bitcast i80 302259125019767858003968 to x86_fp80 ret x86_fp80 %tmp