match.pd: Improve conditional_replacement for x ? 0 : -1 [PR796232]
authorJakub Jelinek <jakub@redhat.com>
Sun, 6 Dec 2020 09:55:12 +0000 (10:55 +0100)
committerJakub Jelinek <jakub@redhat.com>
Sun, 6 Dec 2020 09:55:12 +0000 (10:55 +0100)
commit9e12b8b1819342ef7efac58cf7f4ba4294abe551
treee85728c3ca27665a12469a0206a08fd0869b6ff3
parentbd0f0243869b3941a256ca0ea9c8aca141412f7e
match.pd: Improve conditional_replacement for x ? 0 : -1 [PR796232]

As mentioned in the PR, for boolean x we currently optimize
in phiopt x ? 0 : -1 into -(int)!x but it can be optimized as
(int) x - 1 which is one less operation both in GIMPLE and in x86 assembly.

This patch optimizes it in match.pd, by optimizing -(type)!x when
x has boolean range into (type)x - 1.

2020-12-06  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/96232
* match.pd (-(type)!A -> (type)A - 1): New optimization.

* gcc.dg/tree-ssa/pr96232-1.c: New test.
gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/pr96232-1.c [new file with mode: 0644]