diff --git a/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp b/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp --- a/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp +++ b/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp @@ -182,16 +182,21 @@ // Helper functions to build math functions approximations. //----------------------------------------------------------------------------// -static Value min(ImplicitLocOpBuilder &builder, Value a, Value b) { +// Return the minimum of the two values or NaN if value is NaN +static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound) { return builder.create( - builder.create(arith::CmpFPredicate::OLT, a, b), a, b); + builder.create(arith::CmpFPredicate::ULT, value, bound), + value, bound); } -static Value max(ImplicitLocOpBuilder &builder, Value a, Value b) { +// Return the maximum of the two values or NaN if value is NaN +static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound) { return builder.create( - builder.create(arith::CmpFPredicate::OGT, a, b), a, b); + builder.create(arith::CmpFPredicate::UGT, value, bound), + value, bound); } +// Return the clamped value or NaN if value is NaN static Value clamp(ImplicitLocOpBuilder &builder, Value value, Value lowerBound, Value upperBound) { return max(builder, min(builder, value, upperBound), lowerBound);