[InstCombine] invert canonicalization of sext (x > -1) --> not (ashr x)
authorSanjay Patel <spatel@rotateright.com>
Tue, 24 Jan 2023 21:01:37 +0000 (16:01 -0500)
committerSanjay Patel <spatel@rotateright.com>
Tue, 24 Jan 2023 21:44:15 +0000 (16:44 -0500)
commite44a305690add9f759d2fba85827bca260c94b41
tree037ea66aef49fb113c54708fde43abda181cb5b7
parent7ea998e3be78bcae1a988d311af71236b41d0bf9
[InstCombine] invert canonicalization of sext (x > -1) --> not (ashr x)

https://alive2.llvm.org/ce/z/2iC4oB

This is similar to changes made for zext + lshr:
21d3871b7c90
6c39a3aae1dc

The existing fold did not account for extra uses, so we
see some instruction count reductions in the test diffs.

This is intended to improve analysis (icmp likely has more
transforms than any other opcode), make other transforms
more symmetric with zext/lshr, and it can be inverted
in codegen if profitable.

As with the earlier changes, there is potential to uncover
infinite combine loops, but I have not found any yet.
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/X86/x86-masked-memops.ll
llvm/test/Transforms/InstCombine/and.ll
llvm/test/Transforms/InstCombine/bitcast-inseltpoison.ll
llvm/test/Transforms/InstCombine/bitcast.ll
llvm/test/Transforms/InstCombine/icmp.ll
llvm/test/Transforms/InstCombine/overflow-mul.ll
llvm/test/Transforms/InstCombine/vec_sext.ll
llvm/test/Transforms/InstCombine/xor-ashr.ll
llvm/test/Transforms/InstCombine/xor.ll