From 556cad18dba3a3b7ed84195e3597423b3fd17080 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 26 Oct 2018 20:59:55 +0000 Subject: [PATCH] [LegalizeTypes] Stop DAGTypeLegalizer::getSETCCWidenedResultTy from creating illegal setccs. Add checks for valid setccs The DAGTypeLegalizer::getSETCCWidenedResultTy was widening the MaskVT, but the code in convertMask called after getSETCCWidenedResultTy had no idea this widening had occurred. So none of the operands were widened when convertMask created new setccs with the widened VT. This patch removes the widening and adds some asserts to getNode to validate the types of setccs to prevent issues like this in the future. Differential Revision: https://reviews.llvm.org/D53743 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345428 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/LegalizeTypes.h | 3 --- lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp | 16 +++------------- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 8 ++++++++ 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/LegalizeTypes.h b/lib/CodeGen/SelectionDAG/LegalizeTypes.h index f31b115bc2d..605c63c72d4 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeTypes.h +++ b/lib/CodeGen/SelectionDAG/LegalizeTypes.h @@ -849,9 +849,6 @@ private: /// MaskVT to ToMaskVT if needed with vector extension or truncation. SDValue convertMask(SDValue InMask, EVT MaskVT, EVT ToMaskVT); - /// Get the target mask VT, and widen if needed. - EVT getSETCCWidenedResultTy(SDValue SetCC); - //===--------------------------------------------------------------------===// // Generic Splitting: LegalizeTypesGeneric.cpp //===--------------------------------------------------------------------===// diff --git a/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp b/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp index 58446101556..1027f31d084 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp @@ -3373,16 +3373,6 @@ SDValue DAGTypeLegalizer::convertMask(SDValue InMask, EVT MaskVT, return Mask; } -// Get the target mask VT, and widen if needed. -EVT DAGTypeLegalizer::getSETCCWidenedResultTy(SDValue SetCC) { - assert(SetCC->getOpcode() == ISD::SETCC); - LLVMContext &Ctx = *DAG.getContext(); - EVT MaskVT = getSetCCResultType(SetCC->getOperand(0).getValueType()); - if (getTypeAction(MaskVT) == TargetLowering::TypeWidenVector) - MaskVT = TLI.getTypeToTransformTo(Ctx, MaskVT); - return MaskVT; -} - // This method tries to handle VSELECT and its mask by legalizing operands // (which may require widening) and if needed adjusting the mask vector type // to match that of the VSELECT. Without it, many cases end up with @@ -3450,7 +3440,7 @@ SDValue DAGTypeLegalizer::WidenVSELECTAndMask(SDNode *N) { SDValue Mask; if (Cond->getOpcode() == ISD::SETCC) { - EVT MaskVT = getSETCCWidenedResultTy(Cond); + EVT MaskVT = getSetCCResultType(Cond.getOperand(0).getValueType()); Mask = convertMask(Cond, MaskVT, ToMaskVT); } else if (isLogicalMaskOp(Cond->getOpcode()) && Cond->getOperand(0).getOpcode() == ISD::SETCC && @@ -3458,8 +3448,8 @@ SDValue DAGTypeLegalizer::WidenVSELECTAndMask(SDNode *N) { // Cond is (AND/OR/XOR (SETCC, SETCC)) SDValue SETCC0 = Cond->getOperand(0); SDValue SETCC1 = Cond->getOperand(1); - EVT VT0 = getSETCCWidenedResultTy(SETCC0); - EVT VT1 = getSETCCWidenedResultTy(SETCC1); + EVT VT0 = getSetCCResultType(SETCC0.getOperand(0).getValueType()); + EVT VT1 = getSetCCResultType(SETCC1.getOperand(0).getValueType()); unsigned ScalarBits0 = VT0.getScalarSizeInBits(); unsigned ScalarBits1 = VT1.getScalarSizeInBits(); unsigned ScalarBits_ToMask = ToMaskVT.getScalarSizeInBits(); diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 2d99a6aecb5..23abbf10f53 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -5027,6 +5027,14 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT, break; } case ISD::SETCC: { + assert(VT.isInteger() && "SETCC result type must be an integer!"); + assert(N1.getValueType() == N2.getValueType() && + "SETCC operands must have the same type!"); + assert(VT.isVector() == N1.getValueType().isVector() && + "SETCC type should be vector iff the operand type is vector!"); + assert((!VT.isVector() || + VT.getVectorNumElements() == N1.getValueType().getVectorNumElements()) && + "SETCC vector element counts must match!"); // Use FoldSetCC to simplify SETCC's. if (SDValue V = FoldSetCC(VT, N1, N2, cast(N3)->get(), DL)) return V; -- 2.11.0