Skip to content

Commit edcefce

Browse files
committed
address a few review comments
1 parent 9bae051 commit edcefce

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3294,9 +3294,8 @@ LogicalResult LLVM::ConstantOp::verify() {
32943294
}
32953295
if (auto structType = dyn_cast<LLVMStructType>(getType())) {
32963296
auto arrayAttr = dyn_cast<ArrayAttr>(getValue());
3297-
if (!arrayAttr) {
3298-
return emitOpError() << "expected array attribute for a struct constant";
3299-
}
3297+
if (!arrayAttr)
3298+
return emitOpError() << "expected array attribute for struct type";
33003299

33013300
ArrayRef<Type> elementTypes = structType.getBody();
33023301
if (arrayAttr.size() != elementTypes.size()) {
@@ -3309,17 +3308,15 @@ LogicalResult LLVM::ConstantOp::verify() {
33093308
"floating point or integer";
33103309
}
33113310
auto attrType = cast<TypedAttr>(attr).getType();
3312-
if (attrType != type) {
3311+
if (attrType != type)
33133312
return emitOpError()
33143313
<< "struct element at index " << i << " is of wrong type";
3315-
}
33163314
}
33173315

33183316
return success();
33193317
}
3320-
if (auto targetExtType = dyn_cast<LLVMTargetExtType>(getType())) {
3318+
if (auto targetExtType = dyn_cast<LLVMTargetExtType>(getType()))
33213319
return emitOpError() << "does not support target extension type.";
3322-
}
33233320

33243321
// Check that an attribute whose element type has floating point semantics
33253322
// `attributeFloatSemantics` is compatible with a type whose element type
@@ -3342,9 +3339,9 @@ LogicalResult LLVM::ConstantOp::verify() {
33423339
}
33433340
unsigned floatWidth = APFloat::getSizeInBits(attributeFloatSemantics);
33443341
if (isa<IntegerType>(constantElementType)) {
3345-
if (!constantElementType.isInteger(floatWidth)) {
3342+
if (!constantElementType.isInteger(floatWidth))
33463343
return emitOpError() << "expected integer type of width " << floatWidth;
3347-
}
3344+
33483345
return success();
33493346
}
33503347
return success();
@@ -3387,9 +3384,13 @@ LogicalResult LLVM::ConstantOp::verify() {
33873384
"expected integer element type for integer elements attribute");
33883385
}
33893386
} else if (auto arrayAttr = dyn_cast<ArrayAttr>(getValue())) {
3387+
3388+
// The case where the constant is LLVMStructType has already been handled.
33903389
auto arrayType = dyn_cast<LLVM::LLVMArrayType>(getType());
33913390
if (!arrayType)
3392-
return emitOpError() << "expected array type";
3391+
return emitOpError()
3392+
<< "expected array or struct type for array attribute";
3393+
33933394
// When the attribute is an ArrayAttr, check that its nesting matches the
33943395
// corresponding ArrayType or VectorType nesting.
33953396
return verifyStructArrayConstant(*this, arrayType, arrayAttr, /*dim=*/0);

mlir/test/Dialect/LLVMIR/invalid.mlir

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ llvm.func @array_attribute_two_different_types() -> !llvm.struct<(f64, f64)> {
394394
// -----
395395

396396
llvm.func @struct_wrong_attribute_type() -> !llvm.struct<(f64, f64)> {
397-
// expected-error @+1 {{expected array attribute}}
397+
// expected-error @+1 {{expected array attribute for struct type}}
398398
%0 = llvm.mlir.constant(1.0 : f64) : !llvm.struct<(f64, f64)>
399399
llvm.return %0 : !llvm.struct<(f64, f64)>
400400
}
@@ -443,15 +443,15 @@ llvm.func @scalable_vec_requires_splat() -> vector<[4]xf64> {
443443
// -----
444444

445445
llvm.func @int_attr_requires_int_type() -> f32 {
446-
// expected-error @+1 {{expected integer type}}
446+
// expected-error @below{{expected integer type}}
447447
%0 = llvm.mlir.constant(1 : index) : f32
448448
llvm.return %0 : f32
449449
}
450450

451451
// -----
452452

453453
llvm.func @vector_int_attr_requires_int_type() -> vector<2xf32> {
454-
// expected-error @+1 {{expected integer element type}}
454+
// expected-error @below{{expected integer element type}}
455455
%0 = llvm.mlir.constant(dense<[1, 2]> : vector<2xi32>) : vector<2xf32>
456456
llvm.return %0 : vector<2xf32>
457457
}
@@ -498,15 +498,23 @@ llvm.func @vector_with_non_vector_type() -> f32 {
498498

499499
// -----
500500

501-
llvm.func @non_array_attr_for_struct() -> !llvm.array<2 x array<2 x array<2 x struct<(i32)>>>> {
501+
llvm.func @array_attr_with_invalid_type() -> i32 {
502+
// expected-error @below{{expected array or struct type for array attribute}}
503+
%0 = llvm.mlir.constant([1 : i32]) : i32
504+
llvm.return %0 : i32
505+
}
506+
507+
// -----
508+
509+
llvm.func @elements_attribute_incompatible_nested_array_struct1_type() -> !llvm.array<2 x array<2 x array<2 x struct<(i32)>>>> {
502510
// expected-error @below{{expected integer element type for integer elements attribute}}
503511
%0 = llvm.mlir.constant(dense<[[[1, 2], [3, 4]], [[42, 43], [44, 45]]]> : tensor<2x2x2xi32>) : !llvm.array<2 x array<2 x array<2 x struct<(i32)>>>>
504512
llvm.return %0 : !llvm.array<2 x array<2 x array<2 x struct<(i32)>>>>
505513
}
506514

507515
// -----
508516

509-
llvm.func @non_array_attr_for_struct() -> !llvm.array<2 x array<2 x array<2 x struct<(i32, i32, i32)>>>> {
517+
llvm.func @elements_attribute_incompatible_nested_array_struct3_type() -> !llvm.array<2 x array<2 x array<2 x struct<(i32, i32, i32)>>>> {
510518
// expected-error @below{{expected integer element type for integer elements attribute}}
511519
%0 = llvm.mlir.constant(dense<[[[1, 2], [3, 4]], [[42, 43], [44, 45]]]> : tensor<2x2x2xi32>) : !llvm.array<2 x array<2 x array<2 x struct<(i32, i32, i32)>>>>
512520
llvm.return %0 : !llvm.array<2 x array<2 x array<2 x struct<(i32, i32, i32)>>>>
@@ -538,8 +546,6 @@ llvm.func @struct_wrong_attribute_element_type() -> !llvm.struct<(f64, f64)> {
538546

539547
// -----
540548

541-
// -----
542-
543549
func.func @insertvalue_non_llvm_type(%a : i32, %b : i32) {
544550
// expected-error@+2 {{expected LLVM IR Dialect type}}
545551
llvm.insertvalue %a, %b[0] : tensor<*xi32>
@@ -583,13 +589,13 @@ func.func @extractvalue_invalid_type(%a : !llvm.array<4 x vector<8xf32>>) -> !ll
583589
return %b : !llvm.array<4 x vector<8xf32>>
584590
}
585591

586-
587592
// -----
588593

589594
func.func @extractvalue_non_llvm_type(%a : i32, %b : tensor<*xi32>) {
590595
// expected-error@+2 {{expected LLVM IR Dialect type}}
591596
llvm.extractvalue %b[0] : tensor<*xi32>
592597
}
598+
593599
// -----
594600

595601
func.func @extractvalue_struct_out_of_bounds() {
@@ -758,6 +764,7 @@ func.func @atomicrmw_scalable_vector(%ptr : !llvm.ptr, %f32_vec : vector<[2]xf32
758764
%0 = llvm.atomicrmw fadd %ptr, %f32_vec unordered : !llvm.ptr, vector<[2]xf32>
759765
llvm.return
760766
}
767+
761768
// -----
762769

763770
func.func @atomicrmw_vector_expected_float(%ptr : !llvm.ptr, %i32_vec : vector<3xi32>) {
@@ -1766,7 +1773,6 @@ func.func @tma_load(%tmaDescriptor: !llvm.ptr, %dest : !llvm.ptr<3>, %barrier: !
17661773
return
17671774
}
17681775

1769-
17701776
// -----
17711777

17721778
func.func @tma_load(%tmaDescriptor: !llvm.ptr, %dest : !llvm.ptr<3>, %barrier: !llvm.ptr<3>, %crd0: i32, %crd1: i32, %crd2: i32, %crd3: i32, %off0: i16, %off1: i16, %ctamask : i16, %cacheHint : i64, %p : i1) {

0 commit comments

Comments
 (0)