forked from OSchip/llvm-project
GlobalISel: Add LLT helper to multiply vector sizes
This commit is contained in:
parent
e38c5fded6
commit
12d79b1514
|
@ -207,6 +207,18 @@ public:
|
|||
return scalar(getScalarSizeInBits() / Factor);
|
||||
}
|
||||
|
||||
/// Produce a vector type that is \p Factor times bigger, preserving the
|
||||
/// element type. For a scalar or pointer, this will produce a new vector with
|
||||
/// \p Factor elements.
|
||||
LLT multiplyElements(int Factor) const {
|
||||
if (isVector()) {
|
||||
return scalarOrVector(getElementCount().multiplyCoefficientBy(Factor),
|
||||
getElementType());
|
||||
}
|
||||
|
||||
return fixed_vector(Factor, *this);
|
||||
}
|
||||
|
||||
bool isByteSized() const { return getSizeInBits().isKnownMultipleOf(8); }
|
||||
|
||||
unsigned getScalarSizeInBits() const {
|
||||
|
|
|
@ -362,6 +362,11 @@ public:
|
|||
LinearPolySize::get(getKnownMinValue() / RHS, isScalable()));
|
||||
}
|
||||
|
||||
LeafTy multiplyCoefficientBy(ScalarTy RHS) const {
|
||||
return static_cast<LeafTy>(
|
||||
LinearPolySize::get(getKnownMinValue() * RHS, isScalable()));
|
||||
}
|
||||
|
||||
LeafTy coefficientNextPowerOf2() const {
|
||||
return static_cast<LeafTy>(LinearPolySize::get(
|
||||
static_cast<ScalarTy>(llvm::NextPowerOf2(getKnownMinValue())),
|
||||
|
|
|
@ -319,4 +319,49 @@ TEST(LowLevelTypeTest, Divide) {
|
|||
LLT::fixed_vector(4, LLT::pointer(1, 64)).divide(2));
|
||||
}
|
||||
|
||||
TEST(LowLevelTypeTest, MultiplyElements) {
|
||||
// Basic scalar->vector cases
|
||||
EXPECT_EQ(LLT::fixed_vector(2, 16), LLT::scalar(16).multiplyElements(2));
|
||||
EXPECT_EQ(LLT::fixed_vector(3, 16), LLT::scalar(16).multiplyElements(3));
|
||||
EXPECT_EQ(LLT::fixed_vector(4, 32), LLT::scalar(32).multiplyElements(4));
|
||||
EXPECT_EQ(LLT::fixed_vector(4, 7), LLT::scalar(7).multiplyElements(4));
|
||||
|
||||
// Basic vector to vector cases
|
||||
EXPECT_EQ(LLT::fixed_vector(4, 32),
|
||||
LLT::fixed_vector(2, 32).multiplyElements(2));
|
||||
EXPECT_EQ(LLT::fixed_vector(9, 32),
|
||||
LLT::fixed_vector(3, 32).multiplyElements(3));
|
||||
|
||||
// Pointer to vector of pointers
|
||||
EXPECT_EQ(LLT::fixed_vector(2, LLT::pointer(0, 32)),
|
||||
LLT::pointer(0, 32).multiplyElements(2));
|
||||
EXPECT_EQ(LLT::fixed_vector(3, LLT::pointer(1, 32)),
|
||||
LLT::pointer(1, 32).multiplyElements(3));
|
||||
EXPECT_EQ(LLT::fixed_vector(4, LLT::pointer(1, 64)),
|
||||
LLT::pointer(1, 64).multiplyElements(4));
|
||||
|
||||
// Vector of pointers to vector of pointers
|
||||
EXPECT_EQ(LLT::fixed_vector(8, LLT::pointer(1, 64)),
|
||||
LLT::fixed_vector(2, LLT::pointer(1, 64)).multiplyElements(4));
|
||||
EXPECT_EQ(LLT::fixed_vector(9, LLT::pointer(1, 32)),
|
||||
LLT::fixed_vector(3, LLT::pointer(1, 32)).multiplyElements(3));
|
||||
|
||||
// Scalable vectors
|
||||
EXPECT_EQ(LLT::scalable_vector(4, 16),
|
||||
LLT::scalable_vector(2, 16).multiplyElements(2));
|
||||
EXPECT_EQ(LLT::scalable_vector(6, 16),
|
||||
LLT::scalable_vector(2, 16).multiplyElements(3));
|
||||
EXPECT_EQ(LLT::scalable_vector(9, 16),
|
||||
LLT::scalable_vector(3, 16).multiplyElements(3));
|
||||
EXPECT_EQ(LLT::scalable_vector(4, 32),
|
||||
LLT::scalable_vector(2, 32).multiplyElements(2));
|
||||
EXPECT_EQ(LLT::scalable_vector(256, 32),
|
||||
LLT::scalable_vector(8, 32).multiplyElements(32));
|
||||
|
||||
// Scalable vectors of pointers
|
||||
EXPECT_EQ(LLT::scalable_vector(4, LLT::pointer(0, 32)),
|
||||
LLT::scalable_vector(2, LLT::pointer(0, 32)).multiplyElements(2));
|
||||
EXPECT_EQ(LLT::scalable_vector(32, LLT::pointer(1, 64)),
|
||||
LLT::scalable_vector(8, LLT::pointer(1, 64)).multiplyElements(4));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue