Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,11 @@ struct BubbleDownVectorBitCastForExtract
unsigned expandRatio =
castDstType.getNumElements() / castSrcType.getNumElements();

auto getFirstIntValue = [](ArrayRef<OpFoldResult> values) -> uint64_t {
assert(values[0].is<Attribute>() && "Unexpected non-constant index");
return cast<IntegerAttr>(values[0].get<Attribute>()).getInt();
};

uint64_t index = getFirstIntValue(extractOp.getMixedPosition());
// Get the first element of the mixed position as integer.
auto mixedPos = extractOp.getMixedPosition();
if (mixedPos.size() > 0 && !mixedPos[0].is<Attribute>())
return failure();
uint64_t index = cast<IntegerAttr>(mixedPos[0].get<Attribute>()).getInt();

// Get the single scalar (as a vector) in the source value that packs the
// desired scalar. E.g. extract vector<1xf32> from vector<4xf32>
Expand Down
13 changes: 13 additions & 0 deletions mlir/test/Dialect/Vector/vector-transforms.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,16 @@ func.func @vec_0D(%arg0: vector<f32>) -> vector<i32> {
%0 = vector.bitcast %arg0 : vector<f32> to vector<i32>
return %0 : vector<i32>
}

// Make sure not crash on dynamic index `vector.extract`:
func.func @vector_extract_dynamic_index(%arg0 : vector<4xi32>, %index : index) -> i16 {
%0 = vector.bitcast %arg0 : vector<4xi32> to vector<8xi16>
%1 = vector.extract %0[%index] : i16 from vector<8xi16>
return %1 : i16
}

// CHECK-LABEL: func.func @vector_extract_dynamic_index
// CHECK-SAME: (%[[VEC:.+]]: vector<4xi32>, %[[IDX:.+]]: index) -> i16 {
// CHECK: %[[BC:.+]] = vector.bitcast %[[VEC]] : vector<4xi32> to vector<8xi16>
// CHECK: %[[EXTRACT:.+]] = vector.extract %[[BC]][%[[IDX]]] : i16 from vector<8xi16>
// CHECK: return %[[EXTRACT]]
Loading