[IndVarSimplify] Use context to prove a narrow IV def non-negative (#236461)
When IndVars widens an IV, it checks for each narrow def (the IV and its
users) whether it is non-negative on every iteration. If so, zext and
sext of it are equal, so when widening the def’s users they can use
either.
Previously, non-negativity of the def was proved without context, so in
some cases we were unable to prove it and left trunc + zext pairs in the
code.
Now we ask SCEV at the def’s context, which lets it use dominating
guards and assumes.
This allows it to not insert unnecessary truncs/zexts. E.g. in
```
if (m > 0)
for (i32 i = 0; i < m; i++)
use(zext(i + m <nsw>));
```
`i + m` is non-negative on every iteration because of the guard and the
nsw.
Before, IndVars widened `i + m` to i64, truncated it back to i32 and
zexted it again.
Now SCEV proves `i + m >=s 0` at its context, so `zext(add)` equals
`sext(add) = wide_i + wide_m` and so we don't need the trunc + zext pair
for `i + m`.
Assisted-By: Claude