4 changes: 2 additions & 2 deletions mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ void mlir::populateGpuToNVVMConversionPatterns(LLVMTypeConverter &converter,
StringAttr::get(&converter.getContext(),
NVVM::NVVMDialect::getKernelFuncAttrName()));

patterns.add<OpToFuncCallLowering<math::AbsOp>>(converter, "__nv_fabsf",
"__nv_fabs");
patterns.add<OpToFuncCallLowering<math::AbsFOp>>(converter, "__nv_fabsf",
"__nv_fabs");
patterns.add<OpToFuncCallLowering<math::AtanOp>>(converter, "__nv_atanf",
"__nv_atan");
patterns.add<OpToFuncCallLowering<math::Atan2Op>>(converter, "__nv_atan2f",
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ void mlir::populateGpuToROCDLConversionPatterns(
patterns.add<GPUPrintfOpToLLVMCallLowering>(converter, /*addressSpace=*/4);
}

patterns.add<OpToFuncCallLowering<math::AbsOp>>(converter, "__ocml_fabs_f32",
"__ocml_fabs_f64");
patterns.add<OpToFuncCallLowering<math::AbsFOp>>(converter, "__ocml_fabs_f32",
"__ocml_fabs_f64");
patterns.add<OpToFuncCallLowering<math::AtanOp>>(converter, "__ocml_atan_f32",
"__ocml_atan_f64");
patterns.add<OpToFuncCallLowering<math::Atan2Op>>(
Expand Down
6 changes: 4 additions & 2 deletions mlir/lib/Conversion/MathToLLVM/MathToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
using namespace mlir;

namespace {
using AbsOpLowering = VectorConvertToLLVMPattern<math::AbsOp, LLVM::FAbsOp>;
using AbsFOpLowering = VectorConvertToLLVMPattern<math::AbsFOp, LLVM::FAbsOp>;
using AbsIOpLowering = VectorConvertToLLVMPattern<math::AbsIOp, LLVM::AbsOp>;
using CeilOpLowering = VectorConvertToLLVMPattern<math::CeilOp, LLVM::FCeilOp>;
using CopySignOpLowering =
VectorConvertToLLVMPattern<math::CopySignOp, LLVM::CopySignOp>;
Expand Down Expand Up @@ -268,7 +269,8 @@ void mlir::populateMathToLLVMConversionPatterns(LLVMTypeConverter &converter,
RewritePatternSet &patterns) {
// clang-format off
patterns.add<
AbsOpLowering,
AbsFOpLowering,
AbsIOpLowering,
CeilOpLowering,
CopySignOpLowering,
CosOpLowering,
Expand Down
5 changes: 3 additions & 2 deletions mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ void populateMathToSPIRVPatterns(SPIRVTypeConverter &typeConverter,
patterns
.add<CountLeadingZerosPattern, Log1pOpPattern<spirv::GLLogOp>,
ExpM1OpPattern<spirv::GLExpOp>, PowFOpPattern, RoundOpPattern,
spirv::ElementwiseOpPattern<math::AbsOp, spirv::GLFAbsOp>,
spirv::ElementwiseOpPattern<math::AbsFOp, spirv::GLFAbsOp>,
spirv::ElementwiseOpPattern<math::AbsIOp, spirv::GLSAbsOp>,
spirv::ElementwiseOpPattern<math::CeilOp, spirv::GLCeilOp>,
spirv::ElementwiseOpPattern<math::CosOp, spirv::GLCosOp>,
spirv::ElementwiseOpPattern<math::ExpOp, spirv::GLExpOp>,
Expand All @@ -302,7 +303,7 @@ void populateMathToSPIRVPatterns(SPIRVTypeConverter &typeConverter,

// OpenCL patterns
patterns.add<Log1pOpPattern<spirv::CLLogOp>, ExpM1OpPattern<spirv::CLExpOp>,
spirv::ElementwiseOpPattern<math::AbsOp, spirv::CLFAbsOp>,
spirv::ElementwiseOpPattern<math::AbsFOp, spirv::CLFAbsOp>,
spirv::ElementwiseOpPattern<math::CeilOp, spirv::CLCeilOp>,
spirv::ElementwiseOpPattern<math::CosOp, spirv::CLCosOp>,
spirv::ElementwiseOpPattern<math::ErfOp, spirv::CLErfOp>,
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ createLinalgBodyCalculationForElementwiseOp(Operation *op, ValueRange args,

// tosa::AbsOp
if (isa<tosa::AbsOp>(op) && elementTy.isa<FloatType>())
return rewriter.create<math::AbsOp>(loc, resultTypes, args);
return rewriter.create<math::AbsFOp>(loc, resultTypes, args);

if (isa<tosa::AbsOp>(op) && elementTy.isa<IntegerType>()) {
auto zero = rewriter.create<arith::ConstantOp>(
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class RegionBuilderHelper {
case UnaryFn::log:
return builder.create<math::LogOp>(arg.getLoc(), arg);
case UnaryFn::abs:
return builder.create<math::AbsOp>(arg.getLoc(), arg);
return builder.create<math::AbsFOp>(arg.getLoc(), arg);
case UnaryFn::ceil:
return builder.create<math::CeilOp>(arg.getLoc(), arg);
case UnaryFn::floor:
Expand Down
19 changes: 13 additions & 6 deletions mlir/lib/Dialect/Math/IR/MathOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ using namespace mlir::math;
#include "mlir/Dialect/Math/IR/MathOps.cpp.inc"

//===----------------------------------------------------------------------===//
// AbsOp folder
// AbsFOp folder
//===----------------------------------------------------------------------===//

OpFoldResult math::AbsOp::fold(ArrayRef<Attribute> operands) {
return constFoldUnaryOp<FloatAttr>(operands, [](const APFloat &a) {
const APFloat &result(a);
return abs(result);
});
OpFoldResult math::AbsFOp::fold(ArrayRef<Attribute> operands) {
return constFoldUnaryOp<FloatAttr>(operands,
[](const APFloat &a) { return abs(a); });
}

//===----------------------------------------------------------------------===//
// AbsIOp folder
//===----------------------------------------------------------------------===//

OpFoldResult math::AbsIOp::fold(ArrayRef<Attribute> operands) {
return constFoldUnaryOp<IntegerAttr>(operands,
[](const APInt &a) { return a.abs(); });
}

//===----------------------------------------------------------------------===//
Expand Down
6 changes: 3 additions & 3 deletions mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static std::pair<Value, Value> frexp(ImplicitLocOpBuilder &builder, Value arg,
Value normalizedFraction = builder.create<arith::BitcastOp>(f32Vec, tmp1);

// Compute exponent.
Value arg0 = isPositive ? arg : builder.create<math::AbsOp>(arg);
Value arg0 = isPositive ? arg : builder.create<math::AbsFOp>(arg);
Value biasedExponentBits = builder.create<arith::ShRUIOp>(
builder.create<arith::BitcastOp>(i32Vec, arg0),
bcast(i32Cst(builder, 23)));
Expand Down Expand Up @@ -375,7 +375,7 @@ AtanApproximation::matchAndRewrite(math::AtanOp op,

// Remap the problem over [0.0, 1.0] by looking at the absolute value and the
// handling symmetry.
Value abs = builder.create<math::AbsOp>(operand);
Value abs = builder.create<math::AbsFOp>(operand);
Value reciprocal = builder.create<arith::DivFOp>(one, abs);
Value compare =
builder.create<arith::CmpFOp>(arith::CmpFPredicate::OLT, abs, reciprocal);
Expand Down Expand Up @@ -507,7 +507,7 @@ TanhApproximation::matchAndRewrite(math::TanhOp op,
// Mask for tiny values that are approximated with `operand`.
Value tiny = bcast(f32Cst(builder, 0.0004f));
Value tinyMask = builder.create<arith::CmpFOp>(
arith::CmpFPredicate::OLT, builder.create<math::AbsOp>(op.getOperand()),
arith::CmpFPredicate::OLT, builder.create<math::AbsFOp>(op.getOperand()),
tiny);

// The monomial coefficients of the numerator polynomial (odd).
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ Optional<unsigned> Merger::buildTensorExp(linalg::GenericOp op, Value v) {
auto x = buildTensorExp(op, def->getOperand(0));
if (x.has_value()) {
unsigned e = x.value();
if (isa<math::AbsOp>(def))
if (isa<math::AbsFOp>(def))
return addExp(kAbsF, e);
if (isa<complex::AbsOp>(def))
return addExp(kAbsC, e);
Expand Down Expand Up @@ -1073,7 +1073,7 @@ Value Merger::buildExp(RewriterBase &rewriter, Location loc, unsigned e,
llvm_unreachable("unexpected non-op");
// Unary operations.
case kAbsF:
return rewriter.create<math::AbsOp>(loc, v0);
return rewriter.create<math::AbsFOp>(loc, v0);
case kAbsC: {
auto type = v0.getType().cast<ComplexType>();
auto eltType = type.getElementType().cast<FloatType>();
Expand Down
32 changes: 16 additions & 16 deletions mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ func.func @complex_div(%lhs: complex<f32>, %rhs: complex<f32>) -> complex<f32> {

// Case 1. Zero denominator, numerator contains at most one NaN value.
// CHECK: %[[ZERO:.*]] = arith.constant 0.000000e+00 : f32
// CHECK: %[[RHS_REAL_ABS:.*]] = math.abs %[[RHS_REAL]] : f32
// CHECK: %[[RHS_REAL_ABS:.*]] = math.absf %[[RHS_REAL]] : f32
// CHECK: %[[RHS_REAL_ABS_IS_ZERO:.*]] = arith.cmpf oeq, %[[RHS_REAL_ABS]], %[[ZERO]] : f32
// CHECK: %[[RHS_IMAG_ABS:.*]] = math.abs %[[RHS_IMAG]] : f32
// CHECK: %[[RHS_IMAG_ABS:.*]] = math.absf %[[RHS_IMAG]] : f32
// CHECK: %[[RHS_IMAG_ABS_IS_ZERO:.*]] = arith.cmpf oeq, %[[RHS_IMAG_ABS]], %[[ZERO]] : f32
// CHECK: %[[LHS_REAL_IS_NOT_NAN:.*]] = arith.cmpf ord, %[[LHS_REAL]], %[[ZERO]] : f32
// CHECK: %[[LHS_IMAG_IS_NOT_NAN:.*]] = arith.cmpf ord, %[[LHS_IMAG]], %[[ZERO]] : f32
Expand All @@ -117,9 +117,9 @@ func.func @complex_div(%lhs: complex<f32>, %rhs: complex<f32>) -> complex<f32> {
// CHECK: %[[RHS_REAL_FINITE:.*]] = arith.cmpf one, %[[RHS_REAL_ABS]], %[[INF]] : f32
// CHECK: %[[RHS_IMAG_FINITE:.*]] = arith.cmpf one, %[[RHS_IMAG_ABS]], %[[INF]] : f32
// CHECK: %[[RHS_IS_FINITE:.*]] = arith.andi %[[RHS_REAL_FINITE]], %[[RHS_IMAG_FINITE]] : i1
// CHECK: %[[LHS_REAL_ABS:.*]] = math.abs %[[LHS_REAL]] : f32
// CHECK: %[[LHS_REAL_ABS:.*]] = math.absf %[[LHS_REAL]] : f32
// CHECK: %[[LHS_REAL_INFINITE:.*]] = arith.cmpf oeq, %[[LHS_REAL_ABS]], %[[INF]] : f32
// CHECK: %[[LHS_IMAG_ABS:.*]] = math.abs %[[LHS_IMAG]] : f32
// CHECK: %[[LHS_IMAG_ABS:.*]] = math.absf %[[LHS_IMAG]] : f32
// CHECK: %[[LHS_IMAG_INFINITE:.*]] = arith.cmpf oeq, %[[LHS_IMAG_ABS]], %[[INF]] : f32
// CHECK: %[[LHS_IS_INFINITE:.*]] = arith.ori %[[LHS_REAL_INFINITE]], %[[LHS_IMAG_INFINITE]] : i1
// CHECK: %[[INF_NUM_FINITE_DENOM:.*]] = arith.andi %[[LHS_IS_INFINITE]], %[[RHS_IS_FINITE]] : i1
Expand Down Expand Up @@ -289,24 +289,24 @@ func.func @complex_mul(%lhs: complex<f32>, %rhs: complex<f32>) -> complex<f32> {
return %mul : complex<f32>
}
// CHECK: %[[LHS_REAL:.*]] = complex.re %[[LHS]] : complex<f32>
// CHECK: %[[LHS_REAL_ABS:.*]] = math.abs %[[LHS_REAL]] : f32
// CHECK: %[[LHS_REAL_ABS:.*]] = math.absf %[[LHS_REAL]] : f32
// CHECK: %[[LHS_IMAG:.*]] = complex.im %[[LHS]] : complex<f32>
// CHECK: %[[LHS_IMAG_ABS:.*]] = math.abs %[[LHS_IMAG]] : f32
// CHECK: %[[LHS_IMAG_ABS:.*]] = math.absf %[[LHS_IMAG]] : f32
// CHECK: %[[RHS_REAL:.*]] = complex.re %[[RHS]] : complex<f32>
// CHECK: %[[RHS_REAL_ABS:.*]] = math.abs %[[RHS_REAL]] : f32
// CHECK: %[[RHS_REAL_ABS:.*]] = math.absf %[[RHS_REAL]] : f32
// CHECK: %[[RHS_IMAG:.*]] = complex.im %[[RHS]] : complex<f32>
// CHECK: %[[RHS_IMAG_ABS:.*]] = math.abs %[[RHS_IMAG]] : f32
// CHECK: %[[RHS_IMAG_ABS:.*]] = math.absf %[[RHS_IMAG]] : f32

// CHECK: %[[LHS_REAL_TIMES_RHS_REAL:.*]] = arith.mulf %[[LHS_REAL]], %[[RHS_REAL]] : f32
// CHECK: %[[LHS_REAL_TIMES_RHS_REAL_ABS:.*]] = math.abs %[[LHS_REAL_TIMES_RHS_REAL]] : f32
// CHECK: %[[LHS_REAL_TIMES_RHS_REAL_ABS:.*]] = math.absf %[[LHS_REAL_TIMES_RHS_REAL]] : f32
// CHECK: %[[LHS_IMAG_TIMES_RHS_IMAG:.*]] = arith.mulf %[[LHS_IMAG]], %[[RHS_IMAG]] : f32
// CHECK: %[[LHS_IMAG_TIMES_RHS_IMAG_ABS:.*]] = math.abs %[[LHS_IMAG_TIMES_RHS_IMAG]] : f32
// CHECK: %[[LHS_IMAG_TIMES_RHS_IMAG_ABS:.*]] = math.absf %[[LHS_IMAG_TIMES_RHS_IMAG]] : f32
// CHECK: %[[REAL:.*]] = arith.subf %[[LHS_REAL_TIMES_RHS_REAL]], %[[LHS_IMAG_TIMES_RHS_IMAG]] : f32

// CHECK: %[[LHS_IMAG_TIMES_RHS_REAL:.*]] = arith.mulf %[[LHS_IMAG]], %[[RHS_REAL]] : f32
// CHECK: %[[LHS_IMAG_TIMES_RHS_REAL_ABS:.*]] = math.abs %[[LHS_IMAG_TIMES_RHS_REAL]] : f32
// CHECK: %[[LHS_IMAG_TIMES_RHS_REAL_ABS:.*]] = math.absf %[[LHS_IMAG_TIMES_RHS_REAL]] : f32
// CHECK: %[[LHS_REAL_TIMES_RHS_IMAG:.*]] = arith.mulf %[[LHS_REAL]], %[[RHS_IMAG]] : f32
// CHECK: %[[LHS_REAL_TIMES_RHS_IMAG_ABS:.*]] = math.abs %[[LHS_REAL_TIMES_RHS_IMAG]] : f32
// CHECK: %[[LHS_REAL_TIMES_RHS_IMAG_ABS:.*]] = math.absf %[[LHS_REAL_TIMES_RHS_IMAG]] : f32
// CHECK: %[[IMAG:.*]] = arith.addf %[[LHS_IMAG_TIMES_RHS_REAL]], %[[LHS_REAL_TIMES_RHS_IMAG]] : f32

// Handle cases where the "naive" calculation results in NaN values.
Expand Down Expand Up @@ -561,9 +561,9 @@ func.func @complex_tan(%arg: complex<f32>) -> complex<f32> {

// Case 1. Zero denominator, numerator contains at most one NaN value.
// CHECK: %[[ZERO:.*]] = arith.constant 0.000000e+00 : f32
// CHECK: %[[RHS_REAL_ABS:.*]] = math.abs %[[RHS_REAL]] : f32
// CHECK: %[[RHS_REAL_ABS:.*]] = math.absf %[[RHS_REAL]] : f32
// CHECK: %[[RHS_REAL_ABS_IS_ZERO:.*]] = arith.cmpf oeq, %[[RHS_REAL_ABS]], %[[ZERO]] : f32
// CHECK: %[[RHS_IMAG_ABS:.*]] = math.abs %[[RHS_IMAG]] : f32
// CHECK: %[[RHS_IMAG_ABS:.*]] = math.absf %[[RHS_IMAG]] : f32
// CHECK: %[[RHS_IMAG_ABS_IS_ZERO:.*]] = arith.cmpf oeq, %[[RHS_IMAG_ABS]], %[[ZERO]] : f32
// CHECK: %[[LHS_REAL_IS_NOT_NAN:.*]] = arith.cmpf ord, %[[LHS_REAL]], %[[ZERO]] : f32
// CHECK: %[[LHS_IMAG_IS_NOT_NAN:.*]] = arith.cmpf ord, %[[LHS_IMAG]], %[[ZERO]] : f32
Expand All @@ -579,9 +579,9 @@ func.func @complex_tan(%arg: complex<f32>) -> complex<f32> {
// CHECK: %[[RHS_REAL_FINITE:.*]] = arith.cmpf one, %[[RHS_REAL_ABS]], %[[INF]] : f32
// CHECK: %[[RHS_IMAG_FINITE:.*]] = arith.cmpf one, %[[RHS_IMAG_ABS]], %[[INF]] : f32
// CHECK: %[[RHS_IS_FINITE:.*]] = arith.andi %[[RHS_REAL_FINITE]], %[[RHS_IMAG_FINITE]] : i1
// CHECK: %[[LHS_REAL_ABS:.*]] = math.abs %[[LHS_REAL]] : f32
// CHECK: %[[LHS_REAL_ABS:.*]] = math.absf %[[LHS_REAL]] : f32
// CHECK: %[[LHS_REAL_INFINITE:.*]] = arith.cmpf oeq, %[[LHS_REAL_ABS]], %[[INF]] : f32
// CHECK: %[[LHS_IMAG_ABS:.*]] = math.abs %[[LHS_IMAG]] : f32
// CHECK: %[[LHS_IMAG_ABS:.*]] = math.absf %[[LHS_IMAG]] : f32
// CHECK: %[[LHS_IMAG_INFINITE:.*]] = arith.cmpf oeq, %[[LHS_IMAG_ABS]], %[[INF]] : f32
// CHECK: %[[LHS_IS_INFINITE:.*]] = arith.ori %[[LHS_REAL_INFINITE]], %[[LHS_IMAG_INFINITE]] : i1
// CHECK: %[[INF_NUM_FINITE_DENOM:.*]] = arith.andi %[[LHS_IS_INFINITE]], %[[RHS_IS_FINITE]] : i1
Expand Down
5 changes: 2 additions & 3 deletions mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ gpu.module @test_module {
// CHECK: llvm.func @__nv_fabs(f64) -> f64
// CHECK-LABEL: func @gpu_fabs
func.func @gpu_fabs(%arg_f32 : f32, %arg_f64 : f64) -> (f32, f64) {
%result32 = math.abs %arg_f32 : f32
%result32 = math.absf %arg_f32 : f32
// CHECK: llvm.call @__nv_fabsf(%{{.*}}) : (f32) -> f32
%result64 = math.abs %arg_f64 : f64
%result64 = math.absf %arg_f64 : f64
// CHECK: llvm.call @__nv_fabs(%{{.*}}) : (f64) -> f64
func.return %result32, %result64 : f32, f64
}
Expand Down Expand Up @@ -487,4 +487,3 @@ gpu.module @test_module {
gpu.return
}
}

4 changes: 2 additions & 2 deletions mlir/test/Conversion/GPUToROCDL/gpu-to-rocdl.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ gpu.module @test_module {
// CHECK: llvm.func @__ocml_fabs_f64(f64) -> f64
// CHECK-LABEL: func @gpu_fabs
func.func @gpu_fabs(%arg_f32 : f32, %arg_f64 : f64) -> (f32, f64) {
%result32 = math.abs %arg_f32 : f32
%result32 = math.absf %arg_f32 : f32
// CHECK: llvm.call @__ocml_fabs_f32(%{{.*}}) : (f32) -> f32
%result64 = math.abs %arg_f64 : f64
%result64 = math.absf %arg_f64 : f64
// CHECK: llvm.call @__ocml_fabs_f64(%{{.*}}) : (f64) -> f64
func.return %result32, %result64 : f32, f64
}
Expand Down
18 changes: 10 additions & 8 deletions mlir/test/Conversion/MathToLLVM/math-to-llvm.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

// CHECK-LABEL: @ops
func.func @ops(%arg0: f32, %arg1: f32, %arg2: i32, %arg3: i32, %arg4: f64) {
// CHECK: = "llvm.intr.exp"(%{{.*}}) : (f32) -> f32
%13 = math.exp %arg0 : f32
// CHECK: = "llvm.intr.exp2"(%{{.*}}) : (f32) -> f32
%14 = math.exp2 %arg0 : f32
// CHECK: = "llvm.intr.sqrt"(%{{.*}}) : (f32) -> f32
%19 = math.sqrt %arg0 : f32
// CHECK: = "llvm.intr.sqrt"(%{{.*}}) : (f64) -> f64
%20 = math.sqrt %arg4 : f64
// CHECK: = "llvm.intr.exp"(%{{.*}}) : (f32) -> f32
%0 = math.exp %arg0 : f32
// CHECK: = "llvm.intr.exp2"(%{{.*}}) : (f32) -> f32
%1 = math.exp2 %arg0 : f32
// CHECK: = "llvm.intr.sqrt"(%{{.*}}) : (f32) -> f32
%2 = math.sqrt %arg0 : f32
// CHECK: = "llvm.intr.sqrt"(%{{.*}}) : (f64) -> f64
%3 = math.sqrt %arg4 : f64
// CHECK: = "llvm.intr.abs"(%{{.*}}) : (i32) -> i32
%4 = math.absi %arg2 : i32
func.return
}

Expand Down
9 changes: 8 additions & 1 deletion mlir/test/Conversion/MathToSPIRV/math-to-gl-spirv.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func.func @float32_unary_scalar(%arg0: f32) {
// CHECK: spv.GL.Sin %{{.*}}: f32
%8 = math.sin %arg0 : f32
// CHECK: spv.GL.FAbs %{{.*}}: f32
%9 = math.abs %arg0 : f32
%9 = math.absf %arg0 : f32
// CHECK: spv.GL.Ceil %{{.*}}: f32
%10 = math.ceil %arg0 : f32
// CHECK: spv.GL.Floor %{{.*}}: f32
Expand Down Expand Up @@ -79,6 +79,13 @@ func.func @float32_ternary_vector(%a: vector<4xf32>, %b: vector<4xf32>,
return
}

// CHECK-LABEL: @int_unary
func.func @int_unary(%arg0: i32) {
// CHECK: spv.GL.SAbs %{{.*}}
%0 = math.absi %arg0 : i32
return
}

// CHECK-LABEL: @ctlz_scalar
// CHECK-SAME: (%[[VAL:.+]]: i32)
func.func @ctlz_scalar(%val: i32) -> i32 {
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Conversion/MathToSPIRV/math-to-opencl-spirv.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func.func @float32_unary_scalar(%arg0: f32) {
// CHECK: spv.CL.sin %{{.*}}: f32
%8 = math.sin %arg0 : f32
// CHECK: spv.CL.fabs %{{.*}}: f32
%9 = math.abs %arg0 : f32
%9 = math.absf %arg0 : f32
// CHECK: spv.CL.ceil %{{.*}}: f32
%10 = math.ceil %arg0 : f32
// CHECK: spv.CL.floor %{{.*}}: f32
Expand Down
16 changes: 8 additions & 8 deletions mlir/test/Conversion/TosaToLinalg/tosa-to-linalg.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ func.func @test_abs(%arg0: tensor<f32>) -> tensor<f32> {
// CHECK: [[INIT:%.+]] = linalg.init_tensor [] : tensor<f32>
// CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = []} ins(%arg0 : tensor<f32>) outs([[INIT]] : tensor<f32>) {
// CHECK: ^bb0(%arg1: f32, %arg2: f32):
// CHECK: [[ELEMENT:%.+]] = math.abs %arg1
// CHECK: [[ELEMENT:%.+]] = math.absf %arg1
// CHECK: linalg.yield [[ELEMENT]] : f32
// CHECK: } -> tensor<f32>

Expand All @@ -26,7 +26,7 @@ func.func @test_abs(%arg0: tensor<2xf32>) -> tensor<2xf32> {
// CHECK: [[INIT:%.+]] = linalg.init_tensor [2] : tensor<2xf32>
// CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel"]} ins(%arg0 : tensor<2xf32>) outs([[INIT]] : tensor<2xf32>) {
// CHECK: ^bb0(%arg1: f32, %arg2: f32):
// CHECK: [[ELEMENT:%.+]] = math.abs %arg1
// CHECK: [[ELEMENT:%.+]] = math.absf %arg1
// CHECK: linalg.yield [[ELEMENT]] : f32
// CHECK: } -> tensor<2xf32>
%0 = "tosa.abs"(%arg0) : (tensor<2xf32>) -> tensor<2xf32>
Expand All @@ -44,7 +44,7 @@ func.func @test_abs(%arg0: tensor<2x3xf32>) -> tensor<2x3xf32> {
// CHECK: [[INIT:%.+]] = linalg.init_tensor [2, 3] : tensor<2x3xf32>
// CHECK: [[GENERIC:%.+]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP0]]], iterator_types = ["parallel", "parallel"]} ins(%arg0 : tensor<2x3xf32>) outs([[INIT]] : tensor<2x3xf32>) {
// CHECK: ^bb0(%arg1: f32, %arg2: f32):
// CHECK: [[ELEMENT:%.+]] = math.abs %arg1
// CHECK: [[ELEMENT:%.+]] = math.absf %arg1
// CHECK: linalg.yield [[ELEMENT]] : f32
// CHECK: } -> tensor<2x3xf32>
%0 = "tosa.abs"(%arg0) : (tensor<2x3xf32>) -> tensor<2x3xf32>
Expand All @@ -61,7 +61,7 @@ func.func @test_abs(%arg0: tensor<?xf32>) -> tensor<?xf32> {
// CHECK: %[[DIM:.+]] = tensor.dim %arg0, %[[C0]]
// CHECK: %[[INIT:.+]] = linalg.init_tensor [%[[DIM]]]
// CHECK: linalg.generic
// CHECK: math.abs
// CHECK: math.absf
%0 = "tosa.abs"(%arg0) : (tensor<?xf32>) -> tensor<?xf32>
return %0 : tensor<?xf32>
}
Expand All @@ -76,7 +76,7 @@ func.func @test_abs_dyn(%arg0: tensor<2x?xf32>) -> tensor<2x?xf32> {
// CHECK: %[[DIM:.+]] = tensor.dim %arg0, %[[C1]]
// CHECK: %[[INIT:.+]] = linalg.init_tensor [2, %[[DIM]]]
// CHECK: linalg.generic
// CHECK: math.abs
// CHECK: math.absf
%0 = "tosa.abs"(%arg0) : (tensor<2x?xf32>) -> tensor<2x?xf32>
return %0 : tensor<2x?xf32>
}
Expand Down Expand Up @@ -146,7 +146,7 @@ func.func @test_simple_f32(%arg0: tensor<1xf32>) -> () {
%0 = "tosa.tanh"(%arg0) : (tensor<1xf32>) -> tensor<1xf32>

// CHECK: linalg.generic
// CHECK: math.abs
// CHECK: math.absf
%1 = "tosa.abs"(%arg0) : (tensor<1xf32>) -> tensor<1xf32>

// CHECK: linalg.generic
Expand Down Expand Up @@ -1252,7 +1252,7 @@ func.func @pad_float(%arg0 : tensor<1x2xf32>) -> (tensor<4x9xf32>) {
// CHECK-DAG: [[INDEX4:%.+]] = arith.constant 4 : index
// CHECK-DAG: [[CST:%.+]] = arith.constant 0.000000e+00 : f32
// CHECK: tensor.pad %arg0 low{{\[}}%{{.*}}, [[INDEX3]]] high{{\[}}[[INDEX2]], [[INDEX4]]] {
// CHECK: ^bb0(%arg1: index, %arg2: index):
// CHECK: ^bb0(%arg1: index, %arg2: index):
// CHECK: tensor.yield [[CST]]
// CHECK: } : tensor<1x2xf32> to tensor<4x9xf32>
%1 = "tosa.pad"(%arg0, %0) : (tensor<1x2xf32>, tensor<2x2xi32>) -> (tensor<4x9xf32>)
Expand Down Expand Up @@ -1288,7 +1288,7 @@ func.func @pad_float_explicit(%arg0 : tensor<1x2xf32>) -> (tensor<4x9xf32>) {
// CHECK-DAG: [[INDEX4:%.+]] = arith.constant 4 : index
// CHECK-DAG: [[CST:%.+]] = arith.constant 4.200000e+01 : f32
// CHECK: tensor.pad %arg0 low{{\[}}%{{.*}}, [[INDEX3]]] high{{\[}}[[INDEX2]], [[INDEX4]]] {
// CHECK: ^bb0(%arg1: index, %arg2: index):
// CHECK: ^bb0(%arg1: index, %arg2: index):
// CHECK: tensor.yield [[CST]]
// CHECK: } : tensor<1x2xf32> to tensor<4x9xf32>
%1 = arith.constant dense<42.0> : tensor<f32>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func.func @generalize_elemwise_abs(%lhs : tensor<4x8xf32>, %output : tensor<4x8x
}

// CHECK-LABEL: @generalize_elemwise_abs
// CHECK: = math.abs
// CHECK: = math.absf

// -----

Expand Down
4 changes: 2 additions & 2 deletions mlir/test/Dialect/Math/canonicalize.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: mlir-opt %s -canonicalize | FileCheck %s
// RUN: mlir-opt %s -canonicalize | FileCheck %s

// CHECK-LABEL: @ceil_fold
// CHECK: %[[cst:.+]] = arith.constant 1.000000e+00 : f32
Expand Down Expand Up @@ -125,7 +125,7 @@ func.func @sqrt_fold_vec() -> (vector<4xf32>) {
// CHECK: return %[[cst]]
func.func @abs_fold() -> f32 {
%c = arith.constant -4.0 : f32
%r = math.abs %c : f32
%r = math.absf %c : f32
return %r : f32
}

Expand Down
7 changes: 3 additions & 4 deletions mlir/test/Dialect/Math/polynomial-approximation.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func.func @log1p_vector(%arg0: vector<8xf32>) -> vector<8xf32> {
// CHECK: %[[VAL_16:.*]] = arith.select %[[VAL_15]], %[[VAL_0]], %[[VAL_2]] : f32
// CHECK: %[[VAL_17:.*]] = arith.cmpf ugt, %[[VAL_16]], %[[VAL_1]] : f32
// CHECK: %[[VAL_18:.*]] = arith.select %[[VAL_17]], %[[VAL_16]], %[[VAL_1]] : f32
// CHECK: %[[VAL_19:.*]] = math.abs %[[VAL_0]] : f32
// CHECK: %[[VAL_19:.*]] = math.absf %[[VAL_0]] : f32
// CHECK: %[[VAL_20:.*]] = arith.cmpf olt, %[[VAL_19]], %[[VAL_3]] : f32
// CHECK: %[[VAL_21:.*]] = arith.mulf %[[VAL_18]], %[[VAL_18]] : f32
// CHECK: %[[VAL_22:.*]] = math.fma %[[VAL_21]], %[[VAL_10]], %[[VAL_9]] : f32
Expand Down Expand Up @@ -517,7 +517,7 @@ func.func @rsqrt_vector_2x16xf32(%arg0: vector<2x16xf32>) -> vector<2x16xf32> {
// CHECK-DAG: %[[N3:.+]] = arith.constant -0.0106783099
// CHECK-DAG: %[[N4:.+]] = arith.constant 1.00209987
// CHECK-DAG: %[[HALF_PI:.+]] = arith.constant 1.57079637
// CHECK-DAG: %[[ABS:.+]] = math.abs %arg0
// CHECK-DAG: %[[ABS:.+]] = math.absf %arg0
// CHECK-DAG: %[[DIV:.+]] = arith.divf %cst, %[[ABS]]
// CHECK-DAG: %[[CMP:.+]] = arith.cmpf olt, %[[ABS]], %[[DIV]]
// CHECK-DAG: %[[SEL:.+]] = arith.select %[[CMP]], %[[ABS]], %[[DIV]]
Expand Down Expand Up @@ -547,7 +547,7 @@ func.func @atan_scalar(%arg0: f32) -> f32 {
// CHECK-DAG: %[[ARG0:.+]] = arith.extf %arg0 : f16 to f32
// CHECK-DAG: %[[ARG1:.+]] = arith.extf %arg1 : f16 to f32
// CHECK-DAG: %[[RATIO:.+]] = arith.divf %[[ARG0]], %[[ARG1]]
// CHECK-DAG: %[[ABS:.+]] = math.abs %[[RATIO]]
// CHECK-DAG: %[[ABS:.+]] = math.absf %[[RATIO]]
// CHECK-DAG: %[[DIV:.+]] = arith.divf %cst, %[[ABS]]
// CHECK-DAG: %[[CMP:.+]] = arith.cmpf olt, %[[ABS]], %[[DIV]]
// CHECK-DAG: %[[SEL:.+]] = arith.select %[[CMP]], %[[ABS]], %[[DIV]]
Expand Down Expand Up @@ -593,4 +593,3 @@ func.func @atan2_scalar(%arg0: f16, %arg1: f16) -> f16 {
%0 = math.atan2 %arg0, %arg1 : f16
return %0 : f16
}

8 changes: 4 additions & 4 deletions mlir/test/Dialect/SparseTensor/sparse_fp_ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
// CHECK: scf.for %[[VAL_10:.*]] = %[[VAL_8]] to %[[VAL_9]] step %[[VAL_3]] {
// CHECK: %[[VAL_11:.*]] = memref.load %[[VAL_5]]{{\[}}%[[VAL_10]]] : memref<?xindex>
// CHECK: %[[VAL_12:.*]] = memref.load %[[VAL_6]]{{\[}}%[[VAL_10]]] : memref<?xf64>
// CHECK: %[[VAL_13:.*]] = math.abs %[[VAL_12]] : f64
// CHECK: %[[VAL_13:.*]] = math.absf %[[VAL_12]] : f64
// CHECK: memref.store %[[VAL_13]], %[[VAL_7]]{{\[}}%[[VAL_11]]] : memref<32xf64>
// CHECK: }
// CHECK: %[[VAL_14:.*]] = bufferization.to_tensor %[[VAL_7]] : memref<32xf64>
Expand All @@ -56,7 +56,7 @@ func.func @abs(%arga: tensor<32xf64, #SV>,
ins(%arga: tensor<32xf64, #SV>)
outs(%argx: tensor<32xf64>) {
^bb(%a: f64, %x: f64):
%0 = math.abs %a : f64
%0 = math.absf %a : f64
linalg.yield %0 : f64
} -> tensor<32xf64>
return %0 : tensor<32xf64>
Expand Down Expand Up @@ -366,7 +366,7 @@ func.func @divbyc(%arga: tensor<32xf64, #SV>,
// CHECK: %[[VAL_12:.*]] = memref.load %[[VAL_6]]{{\[}}%[[VAL_11]]] : memref<?xindex>
// CHECK: memref.store %[[VAL_12]], %[[VAL_8]]{{\[}}%[[VAL_1]]] : memref<?xindex>
// CHECK: %[[VAL_13:.*]] = memref.load %[[VAL_7]]{{\[}}%[[VAL_11]]] : memref<?xf64>
// CHECK: %[[VAL_14:.*]] = math.abs %[[VAL_13]] : f64
// CHECK: %[[VAL_14:.*]] = math.absf %[[VAL_13]] : f64
// CHECK: %[[VAL_15:.*]] = math.ceil %[[VAL_14]] : f64
// CHECK: %[[VAL_16:.*]] = math.floor %[[VAL_15]] : f64
// CHECK: %[[VAL_17:.*]] = math.sqrt %[[VAL_16]] : f64
Expand All @@ -387,7 +387,7 @@ func.func @zero_preserving_math(%arga: tensor<32xf64, #SV>) -> tensor<32xf64, #S
ins(%arga: tensor<32xf64, #SV>)
outs(%xinp: tensor<32xf64, #SV>) {
^bb(%a: f64, %x: f64):
%0 = math.abs %a : f64
%0 = math.absf %a : f64
%1 = math.ceil %0 : f64
%2 = math.floor %1 : f64
%3 = math.sqrt %2 : f64
Expand Down
16 changes: 8 additions & 8 deletions mlir/test/IR/core-ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ func.func @standard_instrs(tensor<4x4x?xf32>, f32, i32, index, i64, f16) {
// CHECK: arith.constant false
%75 = arith.constant false

// CHECK: %{{.*}} = math.abs %arg1 : f32
%100 = "math.abs"(%f) : (f32) -> f32
// CHECK: %{{.*}} = math.absf %arg1 : f32
%100 = "math.absf"(%f) : (f32) -> f32

// CHECK: %{{.*}} = math.abs %arg1 : f32
%101 = math.abs %f : f32
// CHECK: %{{.*}} = math.absf %arg1 : f32
%101 = math.absf %f : f32

// CHECK: %{{.*}} = math.abs %{{.*}}: vector<4xf32>
%102 = math.abs %vcf32 : vector<4xf32>
// CHECK: %{{.*}} = math.absf %{{.*}}: vector<4xf32>
%102 = math.absf %vcf32 : vector<4xf32>

// CHECK: %{{.*}} = math.abs %arg0 : tensor<4x4x?xf32>
%103 = math.abs %t : tensor<4x4x?xf32>
// CHECK: %{{.*}} = math.absf %arg0 : tensor<4x4x?xf32>
%103 = math.absf %t : tensor<4x4x?xf32>

// CHECK: %{{.*}} = math.ceil %arg1 : f32
%104 = "math.ceil"(%f) : (f32) -> f32
Expand Down
4 changes: 2 additions & 2 deletions mlir/test/Target/Cpp/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func.func @multiple_blocks() {
// -----

func.func @unsupported_std_op(%arg0: f64) -> f64 {
// expected-error@+1 {{'math.abs' op unable to find printer for op}}
%0 = math.abs %arg0 : f64
// expected-error@+1 {{'math.absf' op unable to find printer for op}}
%0 = math.absf %arg0 : f64
return %0 : f64
}

Expand Down
2 changes: 1 addition & 1 deletion mlir/test/python/dialects/linalg/opdsl/emit_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_f32_elemwise_log(input, init_result):

# CHECK-LABEL: @test_f32_elemwise_abs
# CHECK: ^{{.*}}(%[[IN:.+]]: f32, %[[OUT:.+]]: f32)
# CHECK-NEXT: %[[EXP:.+]] = math.abs %[[IN]] : f32
# CHECK-NEXT: %[[EXP:.+]] = math.absf %[[IN]] : f32
# CHECK-NEXT: linalg.yield %[[EXP]] : f32
# CHECK-NEXT: -> tensor<4x16xf32>
@func.FuncOp.from_py_func(
Expand Down