[llvm] [AMDGPU] Lower uniform uaddsat to SALU instructions (PR #210156)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 17 03:29:34 PDT 2026


LU-JOHN wrote:

> > Does [#203155 (comment)](https://github.com/llvm/llvm-project/pull/203155#issuecomment-4936521314) work?
> 
> It would be incorrect for the i16 case because SGPRs are 32 bits wide. Consider a = 0xF000, b = 0x2000.
> 
> min(add(a, b), 0xFFFF) = min(0x11000, 0xFFFF) = 0xFFFF add(min(a, ~b), b) = add(min(0xF000, 0xFFFFDFFF), 0x2000) = add(0xF000, 0x2000) = 0x11000.

Instead of using ~b, could we use xor(b, 0xFFFF), that is:
add(min(a, xor(b, 0xFFFF)), b)

https://github.com/llvm/llvm-project/pull/210156


More information about the llvm-commits mailing list