]> gcc.gnu.org Git - gcc.git/commit
Fix PR 110954: wrong code with cmp | !cmp
authorAndrew Pinski <apinski@marvell.com>
Wed, 9 Aug 2023 20:49:24 +0000 (13:49 -0700)
committerAndrew Pinski <apinski@marvell.com>
Fri, 11 Aug 2023 06:51:07 +0000 (23:51 -0700)
commitf956c232649e4bb7482786cd54e5d5b4085cd00a
treeca36a466e6fcf6bba9662c833b2b1e46b5d90ac2
parent68783211f660a501dee203aec11dae99bf9808ba
Fix PR 110954: wrong code with cmp | !cmp

This was an oversight on my part forgetting that
cmp will might have a different true value than all ones
but will have a value of 1 in most cases.
This means if we have `(f < 0) | !(f < 0)` we would
optimize this to -1 rather than just 1.

This is version 2 of the patch.
Decided to go down a different route than just checking if
the precission was 1 inside bitwise_inverted_equal_p.
So instead bitwise_inverted_equal_p gets passed an argument
that will be set if there was a comparison that was being compared
and the user of bitwise_inverted_equal_p decides what needs to be done.
In most uses of bitwise_inverted_equal_p, the check will be
`!wascmp || element_precision (type) == 1` .
But in the case of `a & ~a` and `a ^| ~a` we can handle the case
of wascmp by using constant_boolean_node isntead.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

PR tree-optimization/110954

gcc/ChangeLog:

* generic-match-head.cc (bitwise_inverted_equal_p): Add
wascmp argument and set it accordingly.
* gimple-match-head.cc (bitwise_inverted_equal_p): Add
wascmp argument to the macro.
(gimple_bitwise_inverted_equal_p): Add
wascmp argument and set it accordingly.
* match.pd (`a & ~a`, `a ^| ~a`): Update call
to bitwise_inverted_equal_p and handle wascmp case.
(`(~x | y) & x`, `(~x | y) & x`, `a?~t:t`): Update
call to bitwise_inverted_equal_p and check to see
if was !wascmp or if precision was 1.

gcc/testsuite/ChangeLog:

* gcc.c-torture/execute/pr110954-1.c: New test.
gcc/generic-match-head.cc
gcc/gimple-match-head.cc
gcc/match.pd
gcc/testsuite/gcc.c-torture/execute/pr110954-1.c [new file with mode: 0644]
This page took 0.067653 seconds and 6 git commands to generate.