Skip to content

Commit e90382b

Browse files
mshelegofda0
authored andcommitted
Check for FP64 emulation in GenXPatternMatch
Prevent GenXPatternMatch from optimizing fdiv if it should be later replaced with builtin function call (cherry picked from commit 5ffba5c)
1 parent 2524207 commit e90382b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXPatternMatch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,10 @@ void GenXPatternMatch::visitFDiv(BinaryOperator &I) {
21212121
return;
21222122
}
21232123

2124+
// Skip if FP64 emulation is required for this platform
2125+
if (ST->emulateFDivFSqrt64() && I.getType()->getScalarType()->isDoubleTy())
2126+
return;
2127+
21242128
// Skip if reciprocal optimization is not allowed.
21252129
if (!I.hasAllowReciprocal())
21262130
return;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2023 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
; RUN: %opt %use_old_pass_manager% -GenXPatternMatch -march=genx64 -mcpu=Gen9 -mtriple=spir64-unknown-unknown -S < %s | FileCheck --check-prefix=CHECK-OPT %s
9+
; RUN: %opt %use_old_pass_manager% -GenXPatternMatch -march=genx64 -mcpu=XeLP -mtriple=spir64-unknown-unknown -S < %s | FileCheck --check-prefix=CHECK-OPT %s
10+
; RUN: %opt %use_old_pass_manager% -GenXPatternMatch -march=genx64 -mcpu=XeHPG -mtriple=spir64-unknown-unknown -S < %s | FileCheck --check-prefix=CHECK-OPT %s
11+
; RUN: %opt %use_old_pass_manager% -GenXPatternMatch -march=genx64 -mcpu=XeLPG -mtriple=spir64-unknown-unknown -S < %s | FileCheck --check-prefix=CHECK-NO-OPT %s
12+
; RUN: %opt %use_old_pass_manager% -GenXPatternMatch -march=genx64 -mcpu=XeHPC -mtriple=spir64-unknown-unknown -S < %s | FileCheck --check-prefix=CHECK-OPT %s
13+
14+
; CHECK-NO-OPT-LABEL: test
15+
; CHECK-NO-OPT: [[ADD:[^ ]+]] = fadd <16 x double> %a, %b
16+
; CHECK-NO-OPT: [[RES:[^ ]+]] = fdiv arcp <16 x double> %a, [[ADD]]
17+
; CHECK-NO-OPT: ret <16 x double> [[RES]]
18+
19+
; CHECK-OPT-LABEL: test
20+
; CHECK-OPT: [[ADD:[^ ]+]] = fadd <16 x double> %a, %b
21+
; CHECK-OPT: [[ADD_INV:[^ ]+]] = call <16 x double> @llvm.genx.inv.v16f64(<16 x double> [[ADD]])
22+
; CHECK-OPT: [[RES:[^ ]+]] = fmul arcp <16 x double> %a, [[ADD_INV]]
23+
; CHECK-OPT: ret <16 x double> [[RES]]
24+
25+
define <16 x double> @test(<16 x double> %a, <16 x double> %b) {
26+
%add = fadd <16 x double> %a, %b
27+
%res = fdiv arcp <16 x double> %a, %add
28+
ret <16 x double> %res
29+
}

0 commit comments

Comments
 (0)