diff options
| -rw-r--r-- | llvm/lib/VMCore/Instructions.cpp | 16 | ||||
| -rw-r--r-- | llvm/unittests/VMCore/InstructionsTest.cpp | 13 |
2 files changed, 25 insertions, 4 deletions
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp index d1290281cb1..622edde5124 100644 --- a/llvm/lib/VMCore/Instructions.cpp +++ b/llvm/lib/VMCore/Instructions.cpp @@ -2297,8 +2297,12 @@ bool CastInst::isCastable(const Type *SrcTy, const Type *DestTy) { if (const VectorType *SrcPTy = dyn_cast<VectorType>(SrcTy)) { // Casting from vector return DestPTy->getBitWidth() == SrcPTy->getBitWidth(); - } else { // Casting from something else - return DestPTy->getBitWidth() == SrcBits; + } else if (DestPTy->getBitWidth() == SrcBits) { + return true; // float/int -> vector + } else if (SrcTy->isX86_MMXTy()) { + return DestPTy->getBitWidth() == 64; // MMX to 64-bit vector + } else { + return false; } } else if (DestTy->isPointerTy()) { // Casting to pointer if (SrcTy->isPointerTy()) { // Casting from pointer @@ -2308,8 +2312,12 @@ bool CastInst::isCastable(const Type *SrcTy, const Type *DestTy) { } else { // Casting from something else return false; } - } else if (DestTy->isX86_MMXTy()) { - return SrcBits == 64; + } else if (DestTy->isX86_MMXTy()) { + if (const VectorType *SrcPTy = dyn_cast<VectorType>(SrcTy)) { + return SrcPTy->getBitWidth() == 64; // 64-bit vector to MMX + } else { + return false; + } } else { // Casting to something else return false; } diff --git a/llvm/unittests/VMCore/InstructionsTest.cpp b/llvm/unittests/VMCore/InstructionsTest.cpp index 1d1127d863b..d286c73d5c6 100644 --- a/llvm/unittests/VMCore/InstructionsTest.cpp +++ b/llvm/unittests/VMCore/InstructionsTest.cpp @@ -107,5 +107,18 @@ TEST(InstructionsTest, BranchInst) { delete bb1; } +TEST(InstructionsTest, CastInst) { + LLVMContext &C(getGlobalContext()); + + const Type* Int8Ty = Type::getInt8Ty(C); + const Type* Int64Ty = Type::getInt64Ty(C); + const Type* V8x8Ty = VectorType::get(Int8Ty, 8); + const Type* X86MMXTy = Type::getX86_MMXTy(C); + + EXPECT_TRUE(CastInst::isCastable(V8x8Ty, X86MMXTy)); + EXPECT_TRUE(CastInst::isCastable(X86MMXTy, V8x8Ty)); + EXPECT_FALSE(CastInst::isCastable(Int64Ty, X86MMXTy)); +} + } // end anonymous namespace } // end namespace llvm |

