llvm-project
5d49ab68 - [InstCombine] Canonicalize atomicrmw sub of a constant to add (#232626)

Commit
1 day ago
[InstCombine] Canonicalize atomicrmw sub of a constant to add (#232626) Rewrite `atomicrmw sub ptr, C` as `atomicrmw add ptr, -C`. This matches the canonical form InstCombine already uses for plain `sub`. In wrapping arithmetic $old - C = old + (-C)$, so both the stored value and the returned old value stay the same, including when C is `INT_MIN`. Ordering, syncscope and metadata are kept. ```llvm ; before %old = atomicrmw sub ptr %p, i32 1 syncscope("agent") monotonic ; after %old = atomicrmw add ptr %p, i32 -1 syncscope("agent") monotonic ``` This benefits AMDGPU, for example: https://godbolt.org/z/fa9n1rPfq
Author
Parents
Loading