[PATCH] D72478: [mlir] Use getDenseElementBitwidth instead of Type::getElementTypeBitWidth.

River Riddle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 9 13:13:40 PST 2020


rriddle created this revision.
rriddle added a reviewer: antiagainst.
Herald added subscribers: llvm-commits, lucyrfox, mgester, arpith-jacob, nicolasvasilache, shauheen, burmako, jpienaar, mehdi_amini.
Herald added a project: LLVM.

Some data values have a different storage width than the corresponding MLIR type, e.g. bfloat is currently stored as a double.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72478

Files:
  mlir/lib/IR/Attributes.cpp
  mlir/unittests/IR/AttributeTest.cpp


Index: mlir/unittests/IR/AttributeTest.cpp
===================================================================
--- mlir/unittests/IR/AttributeTest.cpp
+++ mlir/unittests/IR/AttributeTest.cpp
@@ -135,4 +135,14 @@
 
   testSplat(floatTy, value);
 }
+
+TEST(DenseSplatTest, BF16Splat) {
+  MLIRContext context;
+  FloatType floatTy = FloatType::getBF16(&context);
+  // Note: We currently use double to represent bfloat16.
+  double value = 10.0;
+
+  testSplat(floatTy, value);
+}
+
 } // end namespace
Index: mlir/lib/IR/Attributes.cpp
===================================================================
--- mlir/lib/IR/Attributes.cpp
+++ mlir/lib/IR/Attributes.cpp
@@ -676,7 +676,8 @@
 static bool isValidIntOrFloat(ShapedType type, int64_t dataEltSize,
                               bool isInt) {
   // Make sure that the data element size is the same as the type element width.
-  if ((dataEltSize * CHAR_BIT) != type.getElementTypeBitWidth())
+  if (getDenseElementBitwidth(type.getElementType()) !=
+      static_cast<size_t>(dataEltSize * CHAR_BIT))
     return false;
 
   // Check that the element type is valid.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72478.237176.patch
Type: text/x-patch
Size: 1121 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200109/37a2d63a/attachment.bin>


More information about the llvm-commits mailing list