| // RUN: mlir-opt %s -test-math-algebraic-simplification | FileCheck %s --dump-input=always | |
| // CHECK-LABEL: @pow_noop | |
| func.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.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_square_fast | |
| func.func @pow_square_fast(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) { | |
| // CHECK: %[[SCALAR:.*]] = arith.mulf %arg0, %arg0 fastmath<fast> | |
| // CHECK: %[[VECTOR:.*]] = arith.mulf %arg1, %arg1 fastmath<fast> | |
| // CHECK: return %[[SCALAR]], %[[VECTOR]] | |
| %c = arith.constant 2.0 : f32 | |
| %v = arith.constant dense <2.0> : vector<4xf32> | |
| %0 = math.powf %arg0, %c fastmath<fast> : f32 | |
| %1 = math.powf %arg1, %v fastmath<fast> : vector<4xf32> | |
| return %0, %1 : f32, vector<4xf32> | |
| } | |
| // CHECK-LABEL: @pow_cube | |
| func.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_cube_fast | |
| func.func @pow_cube_fast(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) { | |
| // CHECK: %[[TMP_S:.*]] = arith.mulf %arg0, %arg0 fastmath<fast> | |
| // CHECK: %[[SCALAR:.*]] = arith.mulf %arg0, %[[TMP_S]] fastmath<fast> | |
| // CHECK: %[[TMP_V:.*]] = arith.mulf %arg1, %arg1 fastmath<fast> | |
| // CHECK: %[[VECTOR:.*]] = arith.mulf %arg1, %[[TMP_V]] fastmath<fast> | |
| // CHECK: return %[[SCALAR]], %[[VECTOR]] | |
| %c = arith.constant 3.0 : f32 | |
| %v = arith.constant dense <3.0> : vector<4xf32> | |
| %0 = math.powf %arg0, %c fastmath<fast> : f32 | |
| %1 = math.powf %arg1, %v fastmath<fast> : vector<4xf32> | |
| return %0, %1 : f32, vector<4xf32> | |
| } | |
| // CHECK-LABEL: @pow_recip | |
| func.func @pow_recip(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) { | |
| // CHECK-DAG: %[[CST_S:.*]] = arith.constant 1.0{{.*}} : f32 | |
| // CHECK-DAG: %[[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_recip_fast | |
| func.func @pow_recip_fast(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) { | |
| // CHECK-DAG: %[[CST_S:.*]] = arith.constant 1.0{{.*}} : f32 | |
| // CHECK-DAG: %[[CST_V:.*]] = arith.constant dense<1.0{{.*}}> : vector<4xf32> | |
| // CHECK: %[[SCALAR:.*]] = arith.divf %[[CST_S]], %arg0 fastmath<fast> | |
| // CHECK: %[[VECTOR:.*]] = arith.divf %[[CST_V]], %arg1 fastmath<fast> | |
| // CHECK: return %[[SCALAR]], %[[VECTOR]] | |
| %c = arith.constant -1.0 : f32 | |
| %v = arith.constant dense <-1.0> : vector<4xf32> | |
| %0 = math.powf %arg0, %c fastmath<fast> : f32 | |
| %1 = math.powf %arg1, %v fastmath<fast> : vector<4xf32> | |
| return %0, %1 : f32, vector<4xf32> | |
| } | |
| // CHECK-LABEL: @pow_sqrt | |
| func.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_sqrt_fast | |
| func.func @pow_sqrt_fast(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) { | |
| // CHECK: %[[SCALAR:.*]] = math.sqrt %arg0 fastmath<fast> | |
| // CHECK: %[[VECTOR:.*]] = math.sqrt %arg1 fastmath<fast> | |
| // CHECK: return %[[SCALAR]], %[[VECTOR]] | |
| %c = arith.constant 0.5 : f32 | |
| %v = arith.constant dense <0.5> : vector<4xf32> | |
| %0 = math.powf %arg0, %c fastmath<fast> : f32 | |
| %1 = math.powf %arg1, %v fastmath<fast> : vector<4xf32> | |
| return %0, %1 : f32, vector<4xf32> | |
| } | |
| // CHECK-LABEL: @pow_rsqrt | |
| func.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> | |
| } | |
| // CHECK-LABEL: @pow_rsqrt_fast | |
| func.func @pow_rsqrt_fast(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) { | |
| // CHECK: %[[SCALAR:.*]] = math.rsqrt %arg0 fastmath<fast> | |
| // CHECK: %[[VECTOR:.*]] = math.rsqrt %arg1 fastmath<fast> | |
| // CHECK: return %[[SCALAR]], %[[VECTOR]] | |
| %c = arith.constant -0.5 : f32 | |
| %v = arith.constant dense <-0.5> : vector<4xf32> | |
| %0 = math.powf %arg0, %c fastmath<fast> : f32 | |
| %1 = math.powf %arg1, %v fastmath<fast> : vector<4xf32> | |
| return %0, %1 : f32, vector<4xf32> | |
| } | |
| // CHECK-LABEL: @pow_0_75 | |
| func.func @pow_0_75(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) { | |
| // CHECK: %[[SQRT1S:.*]] = math.sqrt %arg0 | |
| // CHECK: %[[SQRT2S:.*]] = math.sqrt %[[SQRT1S]] | |
| // CHECK: %[[SCALAR:.*]] = arith.mulf %[[SQRT1S]], %[[SQRT2S]] | |
| // CHECK: %[[SQRT1V:.*]] = math.sqrt %arg1 | |
| // CHECK: %[[SQRT2V:.*]] = math.sqrt %[[SQRT1V]] | |
| // CHECK: %[[VECTOR:.*]] = arith.mulf %[[SQRT1V]], %[[SQRT2V]] | |
| // CHECK: return %[[SCALAR]], %[[VECTOR]] | |
| %c = arith.constant 0.75 : f32 | |
| %v = arith.constant dense <0.75> : vector<4xf32> | |
| %0 = math.powf %arg0, %c : f32 | |
| %1 = math.powf %arg1, %v : vector<4xf32> | |
| return %0, %1 : f32, vector<4xf32> | |
| } | |
| // CHECK-LABEL: @pow_0_75_fast | |
| func.func @pow_0_75_fast(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) { | |
| // CHECK: %[[SQRT1S:.*]] = math.sqrt %arg0 fastmath<fast> | |
| // CHECK: %[[SQRT2S:.*]] = math.sqrt %[[SQRT1S]] fastmath<fast> | |
| // CHECK: %[[SCALAR:.*]] = arith.mulf %[[SQRT1S]], %[[SQRT2S]] fastmath<fast> | |
| // CHECK: %[[SQRT1V:.*]] = math.sqrt %arg1 fastmath<fast> | |
| // CHECK: %[[SQRT2V:.*]] = math.sqrt %[[SQRT1V]] fastmath<fast> | |
| // CHECK: %[[VECTOR:.*]] = arith.mulf %[[SQRT1V]], %[[SQRT2V]] fastmath<fast> | |
| // CHECK: return %[[SCALAR]], %[[VECTOR]] | |
| %c = arith.constant 0.75 : f32 | |
| %v = arith.constant dense <0.75> : vector<4xf32> | |
| %0 = math.powf %arg0, %c fastmath<fast> : f32 | |
| %1 = math.powf %arg1, %v fastmath<fast> : vector<4xf32> | |
| return %0, %1 : f32, vector<4xf32> | |
| } | |
| // CHECK-LABEL: @ipowi_zero_exp( | |
| // CHECK-SAME: %[[ARG0:.+]]: i32 | |
| // CHECK-SAME: %[[ARG1:.+]]: vector<4xi32> | |
| // CHECK-SAME: -> (i32, vector<4xi32>) { | |
| func.func @ipowi_zero_exp(%arg0: i32, %arg1: vector<4xi32>) -> (i32, vector<4xi32>) { | |
| // CHECK: %[[CST_S:.*]] = arith.constant 1 : i32 | |
| // CHECK: %[[CST_V:.*]] = arith.constant dense<1> : vector<4xi32> | |
| // CHECK: return %[[CST_S]], %[[CST_V]] | |
| %c = arith.constant 0 : i32 | |
| %v = arith.constant dense <0> : vector<4xi32> | |
| %0 = math.ipowi %arg0, %c : i32 | |
| %1 = math.ipowi %arg1, %v : vector<4xi32> | |
| return %0, %1 : i32, vector<4xi32> | |
| } | |
| // CHECK-LABEL: @ipowi_exp_one( | |
| // CHECK-SAME: %[[ARG0:.+]]: i32 | |
| // CHECK-SAME: %[[ARG1:.+]]: vector<4xi32> | |
| // CHECK-SAME: -> (i32, vector<4xi32>, i32, vector<4xi32>) { | |
| func.func @ipowi_exp_one(%arg0: i32, %arg1: vector<4xi32>) -> (i32, vector<4xi32>, i32, vector<4xi32>) { | |
| // CHECK-DAG: %[[CST_S:.*]] = arith.constant 1 : i32 | |
| // CHECK-DAG: %[[CST_V:.*]] = arith.constant dense<1> : vector<4xi32> | |
| // CHECK: %[[SCALAR:.*]] = arith.divsi %[[CST_S]], %[[ARG0]] | |
| // CHECK: %[[VECTOR:.*]] = arith.divsi %[[CST_V]], %[[ARG1]] | |
| // CHECK: return %[[ARG0]], %[[ARG1]], %[[SCALAR]], %[[VECTOR]] | |
| %c1 = arith.constant 1 : i32 | |
| %v1 = arith.constant dense <1> : vector<4xi32> | |
| %0 = math.ipowi %arg0, %c1 : i32 | |
| %1 = math.ipowi %arg1, %v1 : vector<4xi32> | |
| %cm1 = arith.constant -1 : i32 | |
| %vm1 = arith.constant dense <-1> : vector<4xi32> | |
| %2 = math.ipowi %arg0, %cm1 : i32 | |
| %3 = math.ipowi %arg1, %vm1 : vector<4xi32> | |
| return %0, %1, %2, %3 : i32, vector<4xi32>, i32, vector<4xi32> | |
| } | |
| // CHECK-LABEL: @ipowi_exp_two( | |
| // CHECK-SAME: %[[ARG0:.+]]: i32 | |
| // CHECK-SAME: %[[ARG1:.+]]: vector<4xi32> | |
| // CHECK-SAME: -> (i32, vector<4xi32>, i32, vector<4xi32>) { | |
| func.func @ipowi_exp_two(%arg0: i32, %arg1: vector<4xi32>) -> (i32, vector<4xi32>, i32, vector<4xi32>) { | |
| // CHECK-DAG: %[[CST_S:.*]] = arith.constant 1 : i32 | |
| // CHECK-DAG: %[[CST_V:.*]] = arith.constant dense<1> : vector<4xi32> | |
| // CHECK: %[[SCALAR0:.*]] = arith.muli %[[ARG0]], %[[ARG0]] | |
| // CHECK: %[[VECTOR0:.*]] = arith.muli %[[ARG1]], %[[ARG1]] | |
| // CHECK: %[[SMUL:.*]] = arith.muli %[[ARG0]], %[[ARG0]] | |
| // CHECK: %[[SCALAR1:.*]] = arith.divsi %[[CST_S]], %[[SMUL]] | |
| // CHECK: %[[VMUL:.*]] = arith.muli %[[ARG1]], %[[ARG1]] | |
| // CHECK: %[[VECTOR1:.*]] = arith.divsi %[[CST_V]], %[[VMUL]] | |
| // CHECK: return %[[SCALAR0]], %[[VECTOR0]], %[[SCALAR1]], %[[VECTOR1]] | |
| %c1 = arith.constant 2 : i32 | |
| %v1 = arith.constant dense <2> : vector<4xi32> | |
| %0 = math.ipowi %arg0, %c1 : i32 | |
| %1 = math.ipowi %arg1, %v1 : vector<4xi32> | |
| %cm1 = arith.constant -2 : i32 | |
| %vm1 = arith.constant dense <-2> : vector<4xi32> | |
| %2 = math.ipowi %arg0, %cm1 : i32 | |
| %3 = math.ipowi %arg1, %vm1 : vector<4xi32> | |
| return %0, %1, %2, %3 : i32, vector<4xi32>, i32, vector<4xi32> | |
| } | |
| // CHECK-LABEL: @ipowi_exp_three( | |
| // CHECK-SAME: %[[ARG0:.+]]: i32 | |
| // CHECK-SAME: %[[ARG1:.+]]: vector<4xi32> | |
| // CHECK-SAME: -> (i32, vector<4xi32>, i32, vector<4xi32>) { | |
| func.func @ipowi_exp_three(%arg0: i32, %arg1: vector<4xi32>) -> (i32, vector<4xi32>, i32, vector<4xi32>) { | |
| // CHECK-DAG: %[[CST_S:.*]] = arith.constant 1 : i32 | |
| // CHECK-DAG: %[[CST_V:.*]] = arith.constant dense<1> : vector<4xi32> | |
| // CHECK: %[[SMUL0:.*]] = arith.muli %[[ARG0]], %[[ARG0]] | |
| // CHECK: %[[SCALAR0:.*]] = arith.muli %[[SMUL0]], %[[ARG0]] | |
| // CHECK: %[[VMUL0:.*]] = arith.muli %[[ARG1]], %[[ARG1]] | |
| // CHECK: %[[VECTOR0:.*]] = arith.muli %[[VMUL0]], %[[ARG1]] | |
| // CHECK: %[[SMUL1:.*]] = arith.muli %[[ARG0]], %[[ARG0]] | |
| // CHECK: %[[SMUL2:.*]] = arith.muli %[[SMUL1]], %[[ARG0]] | |
| // CHECK: %[[SCALAR1:.*]] = arith.divsi %[[CST_S]], %[[SMUL2]] | |
| // CHECK: %[[VMUL1:.*]] = arith.muli %[[ARG1]], %[[ARG1]] | |
| // CHECK: %[[VMUL2:.*]] = arith.muli %[[VMUL1]], %[[ARG1]] | |
| // CHECK: %[[VECTOR1:.*]] = arith.divsi %[[CST_V]], %[[VMUL2]] | |
| // CHECK: return %[[SCALAR0]], %[[VECTOR0]], %[[SCALAR1]], %[[VECTOR1]] | |
| %c1 = arith.constant 3 : i32 | |
| %v1 = arith.constant dense <3> : vector<4xi32> | |
| %0 = math.ipowi %arg0, %c1 : i32 | |
| %1 = math.ipowi %arg1, %v1 : vector<4xi32> | |
| %cm1 = arith.constant -3 : i32 | |
| %vm1 = arith.constant dense <-3> : vector<4xi32> | |
| %2 = math.ipowi %arg0, %cm1 : i32 | |
| %3 = math.ipowi %arg1, %vm1 : vector<4xi32> | |
| return %0, %1, %2, %3 : i32, vector<4xi32>, i32, vector<4xi32> | |
| } | |
| // CHECK-LABEL: @fpowi_zero_exp( | |
| // CHECK-SAME: %[[ARG0:.+]]: f32 | |
| // CHECK-SAME: %[[ARG1:.+]]: vector<4xf32> | |
| // CHECK-SAME: -> (f32, vector<4xf32>) { | |
| func.func @fpowi_zero_exp(%arg0: f32, %arg1: vector<4xf32>) -> (f32, vector<4xf32>) { | |
| // CHECK: %[[CST_S:.*]] = arith.constant 1.000000e+00 : f32 | |
| // CHECK: %[[CST_V:.*]] = arith.constant dense<1.000000e+00> : vector<4xf32> | |
| // CHECK: return %[[CST_S]], %[[CST_V]] | |
| %c = arith.constant 0 : i32 | |
| %v = arith.constant dense <0> : vector<4xi32> | |
| %0 = math.fpowi %arg0, %c : f32, i32 | |
| %1 = math.fpowi %arg1, %v : vector<4xf32>, vector<4xi32> | |
| return %0, %1 : f32, vector<4xf32> | |
| } | |
| // CHECK-LABEL: @fpowi_exp_one( | |
| // CHECK-SAME: %[[ARG0:.+]]: f32 | |
| // CHECK-SAME: %[[ARG1:.+]]: vector<4xf32> | |
| // CHECK-SAME: -> (f32, vector<4xf32>, f32, vector<4xf32>) { | |
| func.func @fpowi_exp_one(%arg0: f32, %arg1: vector<4xf32>) -> (f32, vector<4xf32>, f32, vector<4xf32>) { | |
| // CHECK-DAG: %[[CST_S:.*]] = arith.constant 1.000000e+00 : f32 | |
| // CHECK-DAG: %[[CST_V:.*]] = arith.constant dense<1.000000e+00> : vector<4xf32> | |
| // CHECK: %[[SCALAR:.*]] = arith.divf %[[CST_S]], %[[ARG0]] | |
| // CHECK: %[[VECTOR:.*]] = arith.divf %[[CST_V]], %[[ARG1]] | |
| // CHECK: return %[[ARG0]], %[[ARG1]], %[[SCALAR]], %[[VECTOR]] | |
| %c1 = arith.constant 1 : i32 | |
| %v1 = arith.constant dense <1> : vector<4xi32> | |
| %0 = math.fpowi %arg0, %c1 : f32, i32 | |
| %1 = math.fpowi %arg1, %v1 : vector<4xf32>, vector<4xi32> | |
| %cm1 = arith.constant -1 : i32 | |
| %vm1 = arith.constant dense <-1> : vector<4xi32> | |
| %2 = math.fpowi %arg0, %cm1 : f32, i32 | |
| %3 = math.fpowi %arg1, %vm1 : vector<4xf32>, vector<4xi32> | |
| return %0, %1, %2, %3 : f32, vector<4xf32>, f32, vector<4xf32> | |
| } | |
| // CHECK-LABEL: @fpowi_exp_two( | |
| // CHECK-SAME: %[[ARG0:.+]]: f32 | |
| // CHECK-SAME: %[[ARG1:.+]]: vector<4xf32> | |
| // CHECK-SAME: -> (f32, vector<4xf32>, f32, vector<4xf32>) { | |
| func.func @fpowi_exp_two(%arg0: f32, %arg1: vector<4xf32>) -> (f32, vector<4xf32>, f32, vector<4xf32>) { | |
| // CHECK-DAG: %[[CST_S:.*]] = arith.constant 1.000000e+00 : f32 | |
| // CHECK-DAG: %[[CST_V:.*]] = arith.constant dense<1.000000e+00> : vector<4xf32> | |
| // CHECK: %[[SCALAR0:.*]] = arith.mulf %[[ARG0]], %[[ARG0]] | |
| // CHECK: %[[VECTOR0:.*]] = arith.mulf %[[ARG1]], %[[ARG1]] | |
| // CHECK: %[[SMUL:.*]] = arith.mulf %[[ARG0]], %[[ARG0]] | |
| // CHECK: %[[SCALAR1:.*]] = arith.divf %[[CST_S]], %[[SMUL]] | |
| // CHECK: %[[VMUL:.*]] = arith.mulf %[[ARG1]], %[[ARG1]] | |
| // CHECK: %[[VECTOR1:.*]] = arith.divf %[[CST_V]], %[[VMUL]] | |
| // CHECK: return %[[SCALAR0]], %[[VECTOR0]], %[[SCALAR1]], %[[VECTOR1]] | |
| %c1 = arith.constant 2 : i32 | |
| %v1 = arith.constant dense <2> : vector<4xi32> | |
| %0 = math.fpowi %arg0, %c1 : f32, i32 | |
| %1 = math.fpowi %arg1, %v1 : vector<4xf32>, vector<4xi32> | |
| %cm1 = arith.constant -2 : i32 | |
| %vm1 = arith.constant dense <-2> : vector<4xi32> | |
| %2 = math.fpowi %arg0, %cm1 : f32, i32 | |
| %3 = math.fpowi %arg1, %vm1 : vector<4xf32>, vector<4xi32> | |
| return %0, %1, %2, %3 : f32, vector<4xf32>, f32, vector<4xf32> | |
| } | |
| // CHECK-LABEL: @fpowi_exp_three( | |
| // CHECK-SAME: %[[ARG0:.+]]: f32 | |
| // CHECK-SAME: %[[ARG1:.+]]: vector<4xf32> | |
| // CHECK-SAME: -> (f32, vector<4xf32>, f32, vector<4xf32>) { | |
| func.func @fpowi_exp_three(%arg0: f32, %arg1: vector<4xf32>) -> (f32, vector<4xf32>, f32, vector<4xf32>) { | |
| // CHECK-DAG: %[[CST_S:.*]] = arith.constant 1.000000e+00 : f32 | |
| // CHECK-DAG: %[[CST_V:.*]] = arith.constant dense<1.000000e+00> : vector<4xf32> | |
| // CHECK: %[[SMUL0:.*]] = arith.mulf %[[ARG0]], %[[ARG0]] | |
| // CHECK: %[[SCALAR0:.*]] = arith.mulf %[[SMUL0]], %[[ARG0]] | |
| // CHECK: %[[VMUL0:.*]] = arith.mulf %[[ARG1]], %[[ARG1]] | |
| // CHECK: %[[VECTOR0:.*]] = arith.mulf %[[VMUL0]], %[[ARG1]] | |
| // CHECK: %[[SMUL1:.*]] = arith.mulf %[[ARG0]], %[[ARG0]] | |
| // CHECK: %[[SMUL2:.*]] = arith.mulf %[[SMUL1]], %[[ARG0]] | |
| // CHECK: %[[SCALAR1:.*]] = arith.divf %[[CST_S]], %[[SMUL2]] | |
| // CHECK: %[[VMUL1:.*]] = arith.mulf %[[ARG1]], %[[ARG1]] | |
| // CHECK: %[[VMUL2:.*]] = arith.mulf %[[VMUL1]], %[[ARG1]] | |
| // CHECK: %[[VECTOR1:.*]] = arith.divf %[[CST_V]], %[[VMUL2]] | |
| // CHECK: return %[[SCALAR0]], %[[VECTOR0]], %[[SCALAR1]], %[[VECTOR1]] | |
| %c1 = arith.constant 3 : i32 | |
| %v1 = arith.constant dense <3> : vector<4xi32> | |
| %0 = math.fpowi %arg0, %c1 : f32, i32 | |
| %1 = math.fpowi %arg1, %v1 : vector<4xf32>, vector<4xi32> | |
| %cm1 = arith.constant -3 : i32 | |
| %vm1 = arith.constant dense <-3> : vector<4xi32> | |
| %2 = math.fpowi %arg0, %cm1 : f32, i32 | |
| %3 = math.fpowi %arg1, %vm1 : vector<4xf32>, vector<4xi32> | |
| return %0, %1, %2, %3 : f32, vector<4xf32>, f32, vector<4xf32> | |
| } | |
| // CHECK-LABEL: @exp_quotient( | |
| // CHECK-SAME: %[[ARG0:.+]]: f32, %[[ARG1:.+]]: f32, | |
| // CHECK-SAME: %[[ARG2:.+]]: vector<4xf32>, %[[ARG3:.+]]: vector<4xf32> | |
| func.func @exp_quotient(%arg0: f32, %arg1: f32, %arg2: vector<4xf32>, | |
| %arg3: vector<4xf32>) -> (f32, vector<4xf32>) { | |
| // CHECK: %[[SSUB:.*]] = arith.subf %[[ARG0]], %[[ARG1]] fastmath<reassoc,nsz,arcp,contract,afn> : f32 | |
| // CHECK: %[[SCALAR:.*]] = math.exp %[[SSUB]] fastmath<reassoc,nsz,arcp,contract,afn> : f32 | |
| // CHECK: %[[VSUB:.*]] = arith.subf %[[ARG2]], %[[ARG3]] fastmath<reassoc,nsz,arcp,contract,afn> : vector<4xf32> | |
| // CHECK: %[[VECTOR:.*]] = math.exp2 %[[VSUB]] fastmath<reassoc,nsz,arcp,contract,afn> : vector<4xf32> | |
| // CHECK: return %[[SCALAR]], %[[VECTOR]] | |
| %0 = math.exp %arg0 fastmath<fast> : f32 | |
| %1 = math.exp %arg1 fastmath<fast> : f32 | |
| %2 = arith.divf %0, %1 fastmath<fast> : f32 | |
| %3 = math.exp2 %arg2 fastmath<fast> : vector<4xf32> | |
| %4 = math.exp2 %arg3 fastmath<fast> : vector<4xf32> | |
| %5 = arith.divf %3, %4 fastmath<fast> : vector<4xf32> | |
| return %2, %5 : f32, vector<4xf32> | |
| } | |
| // The rewrite only needs `arcp` and `reassoc` on the division. The subtraction | |
| // takes the division's flags, the new `exp` the ones shared by both | |
| // exponentials it replaces. | |
| // CHECK-LABEL: @exp_quotient_minimal_fastmath( | |
| // CHECK-SAME: %[[ARG0:.+]]: f32, %[[ARG1:.+]]: f32 | |
| func.func @exp_quotient_minimal_fastmath(%arg0: f32, %arg1: f32) -> f32 { | |
| // CHECK: %[[SUB:.*]] = arith.subf %[[ARG0]], %[[ARG1]] fastmath<reassoc,arcp> : f32 | |
| // CHECK: %[[EXP:.*]] = math.exp %[[SUB]] fastmath<afn> : f32 | |
| // CHECK: return %[[EXP]] | |
| %0 = math.exp %arg0 fastmath<afn,ninf> : f32 | |
| %1 = math.exp %arg1 fastmath<afn> : f32 | |
| %2 = arith.divf %0, %1 fastmath<reassoc,arcp> : f32 | |
| return %2 : f32 | |
| } | |
| // `nnan` and `ninf` are assumptions about the values an operation sees, and | |
| // neither new operation sees the values of the ones it replaces, so they are | |
| // dropped rather than propagated: here `ninf` holds for the division for | |
| // `%arg0 = -inf`, `%arg1 = 0.0`, but not for the subtraction. | |
| // CHECK-LABEL: @exp_quotient_drops_value_assumptions( | |
| // CHECK-SAME: %[[ARG0:.+]]: f32, %[[ARG1:.+]]: f32 | |
| func.func @exp_quotient_drops_value_assumptions(%arg0: f32, %arg1: f32) -> f32 { | |
| // CHECK: %[[SUB:.*]] = arith.subf %[[ARG0]], %[[ARG1]] fastmath<reassoc,arcp> : f32 | |
| // CHECK: %[[EXP:.*]] = math.exp %[[SUB]] fastmath<afn> : f32 | |
| // CHECK: return %[[EXP]] | |
| %0 = math.exp %arg0 fastmath<nnan,ninf,afn> : f32 | |
| %1 = math.exp %arg1 fastmath<nnan,ninf,afn> : f32 | |
| %2 = arith.divf %0, %1 fastmath<nnan,ninf,reassoc,arcp> : f32 | |
| return %2 : f32 | |
| } | |
| // The two new operations derive their flags independently: the subtraction from | |
| // the division, the exponential from the two exponentials, and neither inherits | |
| // flags that only the other side carries. | |
| // CHECK-LABEL: @exp_quotient_mixed_fastmath( | |
| // CHECK-SAME: %[[ARG0:.+]]: f32, %[[ARG1:.+]]: f32 | |
| func.func @exp_quotient_mixed_fastmath(%arg0: f32, %arg1: f32) -> f32 { | |
| // CHECK: %[[SUB:.*]] = arith.subf %[[ARG0]], %[[ARG1]] fastmath<reassoc,arcp,contract> : f32 | |
| // CHECK: %[[EXP:.*]] = math.exp %[[SUB]] fastmath<nsz,contract> : f32 | |
| // CHECK: return %[[EXP]] | |
| %0 = math.exp %arg0 fastmath<nsz,contract,afn> : f32 | |
| %1 = math.exp %arg1 fastmath<nsz,contract,ninf> : f32 | |
| %2 = arith.divf %0, %1 fastmath<reassoc,arcp,contract,nnan> : f32 | |
| return %2 : f32 | |
| } | |
| // The numerator is still needed, but folding remains profitable because the | |
| // division becomes a subtraction. | |
| // CHECK-LABEL: @exp_quotient_numerator_multiple_uses( | |
| // CHECK-SAME: %[[ARG0:.+]]: f32, %[[ARG1:.+]]: f32 | |
| func.func @exp_quotient_numerator_multiple_uses(%arg0: f32, %arg1: f32) -> (f32, f32) { | |
| // CHECK: %[[NUM:.*]] = math.exp %[[ARG0]] fastmath<fast> : f32 | |
| // CHECK: %[[SUB:.*]] = arith.subf %[[ARG0]], %[[ARG1]] fastmath<reassoc,nsz,arcp,contract,afn> : f32 | |
| // CHECK: %[[EXP:.*]] = math.exp %[[SUB]] fastmath<reassoc,nsz,arcp,contract,afn> : f32 | |
| // CHECK: return %[[EXP]], %[[NUM]] | |
| %0 = math.exp %arg0 fastmath<fast> : f32 | |
| %1 = math.exp %arg1 fastmath<fast> : f32 | |
| %2 = arith.divf %0, %1 fastmath<fast> : f32 | |
| return %2, %0 : f32, f32 | |
| } | |
| // The divisor is still needed, but folding remains profitable because the | |
| // numerator dies and the division becomes a subtraction. | |
| // CHECK-LABEL: @exp_quotient_denominator_multiple_uses( | |
| // CHECK-SAME: %[[ARG0:.+]]: f32, %[[ARG1:.+]]: f32 | |
| func.func @exp_quotient_denominator_multiple_uses(%arg0: f32, %arg1: f32) -> (f32, f32) { | |
| // CHECK: %[[DEN:.*]] = math.exp %[[ARG1]] fastmath<fast> : f32 | |
| // CHECK: %[[SUB:.*]] = arith.subf %[[ARG0]], %[[ARG1]] fastmath<reassoc,nsz,arcp,contract,afn> : f32 | |
| // CHECK: %[[EXP:.*]] = math.exp %[[SUB]] fastmath<reassoc,nsz,arcp,contract,afn> : f32 | |
| // CHECK: return %[[EXP]], %[[DEN]] | |
| %0 = math.exp %arg0 fastmath<fast> : f32 | |
| %1 = math.exp %arg1 fastmath<fast> : f32 | |
| %2 = arith.divf %0, %1 fastmath<fast> : f32 | |
| return %2, %1 : f32, f32 | |
| } | |
| // Negative test - neither exponential dies, so the fold would add a third one. | |
| // CHECK-LABEL: @exp_quotient_both_multiple_uses( | |
| func.func @exp_quotient_both_multiple_uses(%arg0: f32, %arg1: f32) -> (f32, f32, f32) { | |
| // CHECK-COUNT-2: math.exp | |
| // CHECK-NOT: math.exp | |
| // CHECK: arith.divf | |
| %0 = math.exp %arg0 fastmath<fast> : f32 | |
| %1 = math.exp %arg1 fastmath<fast> : f32 | |
| %2 = arith.divf %0, %1 fastmath<fast> : f32 | |
| return %2, %0, %1 : f32, f32, f32 | |
| } | |
| // Both operands come from the same exponential, which therefore dies. | |
| // CHECK-LABEL: @exp_quotient_same_exponential( | |
| // CHECK-SAME: %[[ARG0:.+]]: f32 | |
| func.func @exp_quotient_same_exponential(%arg0: f32) -> f32 { | |
| // CHECK: %[[SUB:.*]] = arith.subf %[[ARG0]], %[[ARG0]] fastmath<reassoc,nsz,arcp,contract,afn> : f32 | |
| // CHECK: %[[EXP:.*]] = math.exp %[[SUB]] fastmath<reassoc,nsz,arcp,contract,afn> : f32 | |
| // CHECK: return %[[EXP]] | |
| %0 = math.exp %arg0 fastmath<fast> : f32 | |
| %1 = arith.divf %0, %0 fastmath<fast> : f32 | |
| return %1 : f32 | |
| } | |
| // Negative test - not enough fastmath flags on the division. | |
| // CHECK-LABEL: @exp_quotient_not_enough_fastmath( | |
| func.func @exp_quotient_not_enough_fastmath(%arg0: f32, %arg1: f32, %arg2: f32, | |
| %arg3: f32) -> (f32, f32) { | |
| // CHECK-COUNT-2: arith.divf | |
| %0 = math.exp %arg0 fastmath<fast> : f32 | |
| %1 = math.exp %arg1 fastmath<fast> : f32 | |
| %2 = arith.divf %0, %1 fastmath<reassoc> : f32 | |
| %3 = math.exp %arg2 fastmath<fast> : f32 | |
| %4 = math.exp %arg3 fastmath<fast> : f32 | |
| %5 = arith.divf %3, %4 fastmath<arcp> : f32 | |
| return %2, %5 : f32, f32 | |
| } | |
| // Negative test - mismatched exponential bases. | |
| // CHECK-LABEL: @exp_quotient_mixed_bases( | |
| func.func @exp_quotient_mixed_bases(%arg0: f32, %arg1: f32) -> f32 { | |
| // CHECK: arith.divf | |
| %0 = math.exp %arg0 fastmath<fast> : f32 | |
| %1 = math.exp2 %arg1 fastmath<fast> : f32 | |
| %2 = arith.divf %0, %1 fastmath<fast> : f32 | |
| return %2 : f32 | |
| } |