[llvm-dev] [BUG] GVN / Memdep bug in the presence of intrinsics

Johannes Doerfert via llvm-dev llvm-dev at lists.llvm.org
Mon Dec 6 05:01:48 PST 2021


-- To avoid forgetting about this I post my bug here --

GVN, or probably memdep analysis, seem to think intrinsics are somewhat 
special
and consequently assume they cannot "effectively clobber" a memory 
location. It
might also be globals-mod-ref or something else that provides AA 
information.

The following example (https://godbolt.org/z/TG6dYvP6M) shows how an 
unknown function
prevents an invalid load hoist while an unknown intrinsic does not. 
Again, the preload
is not sound in a multi-thread environment.

opt -aa-pipeline=basic-aa,globals-aa 
-passes="require<globals-aa>,function(gvn<pre;load-pre;split-backedge-load-pre;memdep>)"

```
@G= internaladdrspace(3) globali32undef
declarevoid at llvm.sync()
definei32 at sync_gvn_bug(i1%cond) nounwind{
entry:
br i1%cond, label%t, label%f
t:
store i3242, i32addrspace(3)* @G
br label%m
f:
br label%m
m:
call void at llvm.sync()
%r= load i32, i32addrspace(3)* @G
call void at llvm.sync()
ret i32%r
}
declarevoid at sync()
definei32 at sync_gvn_bug_ok(i1%cond) nounwind{
entry:
br i1%cond, label%t, label%f
t:
store i3242, i32addrspace(3)* @G
br label%m
f:
br label%m
m:
call void at sync()
%r= load i32, i32addrspace(3)* @G
call void at sync()
ret i32%r
}

```

Help with fixing this is much appreciated!

~ Johannes


-- 
───────────────────
∽ Johannes (he/his)



More information about the llvm-dev mailing list