[LICM] Don't promote store to global even in single-thread mode
authorNikita Popov <npopov@redhat.com>
Thu, 16 Mar 2023 15:59:19 +0000 (16:59 +0100)
committerNikita Popov <npopov@redhat.com>
Mon, 3 Apr 2023 12:20:06 +0000 (14:20 +0200)
commitb58a697f3e19437f8525ec31a384c8901b0b736c
tree63e2b1f81c63e8ca07cce019a386ae0bc000532f
parent82df745e57be2b5765b0249e6afaff0627c470bd
[LICM] Don't promote store to global even in single-thread mode

Even if there are no thread-safety concerns, we should not promote
(not guaranteed-to-execute) stores to globals without further
analysis: While the global may be writable, we may not have
provenance to perform the write. The @promote_global_noalias test
case illustrates a miscompile in the presence of a noalias pointer
to the global.

Worth noting that the load-only promotion may also not be well-defined
depending on precise semantics (we don't specify whether load
violating noalias is poison or UB -- though I believe the general
inclination is to make it poison, and only stores UB), but that's
a more general issue.

This is inspired by https://github.com/llvm/llvm-project/issues/60860,
which is a related issue with TBAA metadata.

Differential Revision: https://reviews.llvm.org/D146233
llvm/lib/Transforms/Scalar/LICM.cpp
llvm/test/Transforms/LICM/promote-single-thread.ll