llvm.org GIT mirror llvm / 7f128ea
Teach the legalizer how to handle operands for VSELECT nodes If we need to split the operand of a VSELECT, it must be the mask operand. We split the entire VSELECT operand with EXTRACT_SUBVECTOR. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168883 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Holewinski 7 years ago
3 changed file(s) with 76 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
577577
578578 // Vector Operand Splitting: <128 x ty> -> 2 x <64 x ty>.
579579 bool SplitVectorOperand(SDNode *N, unsigned OpNo);
580 SDValue SplitVecOp_VSELECT(SDNode *N, unsigned OpNo);
580581 SDValue SplitVecOp_UnaryOp(SDNode *N);
581582
582583 SDValue SplitVecOp_BITCAST(SDNode *N);
10291029 case ISD::STORE:
10301030 Res = SplitVecOp_STORE(cast(N), OpNo);
10311031 break;
1032
1032 case ISD::VSELECT:
1033 Res = SplitVecOp_VSELECT(N, OpNo);
1034 break;
10331035 case ISD::CTTZ:
10341036 case ISD::CTLZ:
10351037 case ISD::CTPOP:
10611063
10621064 ReplaceValueWith(SDValue(N, 0), Res);
10631065 return false;
1066 }
1067
1068 SDValue DAGTypeLegalizer::SplitVecOp_VSELECT(SDNode *N, unsigned OpNo) {
1069 // The only possibility for an illegal operand is the mask, since result type
1070 // legalization would have handled this node already otherwise.
1071 assert(OpNo == 0 && "Illegal operand must be mask");
1072
1073 SDValue Mask = N->getOperand(0);
1074 SDValue Src0 = N->getOperand(1);
1075 SDValue Src1 = N->getOperand(2);
1076 DebugLoc DL = N->getDebugLoc();
1077 EVT MaskVT = Mask.getValueType();
1078 assert(MaskVT.isVector() && "VSELECT without a vector mask?");
1079
1080 SDValue Lo, Hi;
1081 GetSplitVector(N->getOperand(0), Lo, Hi);
1082
1083 unsigned LoNumElts = Lo.getValueType().getVectorNumElements();
1084 unsigned HiNumElts = Hi.getValueType().getVectorNumElements();
1085 assert(LoNumElts == HiNumElts && "Asymmetric vector split?");
1086
1087 EVT LoOpVT = EVT::getVectorVT(*DAG.getContext(),
1088 Src0.getValueType().getVectorElementType(),
1089 LoNumElts);
1090 EVT LoMaskVT = EVT::getVectorVT(*DAG.getContext(),
1091 MaskVT.getVectorElementType(),
1092 LoNumElts);
1093 EVT HiOpVT = EVT::getVectorVT(*DAG.getContext(),
1094 Src0.getValueType().getVectorElementType(),
1095 HiNumElts);
1096 EVT HiMaskVT = EVT::getVectorVT(*DAG.getContext(),
1097 MaskVT.getVectorElementType(),
1098 HiNumElts);
1099
1100 SDValue LoOp0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, LoOpVT, Src0,
1101 DAG.getIntPtrConstant(0));
1102 SDValue LoOp1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, LoOpVT, Src1,
1103 DAG.getIntPtrConstant(0));
1104
1105 SDValue HiOp0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, HiOpVT, Src0,
1106 DAG.getIntPtrConstant(LoNumElts));
1107 SDValue HiOp1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, HiOpVT, Src1,
1108 DAG.getIntPtrConstant(LoNumElts));
1109
1110 SDValue LoMask = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, LoMaskVT, Mask,
1111 DAG.getIntPtrConstant(0));
1112 SDValue HiMask = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, HiMaskVT, Mask,
1113 DAG.getIntPtrConstant(LoNumElts));
1114
1115 SDValue LoSelect = DAG.getNode(ISD::VSELECT, DL, LoOpVT, LoMask, LoOp0,
1116 LoOp1);
1117 SDValue HiSelect = DAG.getNode(ISD::VSELECT, DL, HiOpVT, HiMask, HiOp0,
1118 HiOp1);
1119
1120 return DAG.getNode(ISD::CONCAT_VECTORS, DL, Src0.getValueType(), LoSelect,
1121 HiSelect);
10641122 }
10651123
10661124 SDValue DAGTypeLegalizer::SplitVecOp_UnaryOp(SDNode *N) {
0 ; RUN: llc < %s -march=nvptx -mcpu=sm_20
1 ; RUN: llc < %s -march=nvptx64 -mcpu=sm_20
2
3 ; This test makes sure that vector selects are scalarized by the type legalizer.
4 ; If not, type legalization will fail.
5
6 define void @foo(<2 x i32> addrspace(1)* %def_a, <2 x i32> addrspace(1)* %def_b, <2 x i32> addrspace(1)* %def_c) {
7 entry:
8 %tmp4 = load <2 x i32> addrspace(1)* %def_a
9 %tmp6 = load <2 x i32> addrspace(1)* %def_c
10 %tmp8 = load <2 x i32> addrspace(1)* %def_b
11 %0 = icmp sge <2 x i32> %tmp4, zeroinitializer
12 %cond = select <2 x i1> %0, <2 x i32> %tmp6, <2 x i32> %tmp8
13 store <2 x i32> %cond, <2 x i32> addrspace(1)* %def_c
14 ret void
15 }