[flang-commits] [flang] [flang][FIRToSCF] Build the typed induction variable in i64 and narrow with nsw (PR #219281)

via flang-commits flang-commits at lists.llvm.org
Mon Aug 31 18:48:45 PDT 2026


khaki3 wrote:

Thanks for the reviews. I've updated the PR.

Example: `do i = -huge(i), huge(i)-1` with integer(4): trip count is 2^32-2

Before 419908dd2e:

```c
int32_t i = lb;
for (int64_t n = 0; n < trip; n++) { use(i); i += step; }
```

419908dd2e (#217696, current main):

```c
int32_t k = (int32_t)n;       // bare trunc
int32_t i = lb + step * k;    // i32, nsw
```

c46ba31649 (first version of this PR):

```c
int32_t k = (int32_t)n;       // trunc nsw nuw
int32_t i = lb + step * k;    // i32, nsw
```

1a54f4aee4 (now):

```c
int64_t wide = (int64_t)lb + (int64_t)step * n;
int32_t i = (int32_t)wide;    // trunc nsw
```

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


More information about the flang-commits mailing list