[llvm] [AMDGPU] Improved Lowering of abs(i16) and -abs(i16) (PR #165626)

Patrick Simmons via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 31 22:28:11 PDT 2025


linuxrocks123 wrote:

> This doesn't really fit with the usual strategy for dealing with this sort of issue (it's sort of backwards). The usual strategy is something closer to treat the operation as legal, and deal with it later if it isn't.
> 
> There are a few options. What I suggest is to make ISD::ABS custom for i16. In the custom lowering, check if the input is divergent, return to use the default expansion.
> 
> That should get the right result most of the time. There's a possible edge case where SIFixVGPRCopies will need to deal s_abs_i16 with SGPR inputs

@arsenm have you looked at b83ae56e86356d5a47cff3878c1acdff2f6920de?  I think that earlier failed attempt is close to what you were suggesting.  Perhaps that earlier method could work better if I checked for whether the input is divergent as you suggested, so how would I go about checking whether the input is divergent?

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


More information about the llvm-commits mailing list