From e367039fe516c0ea1623a1f88870b4a6c5adabe7 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sun, 21 Oct 2018 21:07:25 +0000 Subject: [PATCH] foo llvm-svn: 344873 --- llvm/lib/Target/X86/X86ISelLowering.cpp | 12 ++-- llvm/lib/Target/X86/X86MCInstLower.cpp | 24 ++++++-- .../X86/X86ShuffleDecodeConstantPool.cpp | 58 +++++++++---------- .../Target/X86/X86ShuffleDecodeConstantPool.h | 13 +++-- 4 files changed, 62 insertions(+), 45 deletions(-) diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 9e4311620835..26a7c004e1f7 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -6046,7 +6046,7 @@ static bool getTargetShuffleMask(SDNode *N, MVT VT, bool AllowSentinelZero, break; } if (auto *C = getTargetConstantFromNode(MaskNode)) { - DecodeVPERMILPMask(C, MaskEltSize, Mask); + DecodeVPERMILPMask(C, MaskEltSize, VT.getSizeInBits(), Mask); break; } return false; @@ -6063,7 +6063,7 @@ static bool getTargetShuffleMask(SDNode *N, MVT VT, bool AllowSentinelZero, break; } if (auto *C = getTargetConstantFromNode(MaskNode)) { - DecodePSHUFBMask(C, Mask); + DecodePSHUFBMask(C, VT.getSizeInBits(), Mask); break; } return false; @@ -6128,7 +6128,7 @@ static bool getTargetShuffleMask(SDNode *N, MVT VT, bool AllowSentinelZero, break; } if (auto *C = getTargetConstantFromNode(MaskNode)) { - DecodeVPERMIL2PMask(C, CtrlImm, MaskEltSize, Mask); + DecodeVPERMIL2PMask(C, CtrlImm, MaskEltSize, VT.getSizeInBits(), Mask); break; } } @@ -6145,7 +6145,7 @@ static bool getTargetShuffleMask(SDNode *N, MVT VT, bool AllowSentinelZero, break; } if (auto *C = getTargetConstantFromNode(MaskNode)) { - DecodeVPPERMMask(C, Mask); + DecodeVPPERMMask(C, VT.getSizeInBits(), Mask); break; } return false; @@ -6163,7 +6163,7 @@ static bool getTargetShuffleMask(SDNode *N, MVT VT, bool AllowSentinelZero, break; } if (auto *C = getTargetConstantFromNode(MaskNode)) { - DecodeVPERMVMask(C, MaskEltSize, Mask); + DecodeVPERMVMask(C, MaskEltSize, VT.getSizeInBits(), Mask); break; } return false; @@ -6178,7 +6178,7 @@ static bool getTargetShuffleMask(SDNode *N, MVT VT, bool AllowSentinelZero, SDValue MaskNode = N->getOperand(1); unsigned MaskEltSize = VT.getScalarSizeInBits(); if (auto *C = getTargetConstantFromNode(MaskNode)) { - DecodeVPERMV3Mask(C, MaskEltSize, Mask); + DecodeVPERMV3Mask(C, MaskEltSize, VT.getSizeInBits(), Mask); break; } return false; diff --git a/llvm/lib/Target/X86/X86MCInstLower.cpp b/llvm/lib/Target/X86/X86MCInstLower.cpp index 58b1c5059446..9c278116d7e1 100644 --- a/llvm/lib/Target/X86/X86MCInstLower.cpp +++ b/llvm/lib/Target/X86/X86MCInstLower.cpp @@ -1594,6 +1594,18 @@ void X86AsmPrinter::EmitSEHInstruction(const MachineInstr *MI) { } } +static unsigned getRegisterWidth(const MCOperandInfo &Info) { + if (Info.RegClass == X86::VR128RegClassID || + Info.RegClass == X86::VR128XRegClassID) + return 128; + if (Info.RegClass == X86::VR256RegClassID || + Info.RegClass == X86::VR256XRegClassID) + return 256; + if (Info.RegClass == X86::VR512RegClassID) + return 512; + llvm_unreachable("Unknown register class!"); +} + void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) { X86MCInstLower MCInstLowering(*MF, *this); const X86RegisterInfo *RI = @@ -1879,8 +1891,9 @@ void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) { const MachineOperand &MaskOp = MI->getOperand(MaskIdx); if (auto *C = getConstantFromPool(*MI, MaskOp)) { + unsigned Width = getRegisterWidth(MI->getDesc().OpInfo[0]); SmallVector Mask; - DecodePSHUFBMask(C, Mask); + DecodePSHUFBMask(C, Width, Mask); if (!Mask.empty()) OutStreamer->AddComment(getShuffleComment(MI, SrcIdx, SrcIdx, Mask), !EnablePrintSchedInfo); @@ -1951,8 +1964,9 @@ void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) { const MachineOperand &MaskOp = MI->getOperand(MaskIdx); if (auto *C = getConstantFromPool(*MI, MaskOp)) { + unsigned Width = getRegisterWidth(MI->getDesc().OpInfo[0]); SmallVector Mask; - DecodeVPERMILPMask(C, ElSize, Mask); + DecodeVPERMILPMask(C, ElSize, Width, Mask); if (!Mask.empty()) OutStreamer->AddComment(getShuffleComment(MI, SrcIdx, SrcIdx, Mask), !EnablePrintSchedInfo); @@ -1982,8 +1996,9 @@ void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) { const MachineOperand &MaskOp = MI->getOperand(6); if (auto *C = getConstantFromPool(*MI, MaskOp)) { + unsigned Width = getRegisterWidth(MI->getDesc().OpInfo[0]); SmallVector Mask; - DecodeVPERMIL2PMask(C, (unsigned)CtrlOp.getImm(), ElSize, Mask); + DecodeVPERMIL2PMask(C, (unsigned)CtrlOp.getImm(), ElSize, Width, Mask); if (!Mask.empty()) OutStreamer->AddComment(getShuffleComment(MI, 1, 2, Mask), !EnablePrintSchedInfo); @@ -1999,8 +2014,9 @@ void X86AsmPrinter::EmitInstruction(const MachineInstr *MI) { const MachineOperand &MaskOp = MI->getOperand(6); if (auto *C = getConstantFromPool(*MI, MaskOp)) { + unsigned Width = getRegisterWidth(MI->getDesc().OpInfo[0]); SmallVector Mask; - DecodeVPPERMMask(C, Mask); + DecodeVPPERMMask(C, Width, Mask); if (!Mask.empty()) OutStreamer->AddComment(getShuffleComment(MI, 1, 2, Mask), !EnablePrintSchedInfo); diff --git a/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp b/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp index c7ddf93f8e85..720be8afa62c 100644 --- a/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp +++ b/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp @@ -112,11 +112,10 @@ static bool extractConstantMask(const Constant *C, unsigned MaskEltSizeInBits, return true; } -void DecodePSHUFBMask(const Constant *C, SmallVectorImpl &ShuffleMask) { - Type *MaskTy = C->getType(); - unsigned MaskTySize = MaskTy->getPrimitiveSizeInBits(); - (void)MaskTySize; - assert((MaskTySize == 128 || MaskTySize == 256 || MaskTySize == 512) && +void DecodePSHUFBMask(const Constant *C, unsigned Width, + SmallVectorImpl &ShuffleMask) { + assert((Width == 128 || Width == 256 || Width == 512) && + C->getType()->getPrimitiveSizeInBits() >= Width && "Unexpected vector size."); // The shuffle mask requires a byte vector. @@ -125,7 +124,7 @@ void DecodePSHUFBMask(const Constant *C, SmallVectorImpl &ShuffleMask) { if (!extractConstantMask(C, 8, UndefElts, RawMask)) return; - unsigned NumElts = RawMask.size(); + unsigned NumElts = Width / 8; assert((NumElts == 16 || NumElts == 32 || NumElts == 64) && "Unexpected number of vector elements."); @@ -151,12 +150,10 @@ void DecodePSHUFBMask(const Constant *C, SmallVectorImpl &ShuffleMask) { } } -void DecodeVPERMILPMask(const Constant *C, unsigned ElSize, +void DecodeVPERMILPMask(const Constant *C, unsigned ElSize, unsigned Width, SmallVectorImpl &ShuffleMask) { - Type *MaskTy = C->getType(); - unsigned MaskTySize = MaskTy->getPrimitiveSizeInBits(); - (void)MaskTySize; - assert((MaskTySize == 128 || MaskTySize == 256 || MaskTySize == 512) && + assert((Width == 128 || Width == 256 || Width == 512) && + C->getType()->getPrimitiveSizeInBits() >= Width && "Unexpected vector size."); assert((ElSize == 32 || ElSize == 64) && "Unexpected vector element size."); @@ -166,7 +163,7 @@ void DecodeVPERMILPMask(const Constant *C, unsigned ElSize, if (!extractConstantMask(C, ElSize, UndefElts, RawMask)) return; - unsigned NumElts = RawMask.size(); + unsigned NumElts = Width / ElSize; unsigned NumEltsPerLane = 128 / ElSize; assert((NumElts == 2 || NumElts == 4 || NumElts == 8 || NumElts == 16) && "Unexpected number of vector elements."); @@ -189,11 +186,13 @@ void DecodeVPERMILPMask(const Constant *C, unsigned ElSize, } void DecodeVPERMIL2PMask(const Constant *C, unsigned M2Z, unsigned ElSize, + unsigned Width, SmallVectorImpl &ShuffleMask) { Type *MaskTy = C->getType(); unsigned MaskTySize = MaskTy->getPrimitiveSizeInBits(); (void)MaskTySize; - assert((MaskTySize == 128 || MaskTySize == 256) && "Unexpected vector size."); + assert((MaskTySize == 128 || MaskTySize == 256) && + Width >= MaskTySize && "Unexpected vector size."); // The shuffle mask requires elements the same size as the target. APInt UndefElts; @@ -201,7 +200,7 @@ void DecodeVPERMIL2PMask(const Constant *C, unsigned M2Z, unsigned ElSize, if (!extractConstantMask(C, ElSize, UndefElts, RawMask)) return; - unsigned NumElts = RawMask.size(); + unsigned NumElts = Width / ElSize; unsigned NumEltsPerLane = 128 / ElSize; assert((NumElts == 2 || NumElts == 4 || NumElts == 8) && "Unexpected number of vector elements."); @@ -242,9 +241,12 @@ void DecodeVPERMIL2PMask(const Constant *C, unsigned M2Z, unsigned ElSize, } } -void DecodeVPPERMMask(const Constant *C, SmallVectorImpl &ShuffleMask) { - assert(C->getType()->getPrimitiveSizeInBits() == 128 && - "Unexpected vector size."); +void DecodeVPPERMMask(const Constant *C, unsigned Width, + SmallVectorImpl &ShuffleMask) { + Type *MaskTy = C->getType(); + unsigned MaskTySize = MaskTy->getPrimitiveSizeInBits(); + (void)MaskTySize; + assert(Width == 128 && Width >= MaskTySize && "Unexpected vector size."); // The shuffle mask requires a byte vector. APInt UndefElts; @@ -252,7 +254,7 @@ void DecodeVPPERMMask(const Constant *C, SmallVectorImpl &ShuffleMask) { if (!extractConstantMask(C, 8, UndefElts, RawMask)) return; - unsigned NumElts = RawMask.size(); + unsigned NumElts = Width / 8; assert(NumElts == 16 && "Unexpected number of vector elements."); for (unsigned i = 0; i != NumElts; ++i) { @@ -291,12 +293,10 @@ void DecodeVPPERMMask(const Constant *C, SmallVectorImpl &ShuffleMask) { } } -void DecodeVPERMVMask(const Constant *C, unsigned ElSize, +void DecodeVPERMVMask(const Constant *C, unsigned ElSize, unsigned Width, SmallVectorImpl &ShuffleMask) { - Type *MaskTy = C->getType(); - unsigned MaskTySize = MaskTy->getPrimitiveSizeInBits(); - (void)MaskTySize; - assert((MaskTySize == 128 || MaskTySize == 256 || MaskTySize == 512) && + assert((Width == 128 || Width == 256 || Width == 512) && + C->getType()->getPrimitiveSizeInBits() >= Width && "Unexpected vector size."); assert((ElSize == 8 || ElSize == 16 || ElSize == 32 || ElSize == 64) && "Unexpected vector element size."); @@ -307,7 +307,7 @@ void DecodeVPERMVMask(const Constant *C, unsigned ElSize, if (!extractConstantMask(C, ElSize, UndefElts, RawMask)) return; - unsigned NumElts = RawMask.size(); + unsigned NumElts = Width / ElSize; for (unsigned i = 0; i != NumElts; ++i) { if (UndefElts[i]) { @@ -319,12 +319,10 @@ void DecodeVPERMVMask(const Constant *C, unsigned ElSize, } } -void DecodeVPERMV3Mask(const Constant *C, unsigned ElSize, +void DecodeVPERMV3Mask(const Constant *C, unsigned ElSize, unsigned Width, SmallVectorImpl &ShuffleMask) { - Type *MaskTy = C->getType(); - unsigned MaskTySize = MaskTy->getPrimitiveSizeInBits(); - (void)MaskTySize; - assert((MaskTySize == 128 || MaskTySize == 256 || MaskTySize == 512) && + assert((Width == 128 || Width == 256 || Width == 512) && + C->getType()->getPrimitiveSizeInBits() >= Width && "Unexpected vector size."); assert((ElSize == 8 || ElSize == 16 || ElSize == 32 || ElSize == 64) && "Unexpected vector element size."); @@ -335,7 +333,7 @@ void DecodeVPERMV3Mask(const Constant *C, unsigned ElSize, if (!extractConstantMask(C, ElSize, UndefElts, RawMask)) return; - unsigned NumElts = RawMask.size(); + unsigned NumElts = Width / ElSize; for (unsigned i = 0; i != NumElts; ++i) { if (UndefElts[i]) { diff --git a/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.h b/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.h index b703cbbd2b29..b08c31935d28 100644 --- a/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.h +++ b/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.h @@ -26,25 +26,28 @@ class Constant; class MVT; /// Decode a PSHUFB mask from an IR-level vector constant. -void DecodePSHUFBMask(const Constant *C, SmallVectorImpl &ShuffleMask); +void DecodePSHUFBMask(const Constant *C, unsigned Width, + SmallVectorImpl &ShuffleMask); /// Decode a VPERMILP variable mask from an IR-level vector constant. -void DecodeVPERMILPMask(const Constant *C, unsigned ElSize, +void DecodeVPERMILPMask(const Constant *C, unsigned ElSize, unsigned Width, SmallVectorImpl &ShuffleMask); /// Decode a VPERMILP2 variable mask from an IR-level vector constant. void DecodeVPERMIL2PMask(const Constant *C, unsigned MatchImm, unsigned ElSize, + unsigned Width, SmallVectorImpl &ShuffleMask); /// Decode a VPPERM variable mask from an IR-level vector constant. -void DecodeVPPERMMask(const Constant *C, SmallVectorImpl &ShuffleMask); +void DecodeVPPERMMask(const Constant *C, unsigned Width, + SmallVectorImpl &ShuffleMask); /// Decode a VPERM W/D/Q/PS/PD mask from an IR-level vector constant. -void DecodeVPERMVMask(const Constant *C, unsigned ElSize, +void DecodeVPERMVMask(const Constant *C, unsigned ElSize, unsigned Width, SmallVectorImpl &ShuffleMask); /// Decode a VPERMT2 W/D/Q/PS/PD mask from an IR-level vector constant. -void DecodeVPERMV3Mask(const Constant *C, unsigned ElSize, +void DecodeVPERMV3Mask(const Constant *C, unsigned ElSize, unsigned Width, SmallVectorImpl &ShuffleMask); } // llvm namespace