[InstCombine] Don't optimize idempotent `atomicrmw <op>, 0` into `load atomic`
authorQuentin Colombet <quentin.colombet@gmail.com>
Wed, 18 Jan 2023 15:01:43 +0000 (16:01 +0100)
committerQuentin Colombet <quentin.colombet@gmail.com>
Thu, 19 Jan 2023 09:04:07 +0000 (10:04 +0100)
commit6b85fa6d81b9f50d7a1c347dfd467c9ab01c4a5d
treef586701fe7c7423bc39c37db2a2242a92ec83ace
parentd49d83e79ca0b59c3d68ff6c46eea69d848b0617
[InstCombine] Don't optimize idempotent `atomicrmw <op>, 0` into `load atomic`

Turning idempotent `atomicrmw`s into `load atomic` is perfectly legal
with respect to how the loading happens, but it may not be legal for the
whole program semantic.

Indeed, this optimization removes a store that may have some effects on
the legality of other optimizations.
Essentially, we lose some information and depending on the backend
it may or may not produce incorrect code, so don't do it!

This fixes llvm.org/PR56450.

Differential Revision: https://reviews.llvm.org/D141277
llvm/lib/Transforms/InstCombine/InstCombineAtomicRMW.cpp
llvm/test/Transforms/InstCombine/atomicrmw.ll