[llvm] [BasicAA] Make isNotCapturedBeforeOrAt() check for calls more precise (PR #69931)

Harald van Dijk via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 4 13:05:30 PST 2023


hvdijk wrote:

I'm seeing miscompilations; this seems to miss something when it comes to vectors. Consider:
```llvm
define i32 @f(<1 x i32> %index, i32 %val) {
entry:
  %alloca = alloca i32
  store i32 %val, ptr %alloca
  %ptrs = getelementptr inbounds i32, ptr %alloca, <1 x i32> %index
  call void @g(<1 x ptr> %ptrs)
  %reload = load i32, ptr %alloca
  ret i32 %reload
}

declare void @g(...)
```
Here, it is not valid to optimise away `%reload`, but this PR does exactly that with `opt -passes=gvn -S -o - test.ll`. It does not happen if I replace the one-element vectors by scalars, it only happens with vectors. The output is:
```llvm
; ModuleID = 'test.ll'
source_filename = "test.ll"

define i32 @f(<1 x i32> %index, i32 %val) {
entry:
  %alloca = alloca i32, align 4
  store i32 %val, ptr %alloca, align 4
  %ptrs = getelementptr inbounds i32, ptr %alloca, <1 x i32> %index
  call void @g(<1 x ptr> %ptrs)
  ret i32 %val
}

declare void @g(...)
```
Is this something you can take a quick look at, or should we revert this for now?

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


More information about the llvm-commits mailing list