@@ -683,6 +683,30 @@ RValue CIRGenFunction::emitLoadOfExtVectorElementLValue(LValue lv) {
683683 return RValue::get (resultVec);
684684}
685685
686+ // / Generates lvalue for partial ext_vector access.
687+ Address CIRGenFunction::emitExtVectorElementLValue (LValue lv,
688+ mlir::Location loc) {
689+ Address vectorAddress = lv.getExtVectorAddress ();
690+ QualType elementTy = lv.getType ()->castAs <VectorType>()->getElementType ();
691+ mlir::Type vectorElementTy = cgm.getTypes ().convertType (elementTy);
692+ Address castToPointerElement =
693+ vectorAddress.withElementType (builder, vectorElementTy);
694+
695+ mlir::ArrayAttr extVecElts = lv.getExtVectorElts ();
696+ unsigned idx = getAccessedFieldNo (0 , extVecElts);
697+ mlir::Value idxValue =
698+ builder.getConstInt (loc, mlir::cast<cir::IntType>(ptrDiffTy), idx);
699+
700+ mlir::Value elementValue = builder.getArrayElement (
701+ loc, loc, castToPointerElement.getPointer (), vectorElementTy, idxValue,
702+ /* shouldDecay=*/ false );
703+
704+ const CharUnits eltSize = getContext ().getTypeSizeInChars (elementTy);
705+ const CharUnits alignment =
706+ castToPointerElement.getAlignment ().alignmentAtOffset (idx * eltSize);
707+ return Address (elementValue, vectorElementTy, alignment);
708+ }
709+
686710static cir::FuncOp emitFunctionDeclPointer (CIRGenModule &cgm, GlobalDecl gd) {
687711 assert (!cir::MissingFeatures::weakRefReference ());
688712 return cgm.getAddrOfFunction (gd);
@@ -1081,12 +1105,6 @@ static Address emitArraySubscriptPtr(CIRGenFunction &cgf,
10811105
10821106LValue
10831107CIRGenFunction::emitArraySubscriptExpr (const clang::ArraySubscriptExpr *e) {
1084- if (isa<ExtVectorElementExpr>(e->getBase ())) {
1085- cgm.errorNYI (e->getSourceRange (),
1086- " emitArraySubscriptExpr: ExtVectorElementExpr" );
1087- return LValue::makeAddr (Address::invalid (), e->getType (), LValueBaseInfo ());
1088- }
1089-
10901108 if (getContext ().getAsVariableArrayType (e->getType ())) {
10911109 cgm.errorNYI (e->getSourceRange (),
10921110 " emitArraySubscriptExpr: VariableArrayType" );
@@ -1116,15 +1134,30 @@ CIRGenFunction::emitArraySubscriptExpr(const clang::ArraySubscriptExpr *e) {
11161134
11171135 // If the base is a vector type, then we are forming a vector element
11181136 // with this subscript.
1119- if (e->getBase ()->getType ()->isVectorType () &&
1137+ if (e->getBase ()->getType ()->isSubscriptableVectorType () &&
11201138 !isa<ExtVectorElementExpr>(e->getBase ())) {
11211139 const mlir::Value idx = emitIdxAfterBase (/* promote=*/ false );
1122- const LValue lhs = emitLValue (e->getBase ());
1123- return LValue::makeVectorElt (lhs .getAddress (), idx, e->getBase ()->getType (),
1124- lhs .getBaseInfo ());
1140+ const LValue lv = emitLValue (e->getBase ());
1141+ return LValue::makeVectorElt (lv .getAddress (), idx, e->getBase ()->getType (),
1142+ lv .getBaseInfo ());
11251143 }
11261144
11271145 const mlir::Value idx = emitIdxAfterBase (/* promote=*/ true );
1146+
1147+ // Handle the extvector case we ignored above.
1148+ if (isa<ExtVectorElementExpr>(e->getBase ())) {
1149+ const LValue lv = emitLValue (e->getBase ());
1150+ Address addr = emitExtVectorElementLValue (lv, cgm.getLoc (e->getExprLoc ()));
1151+
1152+ QualType elementType = lv.getType ()->castAs <VectorType>()->getElementType ();
1153+ addr = emitArraySubscriptPtr (*this , cgm.getLoc (e->getBeginLoc ()),
1154+ cgm.getLoc (e->getEndLoc ()), addr, e->getType (),
1155+ idx, cgm.getLoc (e->getExprLoc ()),
1156+ /* shouldDecay=*/ false );
1157+
1158+ return makeAddrLValue (addr, elementType, lv.getBaseInfo ());
1159+ }
1160+
11281161 if (const Expr *array = getSimpleArrayDecayOperand (e->getBase ())) {
11291162 LValue arrayLV;
11301163 if (const auto *ase = dyn_cast<ArraySubscriptExpr>(array))
0 commit comments