Skip to content

Commit 15a9f48

Browse files
mshelegofda0
authored andcommitted
Do not split dead parts of IEEE intrinsics
These intrinsics end up as DIVM and SQRTM visa instructions and their execution size is restored to 8 or 16 by finalizer, so there is no sense in splitting their unused parts (cherry picked from commit 82e2902)
1 parent 3e9dec8 commit 15a9f48

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXLegalization.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2017-2023 Intel Corporation
3+
Copyright (C) 2017-2024 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -1124,10 +1124,20 @@ unsigned GenXLegalization::splitDeadElements(unsigned Width,
11241124
auto *V = getExecWidthValue();
11251125
auto *ElemTy = V->getType()->getScalarType();
11261126
// The most math instructions require exec size to be 8 or 16 in case of half
1127-
// float. Even if we reduce the width here, it will be very likely set back to
1128-
// the 'native' width by finalizer
1127+
// float. And some of them require it even for other float types. Even if we
1128+
// reduce the width here, it will be very likely set back to the 'native'
1129+
// width by finalizer
11291130
if (ElemTy->isHalfTy())
11301131
return Width;
1132+
if (ElemTy->isFloatTy()) {
1133+
auto Main = B.getMainInst();
1134+
if (Main) {
1135+
unsigned IID = vc::getAnyIntrinsicID(Main->Inst);
1136+
if (IID == GenXIntrinsic::genx_ieee_div ||
1137+
IID == GenXIntrinsic::genx_ieee_sqrt)
1138+
return Width;
1139+
}
1140+
}
11311141
const auto &LiveElems = LE->getLiveElements(V);
11321142
if (LiveElems.size() > 1 || LiveElems.isAllDead() || !LiveElems.isAnyDead())
11331143
return Width;

IGC/VectorCompiler/test/Legalization/live-elements.ll

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
;=========================== begin_copyright_notice ============================
22
;
3-
; Copyright (C) 2023 Intel Corporation
3+
; Copyright (C) 2023-2024 Intel Corporation
44
;
55
; SPDX-License-Identifier: MIT
66
;
77
;============================ end_copyright_notice =============================
88

99
; RUN: %opt %use_old_pass_manager% -GenXLegalization -march=genx64 -mcpu=Gen9 -mtriple=spir64-unknown-unknown -S < %s | FileCheck %s
1010

11+
declare <16 x float> @llvm.genx.ieee.sqrt.v16f32(<16 x float>)
12+
declare <16 x float> @llvm.genx.ieee.div.v16f32(<16 x float>, <16 x float>)
13+
1114
; NO SPLIT
1215
; CHECK-LABEL: @test1
1316
; CHECK: add <16 x i32>
@@ -153,3 +156,14 @@ define <16 x i16> @test15(<16 x half> %arg) {
153156
ret <16 x i16> %and
154157
}
155158

159+
; NO SPLIT FOR IEEE INTRINSICS
160+
; CHECK-LABEL: @test16
161+
; CHECK: call <16 x float> @llvm.genx.ieee.sqrt.v16f32
162+
; CHECK-NEXT: call <16 x float> @llvm.genx.ieee.div.v16f32
163+
define <16 x i16> @test16(<16 x float> %arg) {
164+
%sqrt = call <16 x float> @llvm.genx.ieee.sqrt.v16f32(<16 x float> %arg)
165+
%div = call <16 x float> @llvm.genx.ieee.div.v16f32(<16 x float> %arg, <16 x float> %sqrt)
166+
%int = fptoui <16 x float> %div to <16 x i16>
167+
%and = and <16 x i16> %int, <i16 1, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>
168+
ret <16 x i16> %and
169+
}

0 commit comments

Comments
 (0)