Index: lib/IR/ConstantFold.cpp =================================================================== --- lib/IR/ConstantFold.cpp +++ lib/IR/ConstantFold.cpp @@ -191,6 +191,10 @@ if (FP->getType()->isPPC_FP128Ty()) return nullptr; + // Make sure dest type is compatible with the folded integer constant. + if (!DestTy->isIntegerTy()) + return nullptr; + return ConstantInt::get(FP->getContext(), FP->getValueAPF().bitcastToAPInt()); } Index: test/CodeGen/X86/mmx-bitcast-fold.ll =================================================================== --- /dev/null +++ test/CodeGen/X86/mmx-bitcast-fold.ll @@ -0,0 +1,12 @@ +; RUN: opt -mtriple=x86_64-- -early-cse < %s -S | FileCheck %s + +; CHECK: @foo(x86_mmx bitcast (double 0.000000e+00 to x86_mmx)) + +define void @bar() { +entry: + %0 = bitcast double 0.0 to x86_mmx + %1 = call x86_mmx @foo(x86_mmx %0) + ret void +} + +declare x86_mmx @foo(x86_mmx)