Skip to content

Commit 0bced10

Browse files
authored
[SDAG][X86] Extend SplitVecOp_VSETCC for STRICT_FSETCC. (#92509)
1 parent d102ee6 commit 0bced10

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,6 +3033,7 @@ bool DAGTypeLegalizer::SplitVectorOperand(SDNode *N, unsigned OpNo) {
30333033
"operand!\n");
30343034

30353035
case ISD::VP_SETCC:
3036+
case ISD::STRICT_FSETCC:
30363037
case ISD::SETCC: Res = SplitVecOp_VSETCC(N); break;
30373038
case ISD::BITCAST: Res = SplitVecOp_BITCAST(N); break;
30383039
case ISD::EXTRACT_SUBVECTOR: Res = SplitVecOp_EXTRACT_SUBVECTOR(N); break;
@@ -3997,14 +3998,16 @@ SDValue DAGTypeLegalizer::SplitVecOp_TruncateHelper(SDNode *N) {
39973998
}
39983999

39994000
SDValue DAGTypeLegalizer::SplitVecOp_VSETCC(SDNode *N) {
4001+
bool isStrict = N->getOpcode() == ISD::STRICT_FSETCC;
40004002
assert(N->getValueType(0).isVector() &&
4001-
N->getOperand(0).getValueType().isVector() &&
4003+
N->getOperand(isStrict ? 1 : 0).getValueType().isVector() &&
40024004
"Operand types must be vectors");
40034005
// The result has a legal vector type, but the input needs splitting.
40044006
SDValue Lo0, Hi0, Lo1, Hi1, LoRes, HiRes;
40054007
SDLoc DL(N);
4006-
GetSplitVector(N->getOperand(0), Lo0, Hi0);
4007-
GetSplitVector(N->getOperand(1), Lo1, Hi1);
4008+
GetSplitVector(N->getOperand(isStrict ? 1 : 0), Lo0, Hi0);
4009+
GetSplitVector(N->getOperand(isStrict ? 2 : 1), Lo1, Hi1);
4010+
40084011
auto PartEltCnt = Lo0.getValueType().getVectorElementCount();
40094012

40104013
LLVMContext &Context = *DAG.getContext();
@@ -4014,6 +4017,16 @@ SDValue DAGTypeLegalizer::SplitVecOp_VSETCC(SDNode *N) {
40144017
if (N->getOpcode() == ISD::SETCC) {
40154018
LoRes = DAG.getNode(ISD::SETCC, DL, PartResVT, Lo0, Lo1, N->getOperand(2));
40164019
HiRes = DAG.getNode(ISD::SETCC, DL, PartResVT, Hi0, Hi1, N->getOperand(2));
4020+
} else if (N->getOpcode() == ISD::STRICT_FSETCC) {
4021+
LoRes = DAG.getNode(ISD::STRICT_FSETCC, DL,
4022+
DAG.getVTList(PartResVT, N->getValueType(1)),
4023+
N->getOperand(0), Lo0, Lo1, N->getOperand(3));
4024+
HiRes = DAG.getNode(ISD::STRICT_FSETCC, DL,
4025+
DAG.getVTList(PartResVT, N->getValueType(1)),
4026+
N->getOperand(0), Hi0, Hi1, N->getOperand(3));
4027+
SDValue NewChain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other,
4028+
LoRes.getValue(1), HiRes.getValue(1));
4029+
ReplaceValueWith(SDValue(N, 1), NewChain);
40174030
} else {
40184031
assert(N->getOpcode() == ISD::VP_SETCC && "Expected VP_SETCC opcode");
40194032
SDValue MaskLo, MaskHi, EVLLo, EVLHi;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mtriple=x86_64 -mcpu=skx | FileCheck %s --check-prefixes=SKX
3+
4+
;; Test no crash for AVX512 targets without prefer-vector-width=512.
5+
6+
define <16 x i32> @test_v16f32_oeq_q(<16 x i32> %a, <16 x i32> %b, <16 x float> %f1, <16 x float> %f2) #0 {
7+
; SKX-LABEL: test_v16f32_oeq_q:
8+
; SKX: # %bb.0:
9+
; SKX-NEXT: vcmpeqps %ymm7, %ymm5, %k1
10+
; SKX-NEXT: vcmpeqps %ymm6, %ymm4, %k2
11+
; SKX-NEXT: vpblendmd %ymm0, %ymm2, %ymm0 {%k2}
12+
; SKX-NEXT: vpblendmd %ymm1, %ymm3, %ymm1 {%k1}
13+
; SKX-NEXT: retq
14+
%cond = call <16 x i1> @llvm.experimental.constrained.fcmp.v16f32(
15+
<16 x float> %f1, <16 x float> %f2, metadata !"oeq",
16+
metadata !"fpexcept.strict") #0
17+
%res = select <16 x i1> %cond, <16 x i32> %a, <16 x i32> %b
18+
ret <16 x i32> %res
19+
}
20+
21+
define <8 x i32> @test_v8f64_oeq_q(<8 x i32> %a, <8 x i32> %b, <8 x double> %f1, <8 x double> %f2) #0 {
22+
; SKX-LABEL: test_v8f64_oeq_q:
23+
; SKX: # %bb.0:
24+
; SKX-NEXT: vcmpeqpd %ymm4, %ymm2, %k0
25+
; SKX-NEXT: vcmpeqpd %ymm5, %ymm3, %k1
26+
; SKX-NEXT: kshiftlb $4, %k1, %k1
27+
; SKX-NEXT: korb %k1, %k0, %k1
28+
; SKX-NEXT: vpblendmd %ymm0, %ymm1, %ymm0 {%k1}
29+
; SKX-NEXT: retq
30+
%cond = call <8 x i1> @llvm.experimental.constrained.fcmp.v8f64(
31+
<8 x double> %f1, <8 x double> %f2, metadata !"oeq",
32+
metadata !"fpexcept.strict") #0
33+
%res = select <8 x i1> %cond, <8 x i32> %a, <8 x i32> %b
34+
ret <8 x i32> %res
35+
}
36+
37+
declare <16 x i1> @llvm.experimental.constrained.fcmp.v16f32(<16 x float>, <16 x float>, metadata, metadata)
38+
declare <8 x i1> @llvm.experimental.constrained.fcmp.v8f64(<8 x double>, <8 x double>, metadata, metadata)
39+
40+
attributes #0 = { nounwind strictfp "min-legal-vector-width"="0" }

0 commit comments

Comments
 (0)