Index: lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp =================================================================== --- lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -2902,6 +2902,11 @@ case ISD::EXTRACT_ELEMENT: Res = ExpandOp_EXTRACT_ELEMENT(N); break; case ISD::INSERT_VECTOR_ELT: Res = ExpandOp_INSERT_VECTOR_ELT(N); break; case ISD::SCALAR_TO_VECTOR: Res = ExpandOp_SCALAR_TO_VECTOR(N); break; + case ISD::SELECT: + // We expect only condition argument to be expanded + assert(OpNo == 0); + Res = ExpandIntOp_SELECT(N); + break; case ISD::SELECT_CC: Res = ExpandIntOp_SELECT_CC(N); break; case ISD::SETCC: Res = ExpandIntOp_SETCC(N); break; case ISD::SETCCE: Res = ExpandIntOp_SETCCE(N); break; @@ -3106,6 +3111,13 @@ N->getOperand(4)), 0); } +SDValue DAGTypeLegalizer::ExpandIntOp_SELECT(SDNode *N) { + SDValue InL, InH; + GetExpandedInteger(N->getOperand(0), InL, InH); + return DAG.getNode(ISD::SELECT, SDLoc(N), N->getValueType(0), InL, + N->getOperand(1), N->getOperand(2)); +} + SDValue DAGTypeLegalizer::ExpandIntOp_SELECT_CC(SDNode *N) { SDValue NewLHS = N->getOperand(0), NewRHS = N->getOperand(1); ISD::CondCode CCCode = cast(N->getOperand(4))->get(); Index: lib/CodeGen/SelectionDAG/LegalizeTypes.h =================================================================== --- lib/CodeGen/SelectionDAG/LegalizeTypes.h +++ lib/CodeGen/SelectionDAG/LegalizeTypes.h @@ -375,6 +375,7 @@ // Integer Operand Expansion. bool ExpandIntegerOperand(SDNode *N, unsigned OperandNo); SDValue ExpandIntOp_BR_CC(SDNode *N); + SDValue ExpandIntOp_SELECT(SDNode *N); SDValue ExpandIntOp_SELECT_CC(SDNode *N); SDValue ExpandIntOp_SETCC(SDNode *N); SDValue ExpandIntOp_SETCCE(SDNode *N); Index: test/CodeGen/AArch64/expand-select.ll =================================================================== --- test/CodeGen/AArch64/expand-select.ll +++ test/CodeGen/AArch64/expand-select.ll @@ -0,0 +1,13 @@ +; REQUIRES: asserts + +; Check that we don't crash +; RUN: llc -mtriple=aarch64-unknown-linux-gnu -O3 %s -debug-only=selectiondag,legalize-types -o - + +define void @foo(i32 %In1, <2 x i128> %In2, <2 x i128> %In3, <2 x i128> *%Out) { + %cond = and i32 %In1, 1 + %cbool = icmp eq i32 %cond, 0 + %res = select i1 %cbool, <2 x i128> %In2, <2 x i128> %In3 + store <2 x i128> %res, <2 x i128> *%Out + + ret void +}