[InstCombine] canonicalize a signum (spaceship) that ends in add
authorSanjay Patel <spatel@rotateright.com>
Mon, 16 Jan 2023 17:34:26 +0000 (12:34 -0500)
committerSanjay Patel <spatel@rotateright.com>
Mon, 16 Jan 2023 17:47:21 +0000 (12:47 -0500)
commitdedc58da49c7a9d059cc4364ce737f6c7dc15569
tree62c3a465a9cf6ae6b5c86f5079a8713a3316d5bc
parent625e666d0e5af8022570abc12be0135735e50b27
[InstCombine] canonicalize a signum (spaceship) that ends in add

(A s>> (BW - 1)) + (zext (A s> 0)) --> (A s>> (BW - 1)) | (zext (A != 0))

https://alive2.llvm.org/ce/z/V-nM8N

This is not the form that we currently match as m_Signum(),
but I'm not sure if one is better than the other, so there's
a follow-up patch needed either way.

For this patch, it should be better for analysis to use a
not-null test and bitwise logic rather than >0 with add.
Codegen doesn't seem significantly different on any targets
that I looked at.

Also note that none of these variants is shown in issue #60012 -
those generally include at least one 'select', so that's likely
where these patterns will end up.
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/add.ll