[llvm] [SLP]Improve minbitwidth analysis. (PR #84536)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 15 03:39:59 PDT 2024


mstorsjo wrote:

I've run into two separate issues:
```c
typedef char *a;
int b, c;
void d() {
  int colctr = b, colsum, i, j;
  a e, f, g;
  long h;
  for (; c;) {
    colsum = *e++ + *f++;
    j = e[0] + f[0];
    i = colsum;
    for (; colctr; colctr--) {
      e++;
      f++;
      j = e[0] + f[0];
      *g++ = i = colsum;
      colsum = j;
    }
    h = i + j;
    *g = h;
  }
}
```
Compiled like this:
```
$ clang -target i686-w64-mingw32 -O2 -c repro.c
clang: ../include/llvm/ADT/DenseMap.h:1270: llvm::DenseMapIterator<KeyT, ValueT,
 KeyInfoT, Bucket, IsConst>::value_type* llvm::DenseMapIterator<KeyT, ValueT, Ke
yInfoT, Bucket, IsConst>::operator->() const [with KeyT = const llvm::slpvectori
zer::BoUpSLP::TreeEntry*; ValueT = std::pair<long unsigned int, bool>; KeyInfoT 
= llvm::DenseMapInfo<const llvm::slpvectorizer::BoUpSLP::TreeEntry*, void>; Buck
et = llvm::detail::DenseMapPair<const llvm::slpvectorizer::BoUpSLP::TreeEntry*, 
std::pair<long unsigned int, bool> >; bool IsConst = false; llvm::DenseMapIterat
or<KeyT, ValueT, KeyInfoT, Bucket, IsConst>::pointer = llvm::detail::DenseMapPai
r<const llvm::slpvectorizer::BoUpSLP::TreeEntry*, std::pair<long unsigned int, b
ool> >*]: Assertion `Ptr != End && "dereferencing end() iterator"' failed.
```
This regressed in ea429e19f56005bf89e717c14efdf49ec055b183 / #84363, and is a clear and simple assert failure.

This PR, and commit 7f2167868d8c1cedd3915883412b9c787a2f01db, caused miscompilations (code doing the wrong thing at runtime), noticeable in ffmpeg. (I have also observed test failures in openh264, but I haven't had to verify if this is caused by this same commit or not, but it seems plausible.)

To repro that, do something along these lines:
```
$ git clone https://github.com/ffmpeg/ffmpeg
$ mkdir ffmpeg-build
$ cd ffmpeg-build
$ ../ffmpeg/configure --cc=clang --samples=../ffmpeg-samples
$ make fate-rsync # fetching input data to tests
$ make -j$(nproc) fate
```
I've reproduced these failures with i686-mingw, x86_64-mingw, aarch64-mingw and aarch64-linux targets - I presume it's reproducible for x86_64 linux as well but I haven't tried that.

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


More information about the llvm-commits mailing list