Skip to content

Commit 5ffba5c

Browse files
mshelegoigcbot
authored andcommitted
Check for FP64 emulation in GenXPatternMatch
Prevent GenXPatternMatch from optimizing fdiv if it should be later replaced with builtin function call
1 parent f46193a commit 5ffba5c

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
@@ -2101,6 +2101,10 @@ void GenXPatternMatch::visitFDiv(BinaryOperator &I) {
21012101
return;
21022102
}
21032103

2104+
// Skip if FP64 emulation is required for this platform
2105+
if (ST->emulateFDivFSqrt64() && I.getType()->getScalarType()->isDoubleTy())
2106+
return;
2107+
21042108
// Skip if reciprocal optimization is not allowed.
21052109
if (!I.hasAllowReciprocal())
21062110
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)