From 6a08c2be5880cdaee01031b55c79126ec3d688e2 Mon Sep 17 00:00:00 2001 From: Natasha Kononenko Date: Thu, 30 Mar 2023 17:57:55 +0000 Subject: [PATCH] [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 --- mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp index 16f23e4..ef93e19 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 struct ComparisonFold { +template +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(); if (operand.isSplat() && outputTy.hasStaticShape()) { return SplatElementsAttr::get(outputTy, operand.getSplatValue()); -- 2.7.4