Issue 235467
Summary [GlobalISel] LoadStoreOpt merges noncontiguous stores after excluding an aliasing store
Labels miscompilation, llvm:globalisel, generated by fuzzer
Assignees
Reporter ChoKyuWon
    ### reproducer
godbolt: https://godbolt.org/z/ofEPP594j

```llvm
@buf = global [3 x i32] zeroinitializer

define i32 @main() {
  %middle = getelementptr i8, ptr @buf, i64 4
  %end = getelementptr i8, ptr @buf, i64 8
  store i32 10, ptr @buf, align 4
  store i32 11, ptr %middle, align 4
  %x = load i32, ptr %middle, align 4
  store i32 12, ptr %end, align 4
  %last = load i32, ptr %end, align 4
  %sum = add i32 %x, %last
  ret i32 %sum
}
```

```console
$ opt -passes=verify -disable-output repro.ll
$ llubi repro.ll; echo $?
23

$ llc -mtriple=aarch64-unknown-linux-gnu -O3 -global-isel -global-isel-abort=1 repro.ll -o bad.s
$ aarch64-linux-gnu-gcc -static bad.s -o bad
$ qemu-aarch64 ./bad; echo $?
11

$ llc -mtriple=aarch64-unknown-linux-gnu -O3 repro.ll -o good.s
$ aarch64-linux-gnu-gcc -static good.s -o good
$ qemu-aarch64 ./good; echo $?
23
```

### suggested fix
In `llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp`, `LoadStoreOptImpl::processMergeCandidate` skips aliasing stores but passes the remaining stores to `mergeStores` without checking contiguity.
Here, excluding the middle store leaves stores at offsets 0 and 8, which `doSingleStoreMerge` packs into an 8-byte store at offset 0; offset 8 remains zero.
Split the candidate at each excluded store and merge only contiguous runs, or conservatively stop at the first aliasing store.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to