llvm-project
160d2a30 - [VPlan] Allow tail folding early exits with side effects

Commit
8 days ago
[VPlan] Allow tail folding early exits with side effects Continues the work in #179595. This allows us to tail fold e.g. the following loop: ```c extern char a[1024], b[1024], c[1024], y[1024]; void two_guards(void) { for (int i = 0; i < 1000; i++) { if (a[i] == 0) break; if (b[i] > 3) { if (c[i] < 9) y[i] = 1; } } } ``` Into this on RISC-V: ```asm .LBB0_1: # %vector.body # =>This Inner Loop Header: Depth=1 vsetvli a6, a1, e8, m2, ta, ma add a7, a2, a0 vle8.v v10, (a7) vmseq.vi v12, v10, 0 vmsbf.m v0, v12 add a7, a3, a0 vle8.v v10, (a7), v0.t vmsgtu.vi v13, v10, 3 vmand.mm v0, v0, v13 add a7, a4, a0 vle8.v v10, (a7), v0.t vmsleu.vi v13, v10, 8 vmand.mm v0, v0, v13 vcpop.m a7, v12 add t0, a5, a0 vse8.v v8, (t0), v0.t bnez a7, .LBB0_3 # in Loop: Header=BB0_1 Depth=1 sub a1, a1, a6 add a0, a0, a6 bnez a1, .LBB0_1 ``` For early exit loops with side effects, we may be able to handle the exits by masking the vector body, or we may have to handle them in the scalar loop. If it's the latter we can't tail fold the plan just yet, we need to fixup a lot of assumptions around the middle block etc. For now just disable tail folding in the cost model. It's safe to change the tail folding here because foldTailByMasking hasn't been called yet and there hasn't been any costing done.
Author
Committer
Parents
Loading