[flang-commits] [flang] [flang] Clean-up for fir.do_loop generation in lowering. (PR #160630)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Thu Sep 25 09:41:04 PDT 2025


vzakhari wrote:

> > Maybe I'm misreading, but looking at the changes to the test, it looks like we're still yielding the original type instead of the primary iv. Why not yield the primary iv and convert the result after the loop? It's still incrementing the user variable?
> 
> Slava will know best. My understanding is that using the original variable type helps LLVM vectorizer: [af7edf1](https://github.com/llvm/llvm-project/commit/af7edf1557d87026bb4dd4783f60e766538e923c)

Yes, incrementing the user IV in the user type was crucial for helping LLVM vectorizer. Jean, Scott and I had some discussions about this today.

It seems that exposing the `index` loop counter too early in the Lowering does not give us a lot of benefit, and the following representation might be better:
```
      %3 = fir.do_loop %arg0 = %lb_in_user_type to %ub_in_user_type step %step_in_user_type -> (i32) {
        fir.store %arg0 to %user_iv_loc : !fir.ref<i32>
        ...
        fir.result %arg0 : i32
      }
      fir.store %3 to %user_iv_loc : !fir.ref<i32>
```

The `fir.do_loop` to CFG conversion, then should introduce an `index` loop counter to make sure that the loops with the final increment overflowing the IV user-type work properly.

I plan to merge this PR as-is, and I will experiment with the above lowering scheme.

https://github.com/llvm/llvm-project/pull/160630


More information about the flang-commits mailing list