File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed
lib/Dialect/Vector/Transforms Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -596,12 +596,11 @@ struct BubbleDownVectorBitCastForExtract
596
596
unsigned expandRatio =
597
597
castDstType.getNumElements () / castSrcType.getNumElements ();
598
598
599
- auto getFirstIntValue = [](ArrayRef<OpFoldResult> values) -> uint64_t {
600
- assert (values[0 ].is <Attribute>() && " Unexpected non-constant index" );
601
- return cast<IntegerAttr>(values[0 ].get <Attribute>()).getInt ();
602
- };
603
-
604
- uint64_t index = getFirstIntValue (extractOp.getMixedPosition ());
599
+ // Get the first element of the mixed position as integer.
600
+ auto mixedPos = extractOp.getMixedPosition ();
601
+ if (mixedPos.size () > 0 && !mixedPos[0 ].is <Attribute>())
602
+ return failure ();
603
+ uint64_t index = cast<IntegerAttr>(mixedPos[0 ].get <Attribute>()).getInt ();
605
604
606
605
// Get the single scalar (as a vector) in the source value that packs the
607
606
// desired scalar. E.g. extract vector<1xf32> from vector<4xf32>
Original file line number Diff line number Diff line change @@ -433,3 +433,16 @@ func.func @vec_0D(%arg0: vector<f32>) -> vector<i32> {
433
433
%0 = vector.bitcast %arg0 : vector <f32 > to vector <i32 >
434
434
return %0 : vector <i32 >
435
435
}
436
+
437
+ // Make sure not crash on dynamic index `vector.extract`:
438
+ func.func @vector_extract_dynamic_index (%arg0 : vector <4 xi32 >, %index : index ) -> i16 {
439
+ %0 = vector.bitcast %arg0 : vector <4 xi32 > to vector <8 xi16 >
440
+ %1 = vector.extract %0 [%index ] : i16 from vector <8 xi16 >
441
+ return %1 : i16
442
+ }
443
+
444
+ // CHECK-LABEL: func.func @vector_extract_dynamic_index
445
+ // CHECK-SAME: (%[[VEC:.+]]: vector<4xi32>, %[[IDX:.+]]: index) -> i16 {
446
+ // CHECK: %[[BC:.+]] = vector.bitcast %[[VEC]] : vector<4xi32> to vector<8xi16>
447
+ // CHECK: %[[EXTRACT:.+]] = vector.extract %[[BC]][%[[IDX]]] : i16 from vector<8xi16>
448
+ // CHECK: return %[[EXTRACT]]
You can’t perform that action at this time.
0 commit comments