Avoid dyn_cast to ShapedType
authorGeoffrey Martin-Noble <gcmn@google.com>
Wed, 29 May 2019 22:51:17 +0000 (15:51 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Sun, 2 Jun 2019 03:09:22 +0000 (20:09 -0700)
    ShapedType just indicates shape/rank/element semantics. It's generally not useful for other type checking. This check already checks for vector or tensor type, so we can use a direct cast if we check those first.

    Related to making MemRefType a subclass of ShapedType

--

PiperOrigin-RevId: 250583231

mlir/lib/Quantizer/Configurations/FxpMathConfig.cpp

index 8623df9..d512c4d 100644 (file)
@@ -96,9 +96,8 @@ struct FxpMathTargetConfigImpl : public FxpMathTargetConfig {
   bool isHandledType(Type t) const final {
     if (t.isa<FloatType>())
       return true;
-    auto shapedType = t.dyn_cast<ShapedType>();
-    return (shapedType && shapedType.getElementType().isa<FloatType>() &&
-            (t.isa<VectorType>() || t.isa<TensorType>()));
+    return (t.isa<VectorType>() || t.isa<TensorType>()) &&
+           t.cast<ShapedType>().getElementType().isa<FloatType>();
   }
 
   void finalizeAnchors(CAGSlice &cag) const override {