Why is LSR positioned after LV in the pass pipeline?

Hi,

We know LoopVectorize is a target-independent optimization and is run in quite early stage, while LSR is a target-specific one and is apparently later than LV. The problem here is in some cases I’ve seen, if some expansive computations in a loop are users of vectorized induction variables, they cannot be reduced because vector type is not scevable and those chains wont’ be collected in LSR. Even for scalar induction variables, put LSR behind LV affects LV’s cost computation and possibly makes llvm wrongly assume some loops are not beneficial to vectorize. I’d really appreciate it if someone could explain the rationale here.

Regards,

Mindong