[Mlir-commits] [mlir] [MLIR] Introduce support for early exits (PR #166688)

Mehdi Amini llvmlistbot at llvm.org
Tue Mar 31 06:22:25 PDT 2026


================

----------------
joker-eph wrote:

> Are you asking why we introduce scf.loop instead of just keeping scf.while and scf.for and adding support for early-exit to these?

I see scf.for as a simple loop with guarantee that its trip count is directly inferable from the operands, it makes it a nice property for some analysis.  Adding break capabilities would make this moot, I don't think it's desirable?

scf.while does not have this property, and I think scf.loop would make scf.while not useful anymore.
There is a difference in design that explains why we can't just make scf.while having break instead of introducing scf.loop: it is that scf.while is designed so that its exit condition is computed in a separate region. Its RegionBranchOpInterface orchestrates this logic of how the control-flow and dataflow works across these regions. This makes it ackward when you also introduces breaks.

scf.loop has a single region and only relies on break as the sole way to exit.

>> Is this the same question as in the other comment thread above? If not can you reformulate (I'm reading it the same now, but not sure).
> Not sure which one.

You asked above 
> Would it be illegal to break / continue over regions that do not implement the appropriate functions of those interfaces, right?

I was wondering if you're asking something else here with "escaping regions that weren't counting on that behaviour", and if so to clarify the difference. If not then I hope the pointers I provided to the verifier in the other thread are answering, let me know.


https://github.com/llvm/llvm-project/pull/166688


More information about the Mlir-commits mailing list