Files
clang-p2996/mlir/test/Dialect/Math/algebraic-simplification.mlir
Mogball a54f4eae0e [MLIR] Replace std ops with arith dialect ops
Precursor: https://reviews.llvm.org/D110200

Removed redundant ops from the standard dialect that were moved to the
`arith` or `math` dialects.

Renamed all instances of operations in the codebase and in tests.

Reviewed By: rriddle, jpienaar

Differential Revision: https://reviews.llvm.org/D110797
2021-10-13 03:07:03 +00:00

76 lines
2.8 KiB
MLIR

// RUN: mlir-opt %s -test-math-algebraic-simplification | FileCheck %s --dump-input=always
// CHECK-LABEL: @pow_noop
func @pow_noop(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) {
// CHECK: return %arg0, %arg1
%c = arith.constant 1.0 : f32
%v = arith.constant dense <1.0> : vector<4xf32>
%0 = math.powf %arg0, %c : f32
%1 = math.powf %arg1, %v : vector<4xf32>
return %0, %1 : f32, vector<4xf32>
}
// CHECK-LABEL: @pow_square
func @pow_square(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) {
// CHECK: %[[SCALAR:.*]] = arith.mulf %arg0, %arg0
// CHECK: %[[VECTOR:.*]] = arith.mulf %arg1, %arg1
// CHECK: return %[[SCALAR]], %[[VECTOR]]
%c = arith.constant 2.0 : f32
%v = arith.constant dense <2.0> : vector<4xf32>
%0 = math.powf %arg0, %c : f32
%1 = math.powf %arg1, %v : vector<4xf32>
return %0, %1 : f32, vector<4xf32>
}
// CHECK-LABEL: @pow_cube
func @pow_cube(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) {
// CHECK: %[[TMP_S:.*]] = arith.mulf %arg0, %arg0
// CHECK: %[[SCALAR:.*]] = arith.mulf %arg0, %[[TMP_S]]
// CHECK: %[[TMP_V:.*]] = arith.mulf %arg1, %arg1
// CHECK: %[[VECTOR:.*]] = arith.mulf %arg1, %[[TMP_V]]
// CHECK: return %[[SCALAR]], %[[VECTOR]]
%c = arith.constant 3.0 : f32
%v = arith.constant dense <3.0> : vector<4xf32>
%0 = math.powf %arg0, %c : f32
%1 = math.powf %arg1, %v : vector<4xf32>
return %0, %1 : f32, vector<4xf32>
}
// CHECK-LABEL: @pow_recip
func @pow_recip(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) {
// CHECK: %[[CST_S:.*]] = arith.constant 1.0{{.*}} : f32
// CHECK: %[[CST_V:.*]] = arith.constant dense<1.0{{.*}}> : vector<4xf32>
// CHECK: %[[SCALAR:.*]] = arith.divf %[[CST_S]], %arg0
// CHECK: %[[VECTOR:.*]] = arith.divf %[[CST_V]], %arg1
// CHECK: return %[[SCALAR]], %[[VECTOR]]
%c = arith.constant -1.0 : f32
%v = arith.constant dense <-1.0> : vector<4xf32>
%0 = math.powf %arg0, %c : f32
%1 = math.powf %arg1, %v : vector<4xf32>
return %0, %1 : f32, vector<4xf32>
}
// CHECK-LABEL: @pow_sqrt
func @pow_sqrt(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) {
// CHECK: %[[SCALAR:.*]] = math.sqrt %arg0
// CHECK: %[[VECTOR:.*]] = math.sqrt %arg1
// CHECK: return %[[SCALAR]], %[[VECTOR]]
%c = arith.constant 0.5 : f32
%v = arith.constant dense <0.5> : vector<4xf32>
%0 = math.powf %arg0, %c : f32
%1 = math.powf %arg1, %v : vector<4xf32>
return %0, %1 : f32, vector<4xf32>
}
// CHECK-LABEL: @pow_rsqrt
func @pow_rsqrt(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) {
// CHECK: %[[SCALAR:.*]] = math.rsqrt %arg0
// CHECK: %[[VECTOR:.*]] = math.rsqrt %arg1
// CHECK: return %[[SCALAR]], %[[VECTOR]]
%c = arith.constant -0.5 : f32
%v = arith.constant dense <-0.5> : vector<4xf32>
%0 = math.powf %arg0, %c : f32
%1 = math.powf %arg1, %v : vector<4xf32>
return %0, %1 : f32, vector<4xf32>
}