[llvm] [RISCV] Prefer SP over FP for frame index access when offset fits within compressed immediate range. (PR #193962)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 3 22:22:18 PDT 2026
topperc wrote:
> > I have attached a reproducer that only involves [zstd](https://github.com/facebook/zstd) and reproduces on Linux.
> > [CMakeLists.txt](https://github.com/user-attachments/files/28496982/CMakeLists.txt) [main.c](https://github.com/user-attachments/files/28496983/main.c)
> > The steps to reproduce the issue:
> > ```shell
> > $ git clone https://github.com/facebook/zstd
> > $ zstd main.c # This assumes you have zstd installed, if not you can build it from the repository above.
> > $ cmake -G Ninja -B build -S . -DCMAKE_SYSROOT=/path/to/sysroot -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=riscv64 -DCMAKE_C_COMPILER=/path/to/bin/clang -DCMAKE_C_COMPILER_TARGET=riscv64-linux-gnu
> > $ qemu-riscv64 -L /path/to/sysroot ./build/reproducer main.c.zst
> > Compressed size: 1352
> > Uncompressed size: 4835
> > Running OneShot Decompression...
> > Decompression failed: Data corruption detected
> > Running Streaming Decompression...
> > Streaming decompression failed: Data corruption detected
> > ```
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Prior to this change, the decompression would succeed but after this change it fails. If I omit the `-fno-omit-frame-pointer` option, decompression would succeed.
> > I also see a different behavior depending on the value of `-ftrivial-auto-var-init`:
> >
> > * with `-ftrivial-auto-var-init=uninitialized` the streaming decompression appears to be stuck an infinite loop,
> > * with `-ftrivial-auto-var-init=zero` the one-shot decompression appears to be stuck in an infinite loop,
> > * with `-ftrivial-auto-var-init=pattern` both of them fail.
> >
> > Given that this change is clearly causing a miscompile, I'd like revert this commit while we continue to investigate the issue.
>
> It looks to be related to vectors. Removing 'v' from the march string works.
There's a stack adjustment in `ZSTD_buildSeqTable` before a call to `ZSTD_buildFSETable`. There is a load after it that uses SP, but it is not accounting for the stack adjustment.
https://github.com/llvm/llvm-project/pull/193962
More information about the llvm-commits
mailing list