Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1723,12 +1723,16 @@ struct VectorBroadcastScalarToLowRankLowering
return success();
}

// For 1-d vector, we additionally do a `vectorshuffle`.
// For 1-d vector, we additionally do a `vectorshuffle` if vector width > 1.
auto v =
LLVM::InsertElementOp::create(rewriter, broadcast.getLoc(), vectorType,
poison, adaptor.getSource(), zero);

int64_t width = cast<VectorType>(broadcast.getType()).getDimSize(0);
if (width == 1) {
rewriter.replaceOp(broadcast, v);
return success();
}
SmallVector<int32_t> zeroValues(width, 0);

// Shuffle the value across the desired number of elements.
Expand Down
11 changes: 11 additions & 0 deletions mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ func.func @broadcast_vec1d_from_f32(%arg0: f32) -> vector<2xf32> {

// -----

func.func @broadcast_single_elem_vec1d_from_f32(%arg0: f32) -> vector<1xf32> {
%0 = vector.broadcast %arg0 : f32 to vector<1xf32>
return %0 : vector<1xf32>
}
// CHECK-LABEL: @broadcast_single_elem_vec1d_from_f32
// CHECK-SAME: %[[A:.*]]: f32)
// CHECK: %[[T0:.*]] = llvm.insertelement %[[A]]
// CHECK: return %[[T0]] : vector<1xf32>

// -----

func.func @broadcast_vec1d_from_f32_scalable(%arg0: f32) -> vector<[2]xf32> {
%0 = vector.broadcast %arg0 : f32 to vector<[2]xf32>
return %0 : vector<[2]xf32>
Expand Down