Changeset View
Changeset View
Standalone View
Standalone View
llvm/unittests/IR/DataLayoutTest.cpp
Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | TEST(DataLayoutTest, VectorAlign) { | ||||
Type *const V8F32Ty = FixedVectorType::get(FloatTy, 8); | Type *const V8F32Ty = FixedVectorType::get(FloatTy, 8); | ||||
// The alignment for a vector type larger than any specified vector type uses | // The alignment for a vector type larger than any specified vector type uses | ||||
// the natural alignment as a fallback. | // the natural alignment as a fallback. | ||||
EXPECT_EQ(Align(4 * 8), DL->getABITypeAlign(V8F32Ty)); | EXPECT_EQ(Align(4 * 8), DL->getABITypeAlign(V8F32Ty)); | ||||
EXPECT_EQ(Align(4 * 8), DL->getPrefTypeAlign(V8F32Ty)); | EXPECT_EQ(Align(4 * 8), DL->getPrefTypeAlign(V8F32Ty)); | ||||
} | } | ||||
TEST(DataLayoutTest, VectorAlignElement) { | |||||
LLVMContext Context; | |||||
Type *const FloatTy = Type::getFloatTy(Context); | |||||
Type *const V4F32 = FixedVectorType::get(FloatTy, 4); | |||||
Type *const HalfTy = Type::getHalfTy(Context); | |||||
Type *const V4F16 = FixedVectorType::get(HalfTy, 4); | |||||
{ | |||||
Expected<DataLayout> DL = | |||||
DataLayout::parse("V-f16:16:16-f32:32:32-v64:8:8-v128:8:8"); | |||||
EXPECT_THAT_EXPECTED(DL, Succeeded()); | |||||
EXPECT_TRUE(DL->considersElementAlignment()); | |||||
// The alignment for a vector type larger than any specified vector type | |||||
// uses the natural alignment as a fallback. | |||||
EXPECT_EQ(DL->getABITypeAlign(FloatTy), DL->getABITypeAlign(V4F32)); | |||||
EXPECT_EQ(DL->getABITypeAlign(HalfTy), DL->getABITypeAlign(V4F16)); | |||||
EXPECT_EQ(DL->getPrefTypeAlign(FloatTy), DL->getPrefTypeAlign(V4F32)); | |||||
EXPECT_EQ(DL->getPrefTypeAlign(HalfTy), DL->getPrefTypeAlign(V4F16)); | |||||
} | |||||
{ | |||||
Expected<DataLayout> DL = DataLayout::parse("V-v64:8:8-v128:8:8"); | |||||
EXPECT_THAT_EXPECTED(DL, Succeeded()); | |||||
EXPECT_TRUE(DL->considersElementAlignment()); | |||||
// The alignment for a vector type larger than any specified vector type | |||||
// uses the natural alignment as a fallback. | |||||
EXPECT_EQ(DL->getABITypeAlign(FloatTy), DL->getABITypeAlign(V4F32)); | |||||
EXPECT_EQ(DL->getABITypeAlign(HalfTy), DL->getABITypeAlign(V4F16)); | |||||
EXPECT_EQ(DL->getPrefTypeAlign(FloatTy), DL->getPrefTypeAlign(V4F32)); | |||||
EXPECT_EQ(DL->getPrefTypeAlign(HalfTy), DL->getPrefTypeAlign(V4F16)); | |||||
} | |||||
{ | |||||
Expected<DataLayout> DL = | |||||
DataLayout::parse("f16:16:16-f32:32:32-v64:8:8-v128:8:8"); | |||||
EXPECT_THAT_EXPECTED(DL, Succeeded()); | |||||
EXPECT_FALSE(DL->considersElementAlignment()); | |||||
// Without the `V` option, the vector alignments from the data layout are | |||||
// used regardless of the element alignments. | |||||
EXPECT_EQ(Align(1), DL->getABITypeAlign(V4F32)); | |||||
EXPECT_EQ(Align(1), DL->getABITypeAlign(V4F16)); | |||||
EXPECT_EQ(Align(1), DL->getPrefTypeAlign(V4F32)); | |||||
EXPECT_EQ(Align(1), DL->getPrefTypeAlign(V4F16)); | |||||
} | |||||
} | |||||
} // anonymous namespace | } // anonymous namespace |