@@ -1099,10 +1099,7 @@ class VectorExtractOpConversion
10991099 for (unsigned idx = 0 ; idx < positionVec.size (); ++idx) {
11001100 if (auto position = llvm::dyn_cast<Value>(positionVec[idx])) {
11011101 auto defOp = position.getDefiningOp ();
1102- while (true ) {
1103- if (!defOp) {
1104- break ;
1105- }
1102+ while (defOp) {
11061103 if (llvm::isa<arith::ConstantOp, LLVM::ConstantOp>(defOp)) {
11071104 Attribute value =
11081105 defOp->getAttr (arith::ConstantOp::getAttributeNames ()[0 ]);
@@ -1254,6 +1251,25 @@ class VectorInsertOpConversion
12541251
12551252 SmallVector<OpFoldResult> positionVec = getMixedValues (
12561253 adaptor.getStaticPosition (), adaptor.getDynamicPosition (), rewriter);
1254+ for (unsigned idx = 0 ; idx < positionVec.size (); ++idx) {
1255+ if (auto position = llvm::dyn_cast<Value>(positionVec[idx])) {
1256+ auto defOp = position.getDefiningOp ();
1257+ while (defOp) {
1258+ if (llvm::isa<arith::ConstantOp, LLVM::ConstantOp>(defOp)) {
1259+ Attribute value =
1260+ defOp->getAttr (arith::ConstantOp::getAttributeNames ()[0 ]);
1261+ positionVec[idx] = OpFoldResult{
1262+ rewriter.getI64IntegerAttr (cast<IntegerAttr>(value).getInt ())};
1263+ break ;
1264+ } else if (auto unrealizedCastOp =
1265+ llvm::dyn_cast<UnrealizedConversionCastOp>(defOp)) {
1266+ defOp = unrealizedCastOp.getOperand (0 ).getDefiningOp ();
1267+ } else {
1268+ break ;
1269+ }
1270+ }
1271+ }
1272+ }
12571273
12581274 // Overwrite entire vector with value. Should be handled by folder, but
12591275 // just to be safe.
@@ -1265,8 +1281,9 @@ class VectorInsertOpConversion
12651281
12661282 // One-shot insertion of a vector into an array (only requires insertvalue).
12671283 if (isa<VectorType>(sourceType)) {
1268- if (insertOp. hasDynamicPosition ())
1284+ if (! llvm::all_of (position, llvm::IsaPred<Attribute>)) {
12691285 return failure ();
1286+ }
12701287
12711288 Value inserted = rewriter.create <LLVM::InsertValueOp>(
12721289 loc, adaptor.getDest (), adaptor.getSource (), getAsIntegers (position));
@@ -1278,8 +1295,9 @@ class VectorInsertOpConversion
12781295 Value extracted = adaptor.getDest ();
12791296 auto oneDVectorType = destVectorType;
12801297 if (position.size () > 1 ) {
1281- if (insertOp. hasDynamicPosition ())
1298+ if (! llvm::all_of (position, llvm::IsaPred<Attribute>)) {
12821299 return failure ();
1300+ }
12831301
12841302 oneDVectorType = reducedVectorTypeBack (destVectorType);
12851303 extracted = rewriter.create <LLVM::ExtractValueOp>(
@@ -1293,8 +1311,9 @@ class VectorInsertOpConversion
12931311
12941312 // Potential insertion of resulting 1-D vector into array.
12951313 if (position.size () > 1 ) {
1296- if (insertOp. hasDynamicPosition ())
1314+ if (! llvm::all_of (position, llvm::IsaPred<Attribute>)) {
12971315 return failure ();
1316+ }
12981317
12991318 inserted = rewriter.create <LLVM::InsertValueOp>(
13001319 loc, adaptor.getDest (), inserted,
0 commit comments