The executeregionop is used to allow multiple blocks within SCF constructs. If the container allows multiple blocks, inline the region
The execution region op can be inlined even if its parent can only hold a single block (like scf.for, scf.if) when the execute_region only contains a single block. I think the rewrite pattern you added can be transparently generalized for that case without really any addition in code?
Is there an assumption here that the yield terminator will be the terminator of the last block? Is it possible that there are multiple terminators? I don't see anything in the verifier of the scf.execute_region op that prevents it.
I'm not sure it's feasible. Folders are not supposed to create new operations, and inlining most likely will (the inlined operations will be "new" in the block).
Nit: just use SmallVector<Value> with the default number of stack elements
Not: drop trivial braces
Could we relax this test a little? In particular,
On the contrary, we do care about execute-region being removed, so I would add CHECK-NOT: execute_region.
Nit: could you change the name of this function to be able to tell the "test cases" apart?