Skip to content

Commit 52f9075

Browse files
committed
use ConfinedAttr to constrain values
1 parent bc0c04d commit 52f9075

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

mlir/include/mlir/Dialect/GPU/IR/GPUOps.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,9 @@ def GPU_ShuffleOp : GPU_Op<
13681368

13691369
def GPU_RotateOp : GPU_Op<
13701370
"rotate", [Pure, AllTypesMatch<["value", "rotateResult"]>]>,
1371-
Arguments<(ins AnyIntegerOrFloatOr1DVector:$value, I32Attr:$offset, I32Attr:$width)>,
1371+
Arguments<(ins AnyIntegerOrFloatOr1DVector:$value,
1372+
ConfinedAttr<I32Attr, [IntMinValue<0>]>:$offset,
1373+
ConfinedAttr<I32Attr, [IntPowerOf2]>:$width)>,
13721374
Results<(outs AnyIntegerOrFloatOr1DVector:$rotateResult, I1:$valid)> {
13731375
let summary = "Rotate values within a subgroup.";
13741376
let description = [{

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,9 +1399,6 @@ LogicalResult RotateOp::verify() {
13991399
uint32_t offset = getOffset();
14001400
uint32_t width = getWidth();
14011401

1402-
if (!llvm::isPowerOf2_32(width))
1403-
return emitOpError() << "width must be a power of two";
1404-
14051402
if (offset >= width) {
14061403
return emitOpError() << "offset must be in the range [0, " << width << ")";
14071404
}

mlir/test/Dialect/GPU/invalid.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ func.func @rotate_unsupported_type_vec(%arg0 : vector<[4]xf32>) {
505505
// -----
506506

507507
func.func @rotate_unsupported_width(%arg0 : f32) {
508-
// expected-error@+1 {{op width must be a power of two}}
508+
// expected-error@+1 {{'gpu.rotate' op attribute 'width' failed to satisfy constraint: 32-bit signless integer attribute whose value is a power of two > 0}}
509509
%rotate, %valid = "gpu.rotate"(%arg0) { offset = 4 : i32, width = 15 : i32 } : (f32) -> (f32, i1)
510510
return
511511
}
@@ -521,7 +521,7 @@ func.func @rotate_unsupported_offset(%arg0 : f32) {
521521
// -----
522522

523523
func.func @rotate_unsupported_offset_minus(%arg0 : f32) {
524-
// expected-error@+1 {{op offset must be in the range [0, 16)}}
524+
// expected-error@+1 {{'gpu.rotate' op attribute 'offset' failed to satisfy constraint: 32-bit signless integer attribute whose minimum value is 0}}
525525
%rotate, %valid = "gpu.rotate"(%arg0) { offset = -1 : i32, width = 16 : i32 } : (f32) -> (f32, i1)
526526
return
527527
}

0 commit comments

Comments
 (0)