@@ -60,6 +60,12 @@ LogicalResult vectorOneToOneRewrite(Operation *op, StringRef targetOp,
6060 Attribute propertiesAttr,
6161 const LLVMTypeConverter &typeConverter,
6262 ConversionPatternRewriter &rewriter);
63+
64+ // / Return "true" if the given type is an unsupported floating point type. In
65+ // / case of a vector type, return "true" if the element type is an unsupported
66+ // / floating point type.
67+ bool isUnsupportedFloatingPointType (const TypeConverter &typeConverter,
68+ Type type);
6369} // namespace detail
6470} // namespace LLVM
6571
@@ -97,43 +103,25 @@ class VectorConvertToLLVMPattern : public ConvertOpToLLVMPattern<SourceOp> {
97103 using ConvertOpToLLVMPattern<SourceOp>::ConvertOpToLLVMPattern;
98104 using Super = VectorConvertToLLVMPattern<SourceOp, TargetOp>;
99105
100- // / Return the given type if it's a floating point type. If the given type is
101- // / a vector type, return its element type if it's a floating point type.
102- static FloatType getFloatingPointType (Type type) {
103- if (auto floatType = dyn_cast<FloatType>(type))
104- return floatType;
105- if (auto vecType = dyn_cast<VectorType>(type))
106- return dyn_cast<FloatType>(vecType.getElementType ());
107- return nullptr ;
108- }
109-
110106 LogicalResult
111107 matchAndRewrite (SourceOp op, typename SourceOp::Adaptor adaptor,
112108 ConversionPatternRewriter &rewriter) const override {
113109 static_assert (
114110 std::is_base_of<OpTrait::OneResult<SourceOp>, SourceOp>::value,
115111 " expected single result op" );
116112
117- // The pattern should not apply if a floating-point operand is converted to
118- // a non-floating-point type. This indicates that the floating point type
119- // is not supported by the LLVM lowering. (Such types are converted to
120- // integers.)
121- auto checkType = [&](Value v) -> LogicalResult {
122- FloatType floatType = getFloatingPointType (v.getType ());
123- if (!floatType)
124- return success ();
125- Type convertedType = this ->getTypeConverter ()->convertType (floatType);
126- if (!isa_and_nonnull<FloatType>(convertedType))
127- return rewriter.notifyMatchFailure (op,
128- " unsupported floating point type" );
129- return success ();
130- };
113+ // Bail on unsupported floating point types. (These are type-converted to
114+ // integer types.)
131115 if (FailOnUnsupportedFP) {
132116 for (Value operand : op->getOperands ())
133- if (failed (checkType (operand)))
134- return failure ();
135- if (failed (checkType (op->getResult (0 ))))
136- return failure ();
117+ if (LLVM::detail::isUnsupportedFloatingPointType (
118+ *this ->getTypeConverter (), operand.getType ()))
119+ return rewriter.notifyMatchFailure (op,
120+ " unsupported floating point type" );
121+ if (LLVM::detail::isUnsupportedFloatingPointType (
122+ *this ->getTypeConverter (), op->getResult (0 ).getType ()))
123+ return rewriter.notifyMatchFailure (op,
124+ " unsupported floating point type" );
137125 }
138126
139127 // Determine attributes for the target op
0 commit comments