[PATCH] Merge OR of ICMPs of single bit differences
Duncan Sands
baldrick at free.fr
Sat Apr 13 09:15:46 PDT 2013
Hi David,
On 13/04/13 00:31, David Majnemer wrote:
> This patch reorders two transforms that collide with each other:
>
> One performs: (X == 13 | X == 14) -> X-13 <u 2
> The other: (A == C1 || A == C2) -> (A & ~(C1 ^ C2)) == C1
>
> The problem is that there are certain values of C1 and C2 that trigger both
> transforms but the first one blocks out the second, this generates suboptimal code.
>
> Reordering the transforms should be better in every case and allows us to do
> interesting stuff like turn:
> %shr = lshr i32 %X, 4
> %and = and i32 %shr, 15
> %add = add i32 %and, -14
> %tobool = icmp ne i32 %add, 0
>
> into:
> %and = and i32 %X, 240
> %tobool = icmp ne i32 %and, 224
this seems reasonable to me. Another possibility is to recognize that some
forms of "X-13 <u 2" can be turned into "(A & ~(C1 ^ C2)) == C1", which would
catch hand-written cases of this coming straight from the original source code.
Personally I think you should apply your patch and maybe consider the second
possibility as an additional, future, optimization that could be implemented.
Ciao, Duncan.
More information about the llvm-commits
mailing list