diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp index bc93339a68ed3..9b2a455bace47 100644 --- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp +++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp @@ -2466,8 +2466,12 @@ static OpFoldResult foldFromElementsToConstant(FromElementsOp fromElementsOp, if (llvm::any_of(elements, [](Attribute attr) { return !attr; })) return {}; + // DenseElementsAttr only supports int/index/float/complex types. auto destVecType = fromElementsOp.getDest().getType(); auto destEltType = destVecType.getElementType(); + if (!destEltType.isIntOrIndexOrFloat() && !isa(destEltType)) + return {}; + // Constant attributes might have a different type than the return type. // Convert them before creating the dense elements attribute. auto convertedElements = llvm::map_to_vector(elements, [&](Attribute attr) { @@ -2778,8 +2782,8 @@ BroadcastableToResult mlir::vector::isBroadcastableTo( Type srcType, VectorType dstVectorType, std::pair *mismatchingDims) { // Broadcast scalar to vector of the same element type. - if (srcType.isIntOrIndexOrFloat() && dstVectorType && - getElementTypeOrSelf(srcType) == getElementTypeOrSelf(dstVectorType)) + if (isa(srcType) && dstVectorType && + srcType == getElementTypeOrSelf(dstVectorType)) return BroadcastableToResult::Success; // From now on, only vectors broadcast. VectorType srcVectorType = llvm::dyn_cast(srcType); diff --git a/mlir/test/Dialect/Vector/canonicalize.mlir b/mlir/test/Dialect/Vector/canonicalize.mlir index c640ddea7507b..e7381e0c8997e 100644 --- a/mlir/test/Dialect/Vector/canonicalize.mlir +++ b/mlir/test/Dialect/Vector/canonicalize.mlir @@ -3726,3 +3726,17 @@ func.func @no_fold_insert_use_chain_mismatch_static_position(%arg : vector<4xf32 %v_1 = vector.insert %val, %v_0[1] : f32 into vector<4xf32> return %v_1 : vector<4xf32> } + +// ----- + +llvm.mlir.global constant @my_symbol() : i32 + +// CHECK-LABEL: func @from_address_of_regression +// CHECK: %[[a:.*]] = llvm.mlir.addressof @my_symbol +// CHECK: %[[b:.*]] = vector.broadcast %[[a]] : !llvm.ptr to vector<1x!llvm.ptr> +// CHECK: return %[[b]] +func.func @from_address_of_regression() -> vector<1x!llvm.ptr> { + %a = llvm.mlir.addressof @my_symbol : !llvm.ptr + %b = vector.from_elements %a : vector<1x!llvm.ptr> + return %b : vector<1x!llvm.ptr> +} diff --git a/mlir/test/Dialect/Vector/ops.mlir b/mlir/test/Dialect/Vector/ops.mlir index 625ffc185da95..550e52af7874b 100644 --- a/mlir/test/Dialect/Vector/ops.mlir +++ b/mlir/test/Dialect/Vector/ops.mlir @@ -149,7 +149,7 @@ func.func @vector_transfer_ops_tensor(%arg0: tensor, } // CHECK-LABEL: @vector_broadcast -func.func @vector_broadcast(%a: f32, %b: vector, %c: vector<16xf32>, %d: vector<1x16xf32>, %e: vector<8x1xf32>, %f: vector<8x1x!llvm.ptr<1>>) { +func.func @vector_broadcast(%a: f32, %b: vector, %c: vector<16xf32>, %d: vector<1x16xf32>, %e: vector<8x1xf32>, %f: vector<8x1x!llvm.ptr<1>>, %g: !llvm.ptr<1>) { // CHECK: vector.broadcast %{{.*}} : f32 to vector %0 = vector.broadcast %a : f32 to vector // CHECK: vector.broadcast %{{.*}} : vector to vector<4xf32> @@ -164,6 +164,8 @@ func.func @vector_broadcast(%a: f32, %b: vector, %c: vector<16xf32>, %d: ve %5 = vector.broadcast %e : vector<8x1xf32> to vector<8x16xf32> // CHECK-NEXT: vector.broadcast %{{.*}} : vector<8x1x!llvm.ptr<1>> to vector<8x16x!llvm.ptr<1>> %6 = vector.broadcast %f : vector<8x1x!llvm.ptr<1>> to vector<8x16x!llvm.ptr<1>> + // CHECK-NEXT: vector.broadcast %{{.*}} : !llvm.ptr<1> to vector<8x16x!llvm.ptr<1>> + %7 = vector.broadcast %g : !llvm.ptr<1> to vector<8x16x!llvm.ptr<1>> return }