@@ -202,15 +202,25 @@ func.func @roundf_func(%a: f32) -> f32 {
202
202
203
203
// CHECK-LABEL: func @powf_func
204
204
// CHECK-SAME: ([[ARG0:%.+]]: f64, [[ARG1:%.+]]: f64)
205
- func.func @powf_func (%a: f64 , %b: f64 ) -> f64 {
205
+ func.func @powf_func (%a: f64 , %b: f64 ) ->f64 {
206
206
// CHECK-DAG: [[CST0:%.+]] = arith.constant 0.000000e+00
207
207
// CHECK-DAG: [[CST1:%.+]] = arith.constant 1.0
208
- // CHECK: [[LOGA:%.+]] = math.log [[ARG0]]
209
- // CHECK: [[MULB:%.+]] = arith.mulf [[ARG1]], [[LOGA]]
210
- // CHECK: [[EXP:%.+]] = math.exp [[MULB]]
211
- // CHECK: [[CMPF:%.+]] = arith.cmpf oeq, [[ARG1]], [[CST0]]
212
- // CHECK: [[SEL:%.+]] = arith.select [[CMPF]], [[CST1]], [[EXP]]
213
- // CHECK: return [[SEL]]
208
+ // CHECK-DAG: [[TWO:%.+]] = arith.constant 2.000000e+00
209
+ // CHECK-DAG: [[NEGONE:%.+]] = arith.constant -1.000000e+00
210
+ // CHECK-DAG: [[SQR:%.+]] = arith.mulf [[ARG0]], [[ARG0]]
211
+ // CHECK-DAG: [[HALF:%.+]] = arith.divf [[ARG1]], [[TWO]]
212
+ // CHECK-DAG: [[LOG:%.+]] = math.log [[SQR]]
213
+ // CHECK-DAG: [[MULT:%.+]] = arith.mulf [[HALF]], [[LOG]]
214
+ // CHECK-DAG: [[EXPR:%.+]] = math.exp [[MULT]]
215
+ // CHECK-DAG: [[NEGEXPR:%.+]] = arith.mulf [[EXPR]], [[NEGONE]]
216
+ // CHECK-DAG: [[REMF:%.+]] = arith.remf [[ARG1]], [[TWO]]
217
+ // CHECK-DAG: [[CMPNEG:%.+]] = arith.cmpf olt, [[ARG0]]
218
+ // CHECK-DAG: [[CMPZERO:%.+]] = arith.cmpf one, [[REMF]]
219
+ // CHECK-DAG: [[AND:%.+]] = arith.andi [[CMPZERO]], [[CMPNEG]]
220
+ // CHECK-DAG: [[CMPZERO:%.+]] = arith.cmpf oeq, [[ARG1]], [[CST0]]
221
+ // CHECK-DAG: [[SEL:%.+]] = arith.select [[AND]], [[NEGEXPR]], [[EXPR]]
222
+ // CHECK-DAG: [[SEL1:%.+]] = arith.select [[CMPZERO]], [[CST1]], [[SEL]]
223
+ // CHECK: return [[SEL1]]
214
224
%ret = math.powf %a , %b : f64
215
225
return %ret : f64
216
226
}
@@ -592,15 +602,26 @@ func.func @math_fpowi_to_powf_tensor(%0 : tensor<8xf32>, %1: tensor<8xi32>) -> t
592
602
return %2 : tensor <8 xf32 >
593
603
}
594
604
// CHECK-SAME: (%[[ARG0:.*]]: tensor<8xf32>, %[[ARG1:.*]]: tensor<8xi32>) -> tensor<8xf32> {
595
- // CHECK-DAG: %[[CST1:.+]] = arith.constant dense<1.000000e+00> : tensor<8xf32>
605
+ // CHECK-DAG: %[[CSTNEG1:.*]] = arith.constant dense<-1.000000e+00> : tensor<8xf32>
606
+ // CHECK-DAG: %[[CST2:.*]] = arith.constant dense<2.000000e+00> : tensor<8xf32>
596
607
// CHECK-DAG: %[[CST0:.*]] = arith.constant dense<0.000000e+00> : tensor<8xf32>
597
- // CHECK: %[[TOFP:.*]] = arith.sitofp %[[ARG1]] : tensor<8xi32> to tensor<8xf32>
598
- // CHECK: %[[LOGA:.*]] = math.log %[[ARG0]] : tensor<8xf32>
599
- // CHECK: %[[MUL:.*]] = arith.mulf %[[TOFP]], %[[LOGA]] : tensor<8xf32>
600
- // CHECK: %[[EXP:.*]] = math.exp %[[MUL]] : tensor<8xf32>
601
- // CHECK: %[[CMP:.*]] = arith.cmpf oeq, %[[TOFP]], %[[CST0]] : tensor<8xf32>
602
- // CHECK: %[[SEL:.*]] = arith.select %[[CMP]], %[[CST1]], %[[EXP]] : tensor<8xi1>, tensor<8xf32>
603
- // CHECK: return %[[SEL]]
608
+ // CHECK-DAG: %[[CST1:.+]] = arith.constant dense<1.000000e+00> : tensor<8xf32>
609
+ // CHECK: %[[TOFP:.*]] = arith.sitofp %[[ARG1]] : tensor<8xi32> to tensor<8xf32>
610
+ // CHECK: %[[SQ:.*]] = arith.mulf %[[ARG0]], %[[ARG0]] : tensor<8xf32>
611
+ // CHECK: %[[DIV:.*]] = arith.divf %[[TOFP]], %[[CST2]] : tensor<8xf32>
612
+ // CHECK: %[[LG:.*]] = math.log %[[SQ]] : tensor<8xf32>
613
+ // CHECK: %[[MUL:.*]] = arith.mulf %[[DIV]], %[[LG]] : tensor<8xf32>
614
+ // CHECK: %[[EXP:.*]] = math.exp %[[MUL]] : tensor<8xf32>
615
+ // CHECK: %[[MUL1:.*]] = arith.mulf %[[EXP]], %[[CSTNEG1]] : tensor<8xf32>
616
+ // CHECK: %[[REM:.*]] = arith.remf %[[TOFP]], %[[CST2]] : tensor<8xf32>
617
+ // CHECK: %[[CMPF:.*]] = arith.cmpf olt, %[[ARG0]], %[[CST0]] : tensor<8xf32>
618
+ // CHECK: %[[CMPF1:.*]] = arith.cmpf one, %[[REM]], %[[CST0]] : tensor<8xf32>
619
+ // CHECK: %[[AND:.*]] = arith.andi %[[CMPF1]], %[[CMPF]] : tensor<8xi1>
620
+ // CHECK: %[[CMPZERO:.*]] = arith.cmpf oeq, %[[TOFP]], %[[CST0]]
621
+ // CHECK: %[[SEL:.*]] = arith.select %[[AND]], %[[MUL1]], %[[EXP]] : tensor<8xi1>, tensor<8xf32>
622
+ // CHECK: %[[SEL1:.+]] = arith.select %[[CMPZERO]], %[[CST1]], %[[SEL]]
623
+ // CHECK: return %[[SEL1]] : tensor<8xf32>
624
+
604
625
// -----
605
626
606
627
// CHECK-LABEL: func.func @math_fpowi_to_powf_scalar
@@ -609,15 +630,25 @@ func.func @math_fpowi_to_powf_scalar(%0 : f32, %1: i64) -> f32 {
609
630
return %2 : f32
610
631
}
611
632
// CHECK-SAME: (%[[ARG0:.*]]: f32, %[[ARG1:.*]]: i64) -> f32 {
633
+ // CHECK-DAG: %[[CSTNEG1:.*]] = arith.constant -1.000000e+00 : f32
634
+ // CHECK-DAG: %[[CST2:.*]] = arith.constant 2.000000e+00 : f32
612
635
// CHECK-DAG: %[[CST0:.*]] = arith.constant 0.000000e+00 : f32
613
636
// CHECK-DAG: %[[CST1:.+]] = arith.constant 1.000000e+00 : f32
614
637
// CHECK: %[[TOFP:.*]] = arith.sitofp %[[ARG1]] : i64 to f32
615
- // CHECK: %[[LOGA:.*]] = math.log %[[ARG0]] : f32
616
- // CHECK: %[[MUL:.*]] = arith.mulf %[[TOFP]], %[[LOGA]] : f32
638
+ // CHECK: %[[SQ:.*]] = arith.mulf %[[ARG0]], %[[ARG0]] : f32
639
+ // CHECK: %[[DIV:.*]] = arith.divf %[[TOFP]], %[[CST2]] : f32
640
+ // CHECK: %[[LG:.*]] = math.log %[[SQ]] : f32
641
+ // CHECK: %[[MUL:.*]] = arith.mulf %[[DIV]], %[[LG]] : f32
617
642
// CHECK: %[[EXP:.*]] = math.exp %[[MUL]] : f32
618
- // CHECK: %[[CMP:.*]] = arith.cmpf oeq, %[[TOFP]], %[[CST0]] : f32
619
- // CHECK: %[[SEL:.*]] = arith.select %[[CMP]], %[[CST1]], %[[EXP]] : f32
620
- // CHECK: return %[[SEL]] : f32
643
+ // CHECK: %[[MUL1:.*]] = arith.mulf %[[EXP]], %[[CSTNEG1]] : f32
644
+ // CHECK: %[[REM:.*]] = arith.remf %[[TOFP]], %[[CST2]] : f32
645
+ // CHECK: %[[CMPF:.*]] = arith.cmpf olt, %[[ARG0]], %[[CST0]] : f32
646
+ // CHECK: %[[CMPF1:.*]] = arith.cmpf one, %[[REM]], %[[CST0]] : f32
647
+ // CHECK: %[[AND:.*]] = arith.andi %[[CMPF1]], %[[CMPF]] : i1
648
+ // CHECK: %[[CMPZERO:.*]] = arith.cmpf oeq, %[[TOFP]], %[[CST0]]
649
+ // CHECK: %[[SEL:.*]] = arith.select %[[AND]], %[[MUL1]], %[[EXP]] : f32
650
+ // CHECK: %[[SEL1:.+]] = arith.select %[[CMPZERO]], %[[CST1]], %[[SEL]]
651
+ // CHECK: return %[[SEL1]] : f32
621
652
622
653
// -----
623
654
0 commit comments