Fix the detection of boolean splat values in DenseElementsAttr for arrays with <=15 values.

PiperOrigin-RevId: 253711372
This commit is contained in:
River Riddle 2019-06-17 19:46:31 -07:00 committed by Mehdi Amini
parent 92d4eb69b5
commit 2b67821b90
2 changed files with 16 additions and 3 deletions

View File

@ -478,9 +478,11 @@ struct DenseElementsAttributeStorage : public AttributeStorage {
splatData = splatData.drop_back();
}
// Check that the data buffer corresponds to a splat.
return llvm::is_splat(splatData) ? generateSplatKey()
: KeyTy(ty, data, llvm::hash_value(data));
// Check that the data buffer corresponds to a splat of the proper mask.
char mask = splatValue ? ~0 : 0;
return llvm::all_of(splatData, [mask](char c) { return c == mask; })
? generateSplatKey()
: KeyTy(ty, data, llvm::hash_value(data));
}
/// Hash the key for the storage.

View File

@ -84,6 +84,17 @@ TEST(DenseSplatTest, LargeBoolSplat) {
EXPECT_EQ(detectedSplat, falseSplat);
}
TEST(DenseSplatTest, BoolNonSplat) {
MLIRContext context;
IntegerType boolTy = IntegerType::get(1, &context);
VectorType shape = VectorType::get({6}, boolTy);
// Check that we properly handle non-splat values.
DenseElementsAttr nonSplat =
DenseElementsAttr::get(shape, {false, false, true, false, false, true});
EXPECT_FALSE(nonSplat.isSplat());
}
TEST(DenseSplatTest, OddIntSplat) {
// Test detecting a splat with an odd(non 8-bit) integer bitwidth.
MLIRContext context;