1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
|
;=========================== begin_copyright_notice ============================
;
; Copyright (C) 2021-2024 Intel Corporation
;
; SPDX-License-Identifier: MIT
;
;============================ end_copyright_notice =============================
; RUN: %opt %use_old_pass_manager% -GenXPatternMatch -march=genx64 -mcpu=Gen9 \
; RUN: -mtriple=spir64-unknown-unknown -S < %s | FileCheck %s
; CHECK-LABEL: @test_inverse
define <16 x float> @test_inverse(<16 x float> %val) {
%sqrt = call <16 x float> @llvm.genx.sqrt.v16f32(<16 x float> %val)
; CHECK: [[INVERSE_SQRT:%.*]] = call <16 x float> @llvm.genx.rsqrt.v16f32(<16 x float> %val)
; CHECK-NEXT: ret <16 x float> [[INVERSE_SQRT]]
%inv = call <16 x float> @llvm.genx.inv.v16f32(<16 x float> %sqrt)
ret <16 x float> %inv
}
; CHECK-LABEL: @test_inverse2
define <16 x float> @test_inverse2(<16 x float> %val1, <16 x float> %val2) {
; CHECK: [[INVERSE_SQRT21:%.*]] = call <16 x float> @llvm.genx.rsqrt.v16f32(<16 x float> %val1)
; CHECK-NEXT: [[INVERSE_SQRT22:%.*]] = call <16 x float> @llvm.genx.rsqrt.v16f32(<16 x float> %val2)
; CHECK-NEXT: [[FADD:%.*]] = fadd <16 x float> [[INVERSE_SQRT21]], [[INVERSE_SQRT22]]
; CHECK-NEXT: ret <16 x float> [[FADD]]
%sqrt1 = call fast <16 x float> @llvm.sqrt.v16f32(<16 x float> %val1)
%inv1 = call <16 x float> @llvm.genx.inv.v16f32(<16 x float> %sqrt1)
%sqrt2 = call <16 x float> @llvm.genx.sqrt.v16f32(<16 x float> %val2)
%inv2 = call <16 x float> @llvm.genx.inv.v16f32(<16 x float> %sqrt2)
%add = fadd <16 x float> %inv1, %inv2
ret <16 x float> %add
}
; CHECK-LABEL: @test_inverse_scalar
define float @test_inverse_scalar(float %val) {
%sqrt = call float @llvm.genx.sqrt.f32(float %val)
; CHECK: [[INVERSE_SQRT_SCALAR:%.*]] = call float @llvm.genx.rsqrt.f32(float %val)
; CHECK-NEXT: ret float [[INVERSE_SQRT_SCALAR]]
%inv = call float @llvm.genx.inv.f32(float %sqrt)
ret float %inv
}
; CHECK-LABEL: @test_inverse_fast
define <16 x float> @test_inverse_fast(<16 x float> %val) {
%sqrt = call fast <16 x float> @llvm.sqrt.v16f32(<16 x float> %val)
; CHECK: [[INVERSE_SQRT_FAST:%.*]] = call <16 x float> @llvm.genx.rsqrt.v16f32(<16 x float> %val)
; CHECK-NEXT: ret <16 x float> [[INVERSE_SQRT_FAST]]
%inv = call <16 x float> @llvm.genx.inv.v16f32(<16 x float> %sqrt)
ret <16 x float> %inv
}
; CHECK-LABEL: @test_inverse_not_fast
define <16 x float> @test_inverse_not_fast(<16 x float> %src) {
; CHECK: @llvm.genx.rsqrt.v16f32(<16 x float> %src)
%sqrt = call <16 x float> @llvm.sqrt.v16f32(<16 x float> %src)
%inv = call <16 x float> @llvm.genx.inv.v16f32(<16 x float> %sqrt)
ret <16 x float> %inv
}
; CHECK-LABEL: @test_inverse_double
define <16 x double> @test_inverse_double(<16 x double> %val_double) {
%sqrt = call <16 x double> @llvm.sqrt.v16f64(<16 x double> %val_double)
; CHECK: call <16 x double> @llvm.genx.rsqrt.v16f64(<16 x double> %val_double)
%inv = call <16 x double> @llvm.genx.inv.v16f64(<16 x double> %sqrt)
ret <16 x double> %inv
}
; CHECK-LABEL: @test_not_inverse_multiple_uses
define <16 x float> @test_not_inverse_multiple_uses(<16 x float> %val) {
; CHECK: call <16 x float> @llvm.sqrt.v16f32(<16 x float> %val)
; CHECK: call <16 x float> @llvm.genx.rsqrt.v16f32(<16 x float> %val)
; CHECK: fadd <16 x float>
%sqrt = call <16 x float> @llvm.sqrt.v16f32(<16 x float> %val)
%inv = call <16 x float> @llvm.genx.inv.v16f32(<16 x float> %sqrt)
%add = fadd <16 x float> %inv, %sqrt
ret <16 x float> %add
}
; CHECK-LABEL: @test_inverse3
define <16 x float> @test_inverse3(<16 x float> %val) {
%sqrt = call <16 x float> @llvm.genx.sqrt.v16f32(<16 x float> %val)
; CHECK: [[INVERSE_SQRT_FDIV:%.*]] = call <16 x float> @llvm.genx.rsqrt.v16f32(<16 x float> %val)
; CHECK-NEXT: ret <16 x float> [[INVERSE_SQRT_FDIV]]
%inv = fdiv fast <16 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, %sqrt
ret <16 x float> %inv
}
; CHECK-LABEL: @test_inverse_of_not_sqrt
define <16 x float> @test_inverse_of_not_sqrt(<16 x float> %val, <16 x float> %tmp) {
; CHECK-NEXT: fsub <16 x float>
; CHECK-NEXT: call <16 x float> @llvm.genx.inv.v16f32
%sub = fsub <16 x float> %val, %tmp
%inv = call <16 x float> @llvm.genx.inv.v16f32(<16 x float> %sub)
ret <16 x float> %inv
}
; CHECK-LABEL: @test_sqrt_multiple_use
define <16 x float> @test_sqrt_multiple_use(<16 x float> %val) {
; CHECK-NEXT: call <16 x float> @llvm.genx.sqrt.v16f32(<16 x float> %val)
; CHECK-NEXT: call <16 x float> @llvm.genx.rsqrt.v16f32(<16 x float> %val)
; CHECK-NEXT: fadd <16 x float>
%sqrt = call <16 x float> @llvm.genx.sqrt.v16f32(<16 x float> %val)
%inv = call <16 x float> @llvm.genx.inv.v16f32(<16 x float> %sqrt)
%add = fadd <16 x float> %sqrt, %inv
ret <16 x float> %add
}
; CHECK-LABEL: @test_sqrt_inv_constant
define float @test_sqrt_inv_constant() {
; CHECK: ret float 0x3FB99999A0000000
%sqrt = call float @llvm.genx.sqrt.f32(float 100.0)
%inv = call float @llvm.genx.inv.f32(float %sqrt)
ret float %inv
}
; CHECK-LABEL: @test_sqrt_div_constant
define float @test_sqrt_div_constant() {
; CHECK: ret float 0x3FB99999A0000000
%sqrt = call float @llvm.genx.sqrt.f32(float 100.0)
%inv = fdiv arcp float 1.0, %sqrt
ret float %inv
}
; CHECK-LABEL: @test_sqrt_fast_inv_constant
define float @test_sqrt_fast_inv_constant() {
; CHECK: ret float 0x3FB99999A0000000
%sqrt = call afn float @llvm.sqrt.f32(float 100.0)
%inv = call float @llvm.genx.inv.f32(float %sqrt)
ret float %inv
}
; CHECK-LABEL: @test_sqrt_inv_constant_neg
define float @test_sqrt_inv_constant_neg() {
; CHECK: ret float 0x7FF8000000000000
%sqrt = call float @llvm.genx.sqrt.f32(float -100.0)
%inv = call float @llvm.genx.inv.f32(float %sqrt)
ret float %inv
}
; CHECK-LABEL: @test_sqrt_inv_constant_negzero
define float @test_sqrt_inv_constant_negzero() {
; CHECK: ret float 0xFFF0000000000000
%sqrt = call float @llvm.genx.sqrt.f32(float -0.0)
%inv = call float @llvm.genx.inv.f32(float %sqrt)
ret float %inv
}
; CHECK-LABEL: @test_sqrt_inv_constant_zero
define float @test_sqrt_inv_constant_zero() {
; CHECK: ret float 0x7FF0000000000000
%sqrt = call float @llvm.genx.sqrt.f32(float 0.0)
%inv = call float @llvm.genx.inv.f32(float %sqrt)
ret float %inv
}
; CHECK-LABEL: @test_sqrt_inv_constant_inf
define float @test_sqrt_inv_constant_inf() {
; CHECK: ret float 0.000000e+00
%sqrt = call float @llvm.genx.sqrt.f32(float 0x7FF0000000000000)
%inv = call float @llvm.genx.inv.f32(float %sqrt)
ret float %inv
}
; CHECK-LABEL: @test_sqrt_inv_constant_neginf
define float @test_sqrt_inv_constant_neginf() {
; CHECK: ret float 0x7FF8000000000000
%sqrt = call float @llvm.genx.sqrt.f32(float 0xFFF0000000000000)
%inv = call float @llvm.genx.inv.f32(float %sqrt)
ret float %inv
}
; CHECK-LABEL: @test_sqrt_inv_constant_undef
define float @test_sqrt_inv_constant_undef() {
; CHECK: ret float undef
%sqrt = call float @llvm.genx.sqrt.f32(float undef)
%inv = call float @llvm.genx.inv.f32(float %sqrt)
ret float %inv
}
; CHECK-LABEL: @test_sqrt_inv_constant_vector
define <2 x float> @test_sqrt_inv_constant_vector() {
; CHECK: ret <2 x float> <float 0x3FC99999A0000000, float 5.000000e-01>
%sqrt = call <2 x float> @llvm.genx.sqrt.v2f32(<2 x float> <float 25.0, float 4.0>)
%inv = call <2 x float> @llvm.genx.inv.v2f32(<2 x float> %sqrt)
ret <2 x float> %inv
}
; CHECK-LABEL: @test_sqrt_inv_constant_vector_zero
define <2 x float> @test_sqrt_inv_constant_vector_zero() {
; CHECK: ret <2 x float> <float 0x7FF0000000000000, float 0x7FF0000000000000>
%sqrt = call <2 x float> @llvm.genx.sqrt.v2f32(<2 x float> zeroinitializer)
%inv = call <2 x float> @llvm.genx.inv.v2f32(<2 x float> %sqrt)
ret <2 x float> %inv
}
; CHECK-LABEL: @test_inv_sqrt_1
define <16 x float> @test_inv_sqrt_1(<16 x float> %val) {
; CHECK: call <16 x float> @llvm.genx.rsqrt.v16f32(<16 x float> %val)
%inv = call <16 x float> @llvm.genx.inv.v16f32(<16 x float> %val)
%sqrt = call <16 x float> @llvm.genx.sqrt.v16f32(<16 x float> %inv)
ret <16 x float> %sqrt
}
; CHECK-LABEL: @test_inv_sqrt_2
define <16 x float> @test_inv_sqrt_2(<16 x float> %val) {
; CHECK: call <16 x float> @llvm.genx.rsqrt.v16f32(<16 x float> %val)
%inv = call <16 x float> @llvm.genx.inv.v16f32(<16 x float> %val)
%sqrt = call <16 x float> @llvm.sqrt.v16f32(<16 x float> %inv)
ret <16 x float> %sqrt
}
; CHECK-LABEL: @test_inv_sqrt_3
define float @test_inv_sqrt_3(float %val) {
; CHECK: call float @llvm.genx.rsqrt.f32(float %val)
%inv = fdiv float 1.0, %val
%sqrt = call float @llvm.genx.sqrt.f32(float %inv)
ret float %sqrt
}
; CHECK-LABEL: @test_inv_sqrt_4
define float @test_inv_sqrt_4(float %val) {
; CHECK: call float @llvm.genx.rsqrt.f32(float %val)
%inv = fdiv float 1.0, %val
%sqrt = call afn float @llvm.sqrt.f32(float %inv)
ret float %sqrt
}
; CHECK-LABEL: @test_inv_sqrt_5
define float @test_inv_sqrt_5(float %val) {
; CHECK: call float @llvm.genx.rsqrt.f32(float %val)
%inv = fdiv arcp float 1.0, %val
%sqrt = call float @llvm.sqrt.f32(float %inv)
ret float %sqrt
}
; CHECK-LABEL: @test_inv_sqrt_6
define float @test_inv_sqrt_6(float %val) {
; CHECK-NOT: call float @llvm.genx.rsqrt.f32(float %val)
%inv = fdiv float 1.0, %val
%sqrt = call float @llvm.sqrt.f32(float %inv)
ret float %sqrt
}
; CHECK-LABEL: @test_inverse_double_2
define <16 x double> @test_inverse_double_2(<16 x double> %val_double) {
%sqrt = call <16 x double> @llvm.genx.sqrt.v16f64(<16 x double> %val_double)
%div = fdiv <16 x double> <double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00>, %sqrt
; CHECK: call <16 x double> @llvm.genx.rsqrt.v16f64(<16 x double> %val_double)
ret <16 x double> %div
}
; CHECK-LABEL: @test_inverse_double_3
define <16 x double> @test_inverse_double_3(<16 x double> %val_double) {
%div = fdiv arcp <16 x double> <double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00>, %val_double
%sqrt = call <16 x double> @llvm.genx.sqrt.v16f64(<16 x double> %div)
; CHECK: call <16 x double> @llvm.genx.rsqrt.v16f64(<16 x double> %val_double)
ret <16 x double> %sqrt
}
declare float @llvm.sqrt.f32(float)
declare float @llvm.genx.sqrt.f32(float)
declare float @llvm.genx.inv.f32(float)
declare <2 x float> @llvm.genx.sqrt.v2f32(<2 x float>)
declare <2 x float> @llvm.genx.inv.v2f32(<2 x float>)
declare <16 x float> @llvm.sqrt.v16f32(<16 x float>)
declare <16 x double> @llvm.sqrt.v16f64(<16 x double>)
declare <16 x float> @llvm.genx.sqrt.v16f32(<16 x float>)
declare <16 x double> @llvm.genx.sqrt.v16f64(<16 x double>)
declare <16 x float> @llvm.genx.inv.v16f32(<16 x float>)
declare <16 x double> @llvm.genx.inv.v16f64(<16 x double>)
|