aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2011-05-18 07:13:41 +0000
committerDuncan Sands <baldrick@free.fr>2011-05-18 07:13:41 +0000
commit117feba971a020653fef3d6d61a16345355b83fd (patch)
tree6e5fa36283ff8948feac04a996743a9697ce50c4 /unittests
parent2a8eb722c7bb0fac2fe09a876f3471dcb25f465e (diff)
Teach getCastOpcode about element-by-element vector casts. For example, "trunc"
can be used to turn a <4 x i64> into a <4 x i32> but getCastOpcode would assert if you passed these types to it. Note that this strictly extends the previous functionality: if getCastOpcode previously accepted two vector types (i.e. didn't assert) then it still will and returns the same opcode (BitCast). That's because before it would only accept vectors with the same bitwidth, and the new code only touches vectors with the same length. However if two vectors have both the same bitwidth and the same length then their element types have the same bitwidth, so the new logic will return BitCast as before. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131530 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/VMCore/InstructionsTest.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/unittests/VMCore/InstructionsTest.cpp b/unittests/VMCore/InstructionsTest.cpp
index 8edcce40cb..9624b816a8 100644
--- a/unittests/VMCore/InstructionsTest.cpp
+++ b/unittests/VMCore/InstructionsTest.cpp
@@ -114,11 +114,19 @@ TEST(InstructionsTest, CastInst) {
const Type* Int8Ty = Type::getInt8Ty(C);
const Type* Int64Ty = Type::getInt64Ty(C);
const Type* V8x8Ty = VectorType::get(Int8Ty, 8);
+ const Type* V8x64Ty = VectorType::get(Int64Ty, 8);
const Type* X86MMXTy = Type::getX86_MMXTy(C);
+ const Constant* c8 = Constant::getNullValue(V8x8Ty);
+ const Constant* c64 = Constant::getNullValue(V8x64Ty);
+
EXPECT_TRUE(CastInst::isCastable(V8x8Ty, X86MMXTy));
EXPECT_TRUE(CastInst::isCastable(X86MMXTy, V8x8Ty));
EXPECT_FALSE(CastInst::isCastable(Int64Ty, X86MMXTy));
+ EXPECT_TRUE(CastInst::isCastable(V8x64Ty, V8x8Ty));
+ EXPECT_TRUE(CastInst::isCastable(V8x8Ty, V8x64Ty));
+ EXPECT_EQ(CastInst::getCastOpcode(c64, true, V8x8Ty, true), CastInst::Trunc);
+ EXPECT_EQ(CastInst::getCastOpcode(c8, true, V8x64Ty, true), CastInst::SExt);
}
} // end anonymous namespace