Skip to content

Commit

Permalink
While testing dragonegg I noticed that isCastable and getCastOpcode
Browse files Browse the repository at this point in the history
had gotten out of sync: isCastable didn't think it was possible to
cast the x86_mmx type to anything, while it did think it possible
to cast an i64 to x86_mmx.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128705 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
CunningBaldrick committed Apr 1, 2011
1 parent 2348232 commit 6079465
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/VMCore/Instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
13 changes: 13 additions & 0 deletions unittests/VMCore/InstructionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6079465

Please sign in to comment.