From f4cf1c3eb4937b10ae36de561ab9f730b9da9f05 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Mon, 4 Apr 2016 23:50:46 +0000 Subject: [PATCH] Don't fold double constant to an integer if dest type not integral Summary: I encountered this issue when constant folding during inlining tried to fold away a bitcast of a double to an x86_mmx, which is not an integral type. The test case exposes the same issue with a smaller code snippet during early CSE. Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D18528 llvm-svn: 265367 --- llvm/lib/IR/ConstantFold.cpp | 4 ++++ llvm/test/CodeGen/X86/mmx-bitcast-fold.ll | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 llvm/test/CodeGen/X86/mmx-bitcast-fold.ll diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 62a7f2e40b69..824555ce0445 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -191,6 +191,10 @@ static Constant *FoldBitCast(Constant *V, Type *DestTy) { 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()); } diff --git a/llvm/test/CodeGen/X86/mmx-bitcast-fold.ll b/llvm/test/CodeGen/X86/mmx-bitcast-fold.ll new file mode 100644 index 000000000000..fc7ce73a441e --- /dev/null +++ b/llvm/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)