llvm.org GIT mirror llvm / 2ce63c7
Add VSELECT to LegalizeVectorTypes::ScalariseVectorResult. Previously it would crash if it encountered a 1 element VSELECT. Solution is slightly more complicated than just creating a SELET as we have to mask or sign extend the vector condition if it had different boolean contents from the scalar condition. Fixes <rdar://problem/11178095> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153976 91177308-0d34-0410-b5e6-96231b3b80d8 Pete Cooper 8 years ago
3 changed file(s) with 42 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
520520 SDValue ScalarizeVecRes_LOAD(LoadSDNode *N);
521521 SDValue ScalarizeVecRes_SCALAR_TO_VECTOR(SDNode *N);
522522 SDValue ScalarizeVecRes_SIGN_EXTEND_INREG(SDNode *N);
523 SDValue ScalarizeVecRes_VSELECT(SDNode *N);
523524 SDValue ScalarizeVecRes_SELECT(SDNode *N);
524525 SDValue ScalarizeVecRes_SELECT_CC(SDNode *N);
525526 SDValue ScalarizeVecRes_SETCC(SDNode *N);
5757 case ISD::LOAD: R = ScalarizeVecRes_LOAD(cast(N));break;
5858 case ISD::SCALAR_TO_VECTOR: R = ScalarizeVecRes_SCALAR_TO_VECTOR(N); break;
5959 case ISD::SIGN_EXTEND_INREG: R = ScalarizeVecRes_InregOp(N); break;
60 case ISD::VSELECT: R = ScalarizeVecRes_VSELECT(N); break;
6061 case ISD::SELECT: R = ScalarizeVecRes_SELECT(N); break;
6162 case ISD::SELECT_CC: R = ScalarizeVecRes_SELECT_CC(N); break;
6263 case ISD::SETCC: R = ScalarizeVecRes_SETCC(N); break;
223224 if (InOp.getValueType() != EltVT)
224225 return DAG.getNode(ISD::TRUNCATE, N->getDebugLoc(), EltVT, InOp);
225226 return InOp;
227 }
228
229 SDValue DAGTypeLegalizer::ScalarizeVecRes_VSELECT(SDNode *N) {
230 SDValue Cond = GetScalarizedVector(N->getOperand(0));
231 SDValue LHS = GetScalarizedVector(N->getOperand(1));
232 TargetLowering::BooleanContent ScalarBool = TLI.getBooleanContents(false);
233 TargetLowering::BooleanContent VecBool = TLI.getBooleanContents(true);
234 if (ScalarBool != VecBool) {
235 EVT CondVT = Cond.getValueType();
236 switch (ScalarBool) {
237 default: llvm_unreachable("Unknown boolean content enum");
238 case TargetLowering::UndefinedBooleanContent:
239 break;
240 case TargetLowering::ZeroOrOneBooleanContent:
241 assert(VecBool == TargetLowering::UndefinedBooleanContent ||
242 VecBool == TargetLowering::ZeroOrNegativeOneBooleanContent);
243 // Vector read from all ones, scalar expects a single 1 so mask.
244 Cond = DAG.getNode(ISD::AND, N->getDebugLoc(), CondVT,
245 Cond, DAG.getConstant(1, CondVT));
246 break;
247 case TargetLowering::ZeroOrNegativeOneBooleanContent:
248 assert(VecBool == TargetLowering::UndefinedBooleanContent ||
249 VecBool == TargetLowering::ZeroOrOneBooleanContent);
250 // Vector reads from a one, scalar from all ones so sign extend.
251 Cond = DAG.getNode(ISD::SIGN_EXTEND_INREG, N->getDebugLoc(), CondVT,
252 Cond, DAG.getValueType(MVT::i1));
253 break;
254 }
255 }
256 return DAG.getNode(ISD::SELECT, N->getDebugLoc(),
257 LHS.getValueType(), Cond, LHS,
258 GetScalarizedVector(N->getOperand(2)));
226259 }
227260
228261 SDValue DAGTypeLegalizer::ScalarizeVecRes_SELECT(SDNode *N) {
184184 ret i32 %reg820
185185 }
186186
187 ; Test case for scalarising a 1 element vselect
188 ;
189 define <1 x i32> @checkScalariseVSELECT(<1 x i32> %a, <1 x i32> %b) {
190 %cond = icmp uge <1 x i32> %a, %b
191 %s = select <1 x i1> %cond, <1 x i32> %a, <1 x i32> %b
192 ret <1 x i32> %s
193 }
194