[all-commits] [llvm/llvm-project] 39b0cb: [IndVarSimplify] Allow predicateLoopExit on some l...

Florian Mayer via All-commits all-commits at lists.llvm.org
Thu Oct 16 09:18:22 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 39b0cbe69ca8704dbc5846a91d136f0ed6101782
      https://github.com/llvm/llvm-project/commit/39b0cbe69ca8704dbc5846a91d136f0ed6101782
  Author: Florian Mayer <fmayer at google.com>
  Date:   2025-10-16 (Thu, 16 Oct 2025)

  Changed paths:
    M llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
    M llvm/test/Transforms/IndVarSimplify/X86/overflow-intrinsics.ll
    A llvm/test/Transforms/IndVarSimplify/unreachable-exit.ll

  Log Message:
  -----------
  [IndVarSimplify] Allow predicateLoopExit on some loops with thread-local writes (#155901)

This is important to optimize patterns that frequently appear with
bounds checks:

```
for (int i = 0; i < N; ++i) {
  bar[i] = foo[i] + 123;
}
```

which gets roughly turned into

```
for (int i = 0; i < N; ++i) {
  if (i >= size of foo)
     ubsan.trap();
  if (i >= size of bar)
     ubsan.trap();
  bar[i] = foo[i] + 123;
}
```

Motivating example:
https://github.com/google/boringssl/blob/main/crypto/fipsmodule/hmac/hmac.cc.inc#L138

I hand-verified the assembly and confirmed that this optimization
removes the check in the loop.
This also allowed the loop to be vectorized.

Alive2: https://alive2.llvm.org/ce/z/3qMdLF

I did a `stage2-check-all` for both normal and
`-DBOOTSTRAP_CMAKE_C[XX]_FLAGS="-fsanitize=array-bounds
-fsanitize-trap=all"`.

I also ran some Google-internal tests with `fsanitize=array-bounds`.
Everything passes.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list