Skip to content

Commit 93e1f73

Browse files
committed
[X86] Break non-power of 2 vXi1 vectors into scalars for argument passing with avx512.
This generates worse code, but matches what is done for avx2 and prevents crashes when more arguments are passed than we have registers for. llvm-svn: 372200
1 parent 11082d5 commit 93e1f73

File tree

4 files changed

+2030
-539
lines changed

4 files changed

+2030
-539
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,14 +1996,16 @@ X86TargetLowering::getPreferredVectorAction(MVT VT) const {
19961996
MVT X86TargetLowering::getRegisterTypeForCallingConv(LLVMContext &Context,
19971997
CallingConv::ID CC,
19981998
EVT VT) const {
1999-
// Break wide vXi1 vectors into scalars to match avx2 behavior.
1999+
// v32i1 vectors should be promoted to v32i8 to match avx2.
2000+
if (VT == MVT::v32i1 && Subtarget.hasAVX512() && !Subtarget.hasBWI())
2001+
return MVT::v32i8;
2002+
// Break wide or odd vXi1 vectors into scalars to match avx2 behavior.
20002003
if (VT.isVector() && VT.getVectorElementType() == MVT::i1 &&
20012004
Subtarget.hasAVX512() &&
2002-
((VT.getVectorNumElements() > 32 && !Subtarget.hasBWI()) ||
2005+
(!isPowerOf2_32(VT.getVectorNumElements()) ||
2006+
(VT.getVectorNumElements() > 16 && !Subtarget.hasBWI()) ||
20032007
(VT.getVectorNumElements() > 64 && Subtarget.hasBWI())))
20042008
return MVT::i8;
2005-
if (VT == MVT::v32i1 && Subtarget.hasAVX512() && !Subtarget.hasBWI())
2006-
return MVT::v32i8;
20072009
// FIXME: Should we just make these types legal and custom split operations?
20082010
if ((VT == MVT::v32i16 || VT == MVT::v64i8) &&
20092011
Subtarget.hasAVX512() && !Subtarget.hasBWI() && !EnableOldKNLABI)
@@ -2014,14 +2016,16 @@ MVT X86TargetLowering::getRegisterTypeForCallingConv(LLVMContext &Context,
20142016
unsigned X86TargetLowering::getNumRegistersForCallingConv(LLVMContext &Context,
20152017
CallingConv::ID CC,
20162018
EVT VT) const {
2017-
// Break wide vXi1 vectors into scalars to match avx2 behavior.
2019+
// v32i1 vectors should be promoted to v32i8 to match avx2.
2020+
if (VT == MVT::v32i1 && Subtarget.hasAVX512() && !Subtarget.hasBWI())
2021+
return 1;
2022+
// Break wide or odd vXi1 vectors into scalars to match avx2 behavior.
20182023
if (VT.isVector() && VT.getVectorElementType() == MVT::i1 &&
20192024
Subtarget.hasAVX512() &&
2020-
((VT.getVectorNumElements() > 32 && !Subtarget.hasBWI()) ||
2025+
(!isPowerOf2_32(VT.getVectorNumElements()) ||
2026+
(VT.getVectorNumElements() > 16 && !Subtarget.hasBWI()) ||
20212027
(VT.getVectorNumElements() > 64 && Subtarget.hasBWI())))
20222028
return VT.getVectorNumElements();
2023-
if (VT == MVT::v32i1 && Subtarget.hasAVX512() && !Subtarget.hasBWI())
2024-
return 1;
20252029
// FIXME: Should we just make these types legal and custom split operations?
20262030
if ((VT == MVT::v32i16 || VT == MVT::v64i8) &&
20272031
Subtarget.hasAVX512() && !Subtarget.hasBWI() && !EnableOldKNLABI)
@@ -2032,10 +2036,11 @@ unsigned X86TargetLowering::getNumRegistersForCallingConv(LLVMContext &Context,
20322036
unsigned X86TargetLowering::getVectorTypeBreakdownForCallingConv(
20332037
LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT,
20342038
unsigned &NumIntermediates, MVT &RegisterVT) const {
2035-
// Break wide vXi1 vectors into scalars to match avx2 behavior.
2039+
// Break wide or odd vXi1 vectors into scalars to match avx2 behavior.
20362040
if (VT.isVector() && VT.getVectorElementType() == MVT::i1 &&
20372041
Subtarget.hasAVX512() &&
2038-
((VT.getVectorNumElements() > 32 && !Subtarget.hasBWI()) ||
2042+
(!isPowerOf2_32(VT.getVectorNumElements()) ||
2043+
(VT.getVectorNumElements() > 16 && !Subtarget.hasBWI()) ||
20392044
(VT.getVectorNumElements() > 64 && Subtarget.hasBWI()))) {
20402045
RegisterVT = MVT::i8;
20412046
IntermediateVT = MVT::i1;

0 commit comments

Comments
 (0)