Skip to content

[mlir][SCF] Do not verify step size of scf.for #78141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2024
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
4 changes: 0 additions & 4 deletions mlir/lib/Dialect/SCF/IR/SCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,6 @@ void ForOp::build(OpBuilder &builder, OperationState &result, Value lb,
}

LogicalResult ForOp::verify() {
IntegerAttr step;
if (matchPattern(getStep(), m_Constant(&step)) && step.getInt() <= 0)
return emitOpError("constant step operand must be positive");

// Check that the number of init args and op results is the same.
if (getInitArgs().size() != getNumResults())
return emitOpError(
Expand Down
8 changes: 6 additions & 2 deletions mlir/test/Dialect/SCF/for-loop-peeling.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,19 @@ func.func @regression(%arg0: memref<i64>, %arg1: index) {

// -----

// Check that this doesn't crash but trigger the verifier.
// Regression test: Make sure that we do not crash.

// CHECK-LABEL: func @zero_step(
// CHECK: scf.for
// CHECK: scf.for
func.func @zero_step(%arg0: memref<i64>) {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%foldto0 = arith.subi %c1, %c1 : index
// expected-error @+1 {{'scf.for' op constant step operand must be positive}}
scf.for %arg2 = %c0 to %c1 step %foldto0 {
%2 = arith.index_cast %arg2 : index to i64
memref.store %2, %arg0[] : memref<i64>
}
return
}

12 changes: 0 additions & 12 deletions mlir/test/Dialect/SCF/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ func.func @loop_for_mismatch(%arg0: i32, %arg1: index) {

// -----

func.func @loop_for_step_positive(%arg0: index) {
// expected-error@+2 {{constant step operand must be positive}}
%c0 = arith.constant 0 : index
"scf.for"(%arg0, %arg0, %c0) ({
^bb0(%arg1: index):
scf.yield
}) : (index, index, index) -> ()
return
}

// -----

func.func @loop_for_one_region(%arg0: index) {
// expected-error@+1 {{requires one region}}
"scf.for"(%arg0, %arg0, %arg0) (
Expand Down