Skip to content

Commit 1529754

Browse files
committed
Revert "[mlir][transform] Update transform.loop.peel (#67482)"
This reverts commit 1d5ccce. Broken bot: * https://lab.llvm.org/buildbot/#/builders/220/builds/28440
1 parent 381cc48 commit 1529754

File tree

5 files changed

+21
-47
lines changed

5 files changed

+21
-47
lines changed

mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,23 @@ def LoopPeelOp : Op<Transform_Dialect, "loop.peel",
142142

143143
This operation ignores non-scf::ForOp ops and drops them in the return.
144144

145-
This operation returns two scf::ForOp, with the first Op satisfying the
146-
postcondition: "the loop trip count is divisible by the step". The second
147-
loop Op contains the remaining iteration. Note that even though the
148-
Payload IR modification may be performed in-place, this operation consumes
149-
the operand handle and produces a new one.
145+
This operation always succeeds and returns the scf::ForOp with the
146+
postcondition: "the loop trip count is divisible by the step".
147+
This operation may return the same unmodified loop handle when peeling did
148+
not modify the IR (i.e. the loop trip count was already divisible).
150149

151-
#### Return Modes
150+
Note that even though the Payload IR modification may be performed
151+
in-place, this operation consumes the operand handle and produces a new
152+
one.
152153

153-
Produces a definite failure if peeling fails.
154+
TODO: Return both the peeled loop and the remainder loop.
154155
}];
155156

156157
let arguments =
157158
(ins Transform_ScfForOp:$target,
158159
DefaultValuedAttr<BoolAttr, "false">:$fail_if_already_divisible);
159-
let results = (outs TransformHandleTypeInterface:$peeled_loop,
160-
TransformHandleTypeInterface:$remainder_loop);
160+
// TODO: Return both the peeled loop and the remainder loop.
161+
let results = (outs TransformHandleTypeInterface:$transformed);
161162

162163
let assemblyFormat =
163164
"$target attr-dict `:` functional-type(operands, results)";

mlir/lib/Dialect/SCF/TransformOps/SCFTransformOps.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,14 @@ transform::LoopPeelOp::applyToOne(transform::TransformRewriter &rewriter,
226226
transform::ApplyToEachResultList &results,
227227
transform::TransformState &state) {
228228
scf::ForOp result;
229+
// This helper returns failure when peeling does not occur (i.e. when the IR
230+
// is not modified). This is not a failure for the op as the postcondition:
231+
// "the loop trip count is divisible by the step"
232+
// is valid.
229233
LogicalResult status =
230234
scf::peelForLoopAndSimplifyBounds(rewriter, target, result);
231-
if (failed(status)) {
232-
DiagnosedSilenceableFailure diag = emitSilenceableError()
233-
<< "failed to peel";
234-
return diag;
235-
}
236-
results.push_back(target);
237-
results.push_back(result);
238-
235+
// TODO: Return both the peeled loop and the remainder loop.
236+
results.push_back(failed(status) ? target : result);
239237
return DiagnosedSilenceableFailure::success();
240238
}
241239

mlir/test/Dialect/Linalg/transform-op-fuse.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ transform.sequence failures(propagate) {
4848
%0 = transform.structured.match ops{["linalg.elemwise_binary"]} in %arg1 : (!transform.any_op) -> !transform.any_op
4949
%1, %loops:2 = transform.structured.fuse %0 {tile_sizes = [32, 32], tile_interchange = [0, 1]}
5050
: (!transform.any_op) -> (!transform.any_op, !transform.op<"scf.for">, !transform.any_op)
51-
transform.loop.peel %loops#0 : (!transform.op<"scf.for">) -> (!transform.any_op, !transform.any_op)
51+
transform.loop.peel %loops#0 : (!transform.op<"scf.for">) -> !transform.any_op
5252
}
5353

5454
// -----

mlir/test/Dialect/SCF/transform-ops-invalid.mlir

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,3 @@ transform.sequence failures(propagate) {
5959
// expected-error @below {{failed to outline}}
6060
transform.loop.outline %0 {func_name = "foo"} : (!transform.any_op) -> (!transform.any_op, !transform.any_op)
6161
}
62-
63-
// -----
64-
65-
func.func @test_loops_do_not_get_peeled() {
66-
%lb = arith.constant 0 : index
67-
%ub = arith.constant 40 : index
68-
%step = arith.constant 5 : index
69-
scf.for %i = %lb to %ub step %step {
70-
arith.addi %i, %i : index
71-
}
72-
return
73-
}
74-
75-
transform.sequence failures(propagate) {
76-
^bb1(%arg1: !transform.any_op):
77-
%0 = transform.structured.match ops{["arith.addi"]} in %arg1 : (!transform.any_op) -> !transform.any_op
78-
%1 = transform.loop.get_parent_for %0 : (!transform.any_op) -> !transform.op<"scf.for">
79-
// expected-error @below {{failed to peel}}
80-
transform.loop.peel %1 : (!transform.op<"scf.for">) -> (!transform.any_op, !transform.any_op)
81-
}

mlir/test/Dialect/SCF/transform-ops.mlir

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,16 @@ transform.sequence failures(propagate) {
8787
// CHECK-LABEL: @loop_peel_op
8888
func.func @loop_peel_op() {
8989
// CHECK: %[[C0:.+]] = arith.constant 0
90-
// CHECK: %[[C41:.+]] = arith.constant 41
90+
// CHECK: %[[C42:.+]] = arith.constant 42
9191
// CHECK: %[[C5:.+]] = arith.constant 5
9292
// CHECK: %[[C40:.+]] = arith.constant 40
9393
// CHECK: scf.for %{{.+}} = %[[C0]] to %[[C40]] step %[[C5]]
9494
// CHECK: arith.addi
95-
// CHECK: scf.for %{{.+}} = %[[C40]] to %[[C41]] step %[[C5]]
95+
// CHECK: scf.for %{{.+}} = %[[C40]] to %[[C42]] step %[[C5]]
9696
// CHECK: arith.addi
9797
%0 = arith.constant 0 : index
98-
%1 = arith.constant 41 : index
98+
%1 = arith.constant 42 : index
9999
%2 = arith.constant 5 : index
100-
// expected-remark @below {{main loop}}
101-
// expected-remark @below {{remainder loop}}
102100
scf.for %i = %0 to %1 step %2 {
103101
arith.addi %i, %i : index
104102
}
@@ -109,10 +107,7 @@ transform.sequence failures(propagate) {
109107
^bb1(%arg1: !transform.any_op):
110108
%0 = transform.structured.match ops{["arith.addi"]} in %arg1 : (!transform.any_op) -> !transform.any_op
111109
%1 = transform.loop.get_parent_for %0 : (!transform.any_op) -> !transform.op<"scf.for">
112-
%main_loop, %remainder = transform.loop.peel %1 : (!transform.op<"scf.for">) -> (!transform.op<"scf.for">, !transform.op<"scf.for">)
113-
// Verify that both of the generated loop handles are valid
114-
transform.test_print_remark_at_operand %main_loop, "main loop" : !transform.op<"scf.for">
115-
transform.test_print_remark_at_operand %remainder, "remainder loop" : !transform.op<"scf.for">
110+
transform.loop.peel %1 : (!transform.op<"scf.for">) -> !transform.any_op
116111
}
117112

118113
// -----

0 commit comments

Comments
 (0)