ArrayRef<char> data;
/// The values used to denote a boolean splat value.
- static constexpr char kSplatTrue = ~0;
- static constexpr char kSplatFalse = 0;
+ // This is not using constexpr declaration due to compilation failure
+ // encountered with MSVC where it would inline these values, which makes it
+ // unsafe to refer by reference in KeyTy.
+ static const char kSplatTrue;
+ static const char kSplatFalse;
};
/// An attribute representing a reference to a dense vector or tensor object
// DenseElementsAttr Utilities
//===----------------------------------------------------------------------===//
+const char DenseIntOrFPElementsAttrStorage::kSplatTrue = ~0;
+const char DenseIntOrFPElementsAttrStorage::kSplatFalse = 0;
+
/// Get the bitwidth of a dense element type within the buffer.
/// DenseElementsAttr requires bitwidths greater than 1 to be aligned by 8.
static size_t getDenseElementStorageWidth(size_t origWidth) {
EXPECT_EQ(trueSplat, trueSplatFromRaw);
}
+TEST(DenseSplatTest, BoolSplatSmall) {
+ MLIRContext context;
+ Builder builder(&context);
+
+ // Check that splats that don't fill entire byte are handled properly.
+ auto tensorType = RankedTensorType::get({4}, builder.getI1Type());
+ std::vector<char> data{0b00001111};
+ auto trueSplatFromRaw =
+ DenseIntOrFPElementsAttr::getFromRawBuffer(tensorType, data);
+ EXPECT_TRUE(trueSplatFromRaw.isSplat());
+ DenseElementsAttr trueSplat = DenseElementsAttr::get(tensorType, true);
+ EXPECT_EQ(trueSplat, trueSplatFromRaw);
+}
+
TEST(DenseSplatTest, LargeBoolSplat) {
constexpr int64_t boolCount = 56;