A "non-local load" is the load of value from a pointer defined in
another basic block than the basic block of the load.
While compiling the Linux kernel with CONFIG_FORTIFY_SOURCE=y and
CONFIG_KASAN=y, we discovered a curious case where a repeated condition
check that should have been optimized out was not.
It looks like GVN's ability to process "non local loads" was simply
disabled outright in pr25924 due to an external report.
That fix was too broad IMO. While we do want ASAN (and HWASAN) to help
us spot loads that produce undef, since those are likely OOB reads, it
still would be nice when we don't have undef to allow GVN to proceed. I
think this is a better balance. It should allow us to better optimize
KASAN binaries without regressions in the sanitizer's ability to help
spot OOB access.
Another important case to check is alloca; alloca is by definition not
initialized.
Tested with the original reproducer from the mailing list, as well as
the above linux kernel configs.
See also the original fix:
commit c7810baaa676 ("Disable gvn non-local speculative loads under asan.")
Link: https://github.com/ClangBuiltLinux/linux/issues/1687
Link: https://github.com/llvm/llvm-project/issues/25924
Link: https://lists.llvm.org/pipermail/llvm-dev/2015-November/092427.html
Link: http://lists.llvm.org/pipermail/llvm-dev/attachments/20151114/1c7d8dbe/attachment.c
I don't get the alloca check here. V is the result of the load, not the loaded pointer.