[VPlan] Give side-effect early exits a dedicated exit block. (#244337)
Instead of routing both early and latch exits through the middle block,
give the early exit its own vector.early.exit block, which computes the
resume IV (IV + first active lane) and branches to the scalar preheader.
The latch now has distinct successors {vector.early.exit, middle.block,
header}, the same shape used for early exits without side effects, and
the middle block keeps the plain cmp.n check. This also removes the
Succ0 == Succ1 special case in expandBranchOnTwoConds
This improves the generated code:
* The exit IV (cttz.elts + add) is only computed when the early exit is
taken, instead of in the middle block on every exit.
* The IV increment moves after the early-exit test, so the old IV is no
longer live across it. This removes a register copy or a second counter
from the vector loop.
* cmp.n folds for constant trip counts that are a multiple of VF,
removing the middle block's branch to the scalar loop.
The generated assembly for both RISCV and AArch64 improve slightly
https://godbolt.org/z/8vYcqqx3v
And it has the benefit that the layout is consistent with other
early-exit style.
```
Before: After:
vector.body: vector.body:
ldr z0, [x12] ld1w { z0.s }, p0/z, [x10, x12, lsl #2]
decw x8 cmpne p1.s, p0/z, z0.s, #0
cmpne p1.s, p0/z, z0.s, #0 brkb p1.b, p0/z, p1.b
brkb p1.b, p0/z, p1.b ld1w { z0.s }, p1/z, [x9, x12, lsl #2]
ld1w { z0.s }, p1/z, [x11] add z0.s, z0.s, #42
add z0.s, z0.s, #42 st1w { z0.s }, p1, [x8, x12, lsl #2]
st1w { z0.s }, p1, [x10] b.ne vector.early.exit
b.ne middle.block vector.body.interim:
add x14, x9, x13 incw x12
incb x10 cmp x11, x12
incb x11 b.ne vector.body
dech x14 middle.block:
incb x12 cbnz x13, for.body.preheader
mov x13, x8 b exit
cbnz x14, vector.body vector.early.exit:
middle.block: incp x12, p1.s
mov x9, #-10000 mov x11, x12
incp x9, p1.s
cmp x9, x8
b.eq exit
cntp x9, p1, p1.s
sub x8, x9, x8
````
PR: https://github.com/llvm/llvm-project/pull/244337