1// RUN: mlir-opt %s -test-math-polynomial-approximation | FileCheck %s 2// RUN: mlir-opt %s -test-math-polynomial-approximation=enable-avx2 \ 3// RUN: | FileCheck --check-prefix=AVX2 %s 4 5// Check that all math functions lowered to approximations built from 6// standard operations (add, mul, fma, shift, etc...). 7 8// CHECK-LABEL: func @exp_scalar( 9// CHECK-SAME: %[[VAL_0:.*]]: f32) -> f32 { 10// CHECK-DAG: %[[VAL_1:.*]] = arith.constant 0.693147182 : f32 11// CHECK-DAG: %[[VAL_2:.*]] = arith.constant 1.44269502 : f32 12// CHECK-DAG: %[[VAL_3:.*]] = arith.constant 1.000000e+00 : f32 13// CHECK-DAG: %[[VAL_4:.*]] = arith.constant 0.499705136 : f32 14// CHECK-DAG: %[[VAL_5:.*]] = arith.constant 0.168738902 : f32 15// CHECK-DAG: %[[VAL_6:.*]] = arith.constant 0.0366896503 : f32 16// CHECK-DAG: %[[VAL_7:.*]] = arith.constant 1.314350e-02 : f32 17// CHECK-DAG: %[[VAL_8:.*]] = arith.constant 23 : i32 18// CHECK-DAG: %[[VAL_9:.*]] = arith.constant 0.000000e+00 : f32 19// CHECK-DAG: %[[VAL_10:.*]] = arith.constant 0x7F800000 : f32 20// CHECK-DAG: %[[VAL_11:.*]] = arith.constant 0xFF800000 : f32 21// CHECK-DAG: %[[VAL_12:.*]] = arith.constant 1.17549435E-38 : f32 22// CHECK-DAG: %[[VAL_13:.*]] = arith.constant 127 : i32 23// CHECK-DAG: %[[VAL_14:.*]] = arith.constant -127 : i32 24// CHECK: %[[VAL_15:.*]] = arith.mulf %[[VAL_0]], %[[VAL_2]] : f32 25// CHECK: %[[VAL_16:.*]] = math.floor %[[VAL_15]] : f32 26// CHECK: %[[VAL_17:.*]] = arith.mulf %[[VAL_16]], %[[VAL_1]] : f32 27// CHECK: %[[VAL_18:.*]] = arith.subf %[[VAL_0]], %[[VAL_17]] : f32 28// CHECK: %[[VAL_19:.*]] = arith.mulf %[[VAL_18]], %[[VAL_18]] : f32 29// CHECK: %[[VAL_20:.*]] = arith.mulf %[[VAL_19]], %[[VAL_19]] : f32 30// CHECK: %[[VAL_21:.*]] = math.fma %[[VAL_3]], %[[VAL_18]], %[[VAL_3]] : f32 31// CHECK: %[[VAL_22:.*]] = math.fma %[[VAL_5]], %[[VAL_18]], %[[VAL_4]] : f32 32// CHECK: %[[VAL_23:.*]] = math.fma %[[VAL_7]], %[[VAL_18]], %[[VAL_6]] : f32 33// CHECK: %[[VAL_24:.*]] = math.fma %[[VAL_22]], %[[VAL_19]], %[[VAL_21]] : f32 34// CHECK: %[[VAL_25:.*]] = math.fma %[[VAL_23]], %[[VAL_20]], %[[VAL_24]] : f32 35// CHECK: %[[VAL_26:.*]] = arith.fptosi %[[VAL_16]] : f32 to i32 36// CHECK: %[[VAL_27:.*]] = arith.addi %[[VAL_26]], %[[VAL_13]] : i32 37// CHECK: %[[VAL_28:.*]] = arith.shli %[[VAL_27]], %[[VAL_8]] : i32 38// CHECK: %[[VAL_29:.*]] = arith.bitcast %[[VAL_28]] : i32 to f32 39// CHECK: %[[VAL_30:.*]] = arith.mulf %[[VAL_25]], %[[VAL_29]] : f32 40// CHECK: %[[VAL_31:.*]] = arith.cmpi sle, %[[VAL_26]], %[[VAL_13]] : i32 41// CHECK: %[[VAL_32:.*]] = arith.cmpi sge, %[[VAL_26]], %[[VAL_14]] : i32 42// CHECK: %[[VAL_33:.*]] = arith.cmpf oeq, %[[VAL_0]], %[[VAL_11]] : f32 43// CHECK: %[[VAL_34:.*]] = arith.cmpf oeq, %[[VAL_0]], %[[VAL_10]] : f32 44// CHECK: %[[VAL_35:.*]] = arith.cmpf ogt, %[[VAL_0]], %[[VAL_9]] : f32 45// CHECK: %[[VAL_36:.*]] = arith.andi %[[VAL_31]], %[[VAL_32]] : i1 46// CHECK: %[[VAL_37:.*]] = select %[[VAL_35]], %[[VAL_10]], %[[VAL_12]] : f32 47// CHECK: %[[VAL_38:.*]] = select %[[VAL_36]], %[[VAL_30]], %[[VAL_37]] : f32 48// CHECK: %[[VAL_39:.*]] = select %[[VAL_34]], %[[VAL_10]], %[[VAL_38]] : f32 49// CHECK: %[[VAL_40:.*]] = select %[[VAL_33]], %[[VAL_9]], %[[VAL_39]] : f32 50// CHECK: return %[[VAL_40]] : f32 51func @exp_scalar(%arg0: f32) -> f32 { 52 %0 = math.exp %arg0 : f32 53 return %0 : f32 54} 55 56// CHECK-LABEL: func @exp_vector( 57// CHECK-SAME: %[[VAL_0:.*]]: vector<8xf32>) -> vector<8xf32> { 58// CHECK: %[[VAL_1:.*]] = arith.constant dense<0.693147182> : vector<8xf32> 59// CHECK-NOT: exp 60// CHECK-COUNT-3: select 61// CHECK: %[[VAL_40:.*]] = select 62// CHECK: return %[[VAL_40]] : vector<8xf32> 63func @exp_vector(%arg0: vector<8xf32>) -> vector<8xf32> { 64 %0 = math.exp %arg0 : vector<8xf32> 65 return %0 : vector<8xf32> 66} 67 68// CHECK-LABEL: func @expm1_scalar( 69// CHECK-SAME: %[[X:.*]]: f32) -> f32 { 70// CHECK-DAG: %[[CST_MINUSONE:.*]] = arith.constant -1.000000e+00 : f32 71// CHECK-DAG: %[[CST_LOG2E:.*]] = arith.constant 1.44269502 : f32 72// CHECK-DAG: %[[CST_ONE:.*]] = arith.constant 1.000000e+00 : f32 73// CHECK: %[[BEGIN_EXP_X:.*]] = arith.mulf %[[X]], %[[CST_LOG2E]] : f32 74// CHECK-NOT: exp 75// CHECK-COUNT-3: select 76// CHECK: %[[EXP_X:.*]] = select 77// CHECK: %[[VAL_58:.*]] = arith.cmpf oeq, %[[EXP_X]], %[[CST_ONE]] : f32 78// CHECK: %[[VAL_59:.*]] = arith.subf %[[EXP_X]], %[[CST_ONE]] : f32 79// CHECK: %[[VAL_60:.*]] = arith.cmpf oeq, %[[VAL_59]], %[[CST_MINUSONE]] : f32 80// CHECK-NOT: log 81// CHECK-COUNT-5: select 82// CHECK: %[[LOG_U:.*]] = select 83// CHECK: %[[VAL_104:.*]] = arith.cmpf oeq, %[[LOG_U]], %[[EXP_X]] : f32 84// CHECK: %[[VAL_105:.*]] = arith.divf %[[X]], %[[LOG_U]] : f32 85// CHECK: %[[VAL_106:.*]] = arith.mulf %[[VAL_59]], %[[VAL_105]] : f32 86// CHECK: %[[VAL_107:.*]] = select %[[VAL_104]], %[[EXP_X]], %[[VAL_106]] : f32 87// CHECK: %[[VAL_108:.*]] = select %[[VAL_60]], %[[CST_MINUSONE]], %[[VAL_107]] : f32 88// CHECK: %[[VAL_109:.*]] = select %[[VAL_58]], %[[X]], %[[VAL_108]] : f32 89// CHECK: return %[[VAL_109]] : f32 90// CHECK: } 91func @expm1_scalar(%arg0: f32) -> f32 { 92 %0 = math.expm1 %arg0 : f32 93 return %0 : f32 94} 95 96// CHECK-LABEL: func @expm1_vector( 97// CHECK-SAME: %[[VAL_0:.*]]: vector<8xf32>) -> vector<8xf32> { 98// CHECK: %[[VAL_1:.*]] = arith.constant dense<-1.000000e+00> : vector<8xf32> 99// CHECK-NOT: exp 100// CHECK-COUNT-4: select 101// CHECK-NOT: log 102// CHECK-COUNT-5: select 103// CHECK-NOT: expm1 104// CHECK-COUNT-3: select 105// CHECK: %[[VAL_115:.*]] = select 106// CHECK: return %[[VAL_115]] : vector<8xf32> 107// CHECK: } 108func @expm1_vector(%arg0: vector<8xf32>) -> vector<8xf32> { 109 %0 = math.expm1 %arg0 : vector<8xf32> 110 return %0 : vector<8xf32> 111} 112 113// CHECK-LABEL: func @log_scalar( 114// CHECK-SAME: %[[X:.*]]: f32) -> f32 { 115// CHECK: %[[VAL_1:.*]] = arith.constant 0.000000e+00 : f32 116// CHECK: %[[VAL_2:.*]] = arith.constant 1.000000e+00 : f32 117// CHECK: %[[VAL_3:.*]] = arith.constant -5.000000e-01 : f32 118// CHECK: %[[VAL_4:.*]] = arith.constant 1.17549435E-38 : f32 119// CHECK: %[[VAL_5:.*]] = arith.constant 0xFF800000 : f32 120// CHECK: %[[VAL_6:.*]] = arith.constant 0x7F800000 : f32 121// CHECK: %[[VAL_7:.*]] = arith.constant 0x7FC00000 : f32 122// CHECK: %[[VAL_8:.*]] = arith.constant 0.707106769 : f32 123// CHECK: %[[VAL_9:.*]] = arith.constant 0.0703768358 : f32 124// CHECK: %[[VAL_10:.*]] = arith.constant -0.115146101 : f32 125// CHECK: %[[VAL_11:.*]] = arith.constant 0.116769984 : f32 126// CHECK: %[[VAL_12:.*]] = arith.constant -0.12420141 : f32 127// CHECK: %[[VAL_13:.*]] = arith.constant 0.142493233 : f32 128// CHECK: %[[VAL_14:.*]] = arith.constant -0.166680574 : f32 129// CHECK: %[[VAL_15:.*]] = arith.constant 0.200007141 : f32 130// CHECK: %[[VAL_16:.*]] = arith.constant -0.24999994 : f32 131// CHECK: %[[VAL_17:.*]] = arith.constant 0.333333313 : f32 132// CHECK: %[[VAL_18:.*]] = arith.constant 1.260000e+02 : f32 133// CHECK: %[[VAL_19:.*]] = arith.constant -2139095041 : i32 134// CHECK: %[[VAL_20:.*]] = arith.constant 1056964608 : i32 135// CHECK: %[[VAL_21:.*]] = arith.constant 23 : i32 136// CHECK: %[[VAL_22:.*]] = arith.constant 0.693147182 : f32 137// CHECK: %[[VAL_23:.*]] = arith.cmpf ogt, %[[X]], %[[VAL_4]] : f32 138// CHECK: %[[VAL_24:.*]] = select %[[VAL_23]], %[[X]], %[[VAL_4]] : f32 139// CHECK-NOT: frexp 140// CHECK: %[[VAL_25:.*]] = arith.bitcast %[[VAL_24]] : f32 to i32 141// CHECK: %[[VAL_26:.*]] = arith.andi %[[VAL_25]], %[[VAL_19]] : i32 142// CHECK: %[[VAL_27:.*]] = arith.ori %[[VAL_26]], %[[VAL_20]] : i32 143// CHECK: %[[VAL_28:.*]] = arith.bitcast %[[VAL_27]] : i32 to f32 144// CHECK: %[[VAL_29:.*]] = arith.bitcast %[[VAL_24]] : f32 to i32 145// CHECK: %[[VAL_30:.*]] = arith.shrui %[[VAL_29]], %[[VAL_21]] : i32 146// CHECK: %[[VAL_31:.*]] = arith.sitofp %[[VAL_30]] : i32 to f32 147// CHECK: %[[VAL_32:.*]] = arith.subf %[[VAL_31]], %[[VAL_18]] : f32 148// CHECK: %[[VAL_33:.*]] = arith.cmpf olt, %[[VAL_28]], %[[VAL_8]] : f32 149// CHECK: %[[VAL_34:.*]] = select %[[VAL_33]], %[[VAL_28]], %[[VAL_1]] : f32 150// CHECK: %[[VAL_35:.*]] = arith.subf %[[VAL_28]], %[[VAL_2]] : f32 151// CHECK: %[[VAL_36:.*]] = select %[[VAL_33]], %[[VAL_2]], %[[VAL_1]] : f32 152// CHECK: %[[VAL_37:.*]] = arith.subf %[[VAL_32]], %[[VAL_36]] : f32 153// CHECK: %[[VAL_38:.*]] = arith.addf %[[VAL_35]], %[[VAL_34]] : f32 154// CHECK: %[[VAL_39:.*]] = arith.mulf %[[VAL_38]], %[[VAL_38]] : f32 155// CHECK: %[[VAL_40:.*]] = arith.mulf %[[VAL_39]], %[[VAL_38]] : f32 156// CHECK: %[[VAL_41:.*]] = math.fma %[[VAL_9]], %[[VAL_38]], %[[VAL_10]] : f32 157// CHECK: %[[VAL_42:.*]] = math.fma %[[VAL_12]], %[[VAL_38]], %[[VAL_13]] : f32 158// CHECK: %[[VAL_43:.*]] = math.fma %[[VAL_15]], %[[VAL_38]], %[[VAL_16]] : f32 159// CHECK: %[[VAL_44:.*]] = math.fma %[[VAL_41]], %[[VAL_38]], %[[VAL_11]] : f32 160// CHECK: %[[VAL_45:.*]] = math.fma %[[VAL_42]], %[[VAL_38]], %[[VAL_14]] : f32 161// CHECK: %[[VAL_46:.*]] = math.fma %[[VAL_43]], %[[VAL_38]], %[[VAL_17]] : f32 162// CHECK: %[[VAL_47:.*]] = math.fma %[[VAL_44]], %[[VAL_40]], %[[VAL_45]] : f32 163// CHECK: %[[VAL_48:.*]] = math.fma %[[VAL_47]], %[[VAL_40]], %[[VAL_46]] : f32 164// CHECK: %[[VAL_49:.*]] = arith.mulf %[[VAL_48]], %[[VAL_40]] : f32 165// CHECK: %[[VAL_50:.*]] = math.fma %[[VAL_3]], %[[VAL_39]], %[[VAL_49]] : f32 166// CHECK: %[[VAL_51:.*]] = arith.addf %[[VAL_38]], %[[VAL_50]] : f32 167// CHECK: %[[VAL_52:.*]] = math.fma %[[VAL_37]], %[[VAL_22]], %[[VAL_51]] : f32 168// CHECK: %[[VAL_53:.*]] = arith.cmpf ult, %[[X]], %[[VAL_1]] : f32 169// CHECK: %[[VAL_54:.*]] = arith.cmpf oeq, %[[X]], %[[VAL_1]] : f32 170// CHECK: %[[VAL_55:.*]] = arith.cmpf oeq, %[[X]], %[[VAL_6]] : f32 171// CHECK: %[[VAL_56:.*]] = select %[[VAL_55]], %[[VAL_6]], %[[VAL_52]] : f32 172// CHECK: %[[VAL_57:.*]] = select %[[VAL_53]], %[[VAL_7]], %[[VAL_56]] : f32 173// CHECK: %[[VAL_58:.*]] = select %[[VAL_54]], %[[VAL_5]], %[[VAL_57]] : f32 174// CHECK: return %[[VAL_58]] : f32 175// CHECK: } 176func @log_scalar(%arg0: f32) -> f32 { 177 %0 = math.log %arg0 : f32 178 return %0 : f32 179} 180 181// CHECK-LABEL: func @log_vector( 182// CHECK-SAME: %[[VAL_0:.*]]: vector<8xf32>) -> vector<8xf32> { 183// CHECK: %[[CST_LN2:.*]] = arith.constant dense<0.693147182> : vector<8xf32> 184// CHECK-COUNT-5: select 185// CHECK: %[[VAL_71:.*]] = select 186// CHECK: return %[[VAL_71]] : vector<8xf32> 187// CHECK: } 188func @log_vector(%arg0: vector<8xf32>) -> vector<8xf32> { 189 %0 = math.log %arg0 : vector<8xf32> 190 return %0 : vector<8xf32> 191} 192 193// CHECK-LABEL: func @log2_scalar( 194// CHECK-SAME: %[[VAL_0:.*]]: f32) -> f32 { 195// CHECK: %[[CST_LOG2E:.*]] = arith.constant 1.44269502 : f32 196// CHECK-COUNT-5: select 197// CHECK: %[[VAL_65:.*]] = select 198// CHECK: return %[[VAL_65]] : f32 199// CHECK: } 200func @log2_scalar(%arg0: f32) -> f32 { 201 %0 = math.log2 %arg0 : f32 202 return %0 : f32 203} 204 205// CHECK-LABEL: func @log2_vector( 206// CHECK-SAME: %[[VAL_0:.*]]: vector<8xf32>) -> vector<8xf32> { 207// CHECK: %[[CST_LOG2E:.*]] = arith.constant dense<1.44269502> : vector<8xf32> 208// CHECK-COUNT-5: select 209// CHECK: %[[VAL_71:.*]] = select 210// CHECK: return %[[VAL_71]] : vector<8xf32> 211// CHECK: } 212func @log2_vector(%arg0: vector<8xf32>) -> vector<8xf32> { 213 %0 = math.log2 %arg0 : vector<8xf32> 214 return %0 : vector<8xf32> 215} 216 217// CHECK-LABEL: func @log1p_scalar( 218// CHECK-SAME: %[[X:.*]]: f32) -> f32 { 219// CHECK: %[[CST_ONE:.*]] = arith.constant 1.000000e+00 : f32 220// CHECK: %[[U:.*]] = arith.addf %[[X]], %[[CST_ONE]] : f32 221// CHECK: %[[U_SMALL:.*]] = arith.cmpf oeq, %[[U]], %[[CST_ONE]] : f32 222// CHECK-NOT: log 223// CHECK-COUNT-5: select 224// CHECK: %[[LOG_U:.*]] = select 225// CHECK: %[[U_INF:.*]] = arith.cmpf oeq, %[[U]], %[[LOG_U]] : f32 226// CHECK: %[[VAL_69:.*]] = arith.subf %[[U]], %[[CST_ONE]] : f32 227// CHECK: %[[VAL_70:.*]] = arith.divf %[[LOG_U]], %[[VAL_69]] : f32 228// CHECK: %[[LOG_LARGE:.*]] = arith.mulf %[[X]], %[[VAL_70]] : f32 229// CHECK: %[[VAL_72:.*]] = arith.ori %[[U_SMALL]], %[[U_INF]] : i1 230// CHECK: %[[APPROX:.*]] = select %[[VAL_72]], %[[X]], %[[LOG_LARGE]] : f32 231// CHECK: return %[[APPROX]] : f32 232// CHECK: } 233func @log1p_scalar(%arg0: f32) -> f32 { 234 %0 = math.log1p %arg0 : f32 235 return %0 : f32 236} 237 238// CHECK-LABEL: func @log1p_vector( 239// CHECK-SAME: %[[VAL_0:.*]]: vector<8xf32>) -> vector<8xf32> { 240// CHECK: %[[CST_ONE:.*]] = arith.constant dense<1.000000e+00> : vector<8xf32> 241// CHECK-COUNT-6: select 242// CHECK: %[[VAL_79:.*]] = select 243// CHECK: return %[[VAL_79]] : vector<8xf32> 244// CHECK: } 245func @log1p_vector(%arg0: vector<8xf32>) -> vector<8xf32> { 246 %0 = math.log1p %arg0 : vector<8xf32> 247 return %0 : vector<8xf32> 248} 249 250 251// CHECK-LABEL: func @tanh_scalar( 252// CHECK-SAME: %[[VAL_0:.*]]: f32) -> f32 { 253// CHECK: %[[VAL_1:.*]] = arith.constant -7.99881172 : f32 254// CHECK: %[[VAL_2:.*]] = arith.constant 7.99881172 : f32 255// CHECK: %[[VAL_3:.*]] = arith.constant 4.000000e-04 : f32 256// CHECK: %[[VAL_4:.*]] = arith.constant 0.00489352457 : f32 257// CHECK: %[[VAL_5:.*]] = arith.constant 6.37261954E-4 : f32 258// CHECK: %[[VAL_6:.*]] = arith.constant 1.48572235E-5 : f32 259// CHECK: %[[VAL_7:.*]] = arith.constant 5.12229725E-8 : f32 260// CHECK: %[[VAL_8:.*]] = arith.constant -8.60467184E-11 : f32 261// CHECK: %[[VAL_9:.*]] = arith.constant 2.00018794E-13 : f32 262// CHECK: %[[VAL_10:.*]] = arith.constant -2.76076837E-16 : f32 263// CHECK: %[[VAL_11:.*]] = arith.constant 0.00489352504 : f32 264// CHECK: %[[VAL_12:.*]] = arith.constant 0.00226843474 : f32 265// CHECK: %[[VAL_13:.*]] = arith.constant 1.18534706E-4 : f32 266// CHECK: %[[VAL_14:.*]] = arith.constant 1.19825836E-6 : f32 267// CHECK: %[[VAL_15:.*]] = arith.cmpf olt, %[[VAL_0]], %[[VAL_2]] : f32 268// CHECK: %[[VAL_16:.*]] = select %[[VAL_15]], %[[VAL_0]], %[[VAL_2]] : f32 269// CHECK: %[[VAL_17:.*]] = arith.cmpf ogt, %[[VAL_16]], %[[VAL_1]] : f32 270// CHECK: %[[VAL_18:.*]] = select %[[VAL_17]], %[[VAL_16]], %[[VAL_1]] : f32 271// CHECK: %[[VAL_19:.*]] = math.abs %[[VAL_0]] : f32 272// CHECK: %[[VAL_20:.*]] = arith.cmpf olt, %[[VAL_19]], %[[VAL_3]] : f32 273// CHECK: %[[VAL_21:.*]] = arith.mulf %[[VAL_18]], %[[VAL_18]] : f32 274// CHECK: %[[VAL_22:.*]] = math.fma %[[VAL_21]], %[[VAL_10]], %[[VAL_9]] : f32 275// CHECK: %[[VAL_23:.*]] = math.fma %[[VAL_21]], %[[VAL_22]], %[[VAL_8]] : f32 276// CHECK: %[[VAL_24:.*]] = math.fma %[[VAL_21]], %[[VAL_23]], %[[VAL_7]] : f32 277// CHECK: %[[VAL_25:.*]] = math.fma %[[VAL_21]], %[[VAL_24]], %[[VAL_6]] : f32 278// CHECK: %[[VAL_26:.*]] = math.fma %[[VAL_21]], %[[VAL_25]], %[[VAL_5]] : f32 279// CHECK: %[[VAL_27:.*]] = math.fma %[[VAL_21]], %[[VAL_26]], %[[VAL_4]] : f32 280// CHECK: %[[VAL_28:.*]] = arith.mulf %[[VAL_18]], %[[VAL_27]] : f32 281// CHECK: %[[VAL_29:.*]] = math.fma %[[VAL_21]], %[[VAL_14]], %[[VAL_13]] : f32 282// CHECK: %[[VAL_30:.*]] = math.fma %[[VAL_21]], %[[VAL_29]], %[[VAL_12]] : f32 283// CHECK: %[[VAL_31:.*]] = math.fma %[[VAL_21]], %[[VAL_30]], %[[VAL_11]] : f32 284// CHECK: %[[VAL_32:.*]] = arith.divf %[[VAL_28]], %[[VAL_31]] : f32 285// CHECK: %[[VAL_33:.*]] = select %[[VAL_20]], %[[VAL_18]], %[[VAL_32]] : f32 286// CHECK: return %[[VAL_33]] : f32 287// CHECK: } 288func @tanh_scalar(%arg0: f32) -> f32 { 289 %0 = math.tanh %arg0 : f32 290 return %0 : f32 291} 292 293// CHECK-LABEL: func @tanh_vector( 294// CHECK-SAME: %[[VAL_0:.*]]: vector<8xf32>) -> vector<8xf32> { 295// CHECK: %[[VAL_1:.*]] = arith.constant dense<-7.99881172> : vector<8xf32> 296// CHECK-NOT: tanh 297// CHECK-COUNT-2: select 298// CHECK: %[[VAL_33:.*]] = select 299// CHECK: return %[[VAL_33]] : vector<8xf32> 300// CHECK: } 301func @tanh_vector(%arg0: vector<8xf32>) -> vector<8xf32> { 302 %0 = math.tanh %arg0 : vector<8xf32> 303 return %0 : vector<8xf32> 304} 305 306// We only approximate rsqrt for vectors and when the AVX2 option is enabled. 307// CHECK-LABEL: func @rsqrt_scalar 308// AVX2-LABEL: func @rsqrt_scalar 309// CHECK: math.rsqrt 310// AVX2: math.rsqrt 311func @rsqrt_scalar(%arg0: f32) -> f32 { 312 %0 = math.rsqrt %arg0 : f32 313 return %0 : f32 314} 315 316// CHECK-LABEL: func @rsqrt_vector 317// CHECK: math.rsqrt 318// AVX2-LABEL: func @rsqrt_vector( 319// AVX2-SAME: %[[VAL_0:.*]]: vector<8xf32>) -> vector<8xf32> { 320// AVX2: %[[VAL_1:.*]] = arith.constant dense<0x7F800000> : vector<8xf32> 321// AVX2: %[[VAL_2:.*]] = arith.constant dense<1.500000e+00> : vector<8xf32> 322// AVX2: %[[VAL_3:.*]] = arith.constant dense<-5.000000e-01> : vector<8xf32> 323// AVX2: %[[VAL_4:.*]] = arith.constant dense<1.17549435E-38> : vector<8xf32> 324// AVX2: %[[VAL_5:.*]] = arith.mulf %[[VAL_0]], %[[VAL_3]] : vector<8xf32> 325// AVX2: %[[VAL_6:.*]] = arith.cmpf olt, %[[VAL_0]], %[[VAL_4]] : vector<8xf32> 326// AVX2: %[[VAL_7:.*]] = arith.cmpf oeq, %[[VAL_0]], %[[VAL_1]] : vector<8xf32> 327// AVX2: %[[VAL_8:.*]] = arith.ori %[[VAL_6]], %[[VAL_7]] : vector<8xi1> 328// AVX2: %[[VAL_9:.*]] = x86vector.avx.rsqrt %[[VAL_0]] : vector<8xf32> 329// AVX2: %[[VAL_10:.*]] = arith.mulf %[[VAL_5]], %[[VAL_9]] : vector<8xf32> 330// AVX2: %[[VAL_11:.*]] = math.fma %[[VAL_9]], %[[VAL_10]], %[[VAL_2]] : vector<8xf32> 331// AVX2: %[[VAL_12:.*]] = arith.mulf %[[VAL_9]], %[[VAL_11]] : vector<8xf32> 332// AVX2: %[[VAL_13:.*]] = select %[[VAL_8]], %[[VAL_9]], %[[VAL_12]] : vector<8xi1>, vector<8xf32> 333// AVX2: return %[[VAL_13]] : vector<8xf32> 334// AVX2: } 335func @rsqrt_vector(%arg0: vector<8xf32>) -> vector<8xf32> { 336 %0 = math.rsqrt %arg0 : vector<8xf32> 337 return %0 : vector<8xf32> 338} 339