@@ -2256,17 +2256,24 @@ SDValue NVPTXTargetLowering::LowerEXTRACT_VECTOR_ELT(SDValue Op,
22562256 }
22572257
22582258 if (VectorVT == MVT::v2f32) {
2259+ auto GetOperand = [&DAG, &DL](SDValue Op, SDValue Index) {
2260+ if (const auto *ConstIdx = dyn_cast<ConstantSDNode>(Index))
2261+ return Op.getOperand (ConstIdx->getZExtValue ());
2262+ SDValue E0 = Op.getOperand (0 );
2263+ SDValue E1 = Op.getOperand (1 );
2264+ return DAG.getSelectCC (DL, Index, DAG.getIntPtrConstant (0 , DL), E0 , E1 ,
2265+ ISD::CondCode::SETEQ);
2266+ };
22592267 if (Vector.getOpcode () == ISD::BITCAST) {
22602268 // peek through v2f32 = bitcast (i64 = build_pair (i32 A, i32 B))
22612269 // where A:i32, B:i32 = CopyFromReg (i64 = F32X2 Operation ...)
22622270 SDValue Pair = Vector.getOperand (0 );
22632271 assert (Pair.getOpcode () == ISD::BUILD_PAIR);
2264- return DAG.getNode (
2265- ISD::BITCAST, DL, Op.getValueType (),
2266- Pair.getOperand (cast<ConstantSDNode>(Index)->getZExtValue ()));
2272+ return DAG.getNode (ISD::BITCAST, DL, Op.getValueType (),
2273+ GetOperand (Pair, Index));
22672274 }
22682275 if (Vector.getOpcode () == ISD::BUILD_VECTOR)
2269- return Vector. getOperand (cast<ConstantSDNode>( Index)-> getZExtValue () );
2276+ return GetOperand (Vector, Index);
22702277 }
22712278
22722279 // Constant index will be matched by tablegen.
0 commit comments