[Mlir-commits] [mlir] 6a08c2b - [mlir][tosa] Disable folder for non-int/float/index types in tosa.slice

Robert Suderman llvmlistbot at llvm.org
Thu Mar 30 11:07:11 PDT 2023


Author: Natasha Kononenko
Date: 2023-03-30T18:05:47Z
New Revision: 6a08c2be5880cdaee01031b55c79126ec3d688e2

URL: https://github.com/llvm/llvm-project/commit/6a08c2be5880cdaee01031b55c79126ec3d688e2
DIFF: https://github.com/llvm/llvm-project/commit/6a08c2be5880cdaee01031b55c79126ec3d688e2.diff

LOG: [mlir][tosa] Disable folder for non-int/float/index types in tosa.slice

In order to fold, we need to create an ElementsAttr, and those cannot be
generated from any type. In particular, currently we need to avoid folding
quantized types.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D147191

Added: 
    

Modified: 
    mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
index 16f23e4798c02..ef93e1955b60b 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
@@ -801,7 +801,8 @@ OpFoldResult SubOp::fold(FoldAdaptor adaptor) {
 }
 
 namespace {
-template <typename Cmp> struct ComparisonFold {
+template <typename Cmp>
+struct ComparisonFold {
   ComparisonFold() = default;
   APInt operator()(const APInt &l, const APInt &r) {
     return APInt(1, Cmp()(l, r));
@@ -1047,6 +1048,11 @@ OpFoldResult SliceOp::fold(FoldAdaptor adaptor) {
   if (!adaptor.getInput())
     return {};
 
+  // Cannot create an ElementsAttr from non-int/float/index types
+  if (!inputTy.getElementType().isIntOrIndexOrFloat() ||
+      !outputTy.getElementType().isIntOrIndexOrFloat())
+    return {};
+
   auto operand = adaptor.getInput().cast<ElementsAttr>();
   if (operand.isSplat() && outputTy.hasStaticShape()) {
     return SplatElementsAttr::get(outputTy, operand.getSplatValue<Attribute>());


        


More information about the Mlir-commits mailing list