optimizer: do not delete statements that may not `:terminate` (#52999)
Fixes #52991.
Currently this commit marks the test case added in #52954 as `broken`
since it has relied on the behavior of #52991.
I'm planning to add followup changes in a separate commit.