Andrew Pinski <quic_apin...@quicinc.com> writes:

> When this pattern was converted from being only dealing with 0/-1, we missed 
> that if `e == f` is true
> then the optimization is wrong and needs an extra check for that.
>
> This changes the patterns to be:
> /* (a ? x : y) != (b ? x : y) --> (a^b & (x != y)) ? TRUE  : FALSE */
> /* (a ? x : y) == (b ? x : y) --> (a^b & (x != y)) ? FALSE : TRUE  */
> /* (a ? x : y) != (b ? y : x) --> (a^b | (x == y)) ? FALSE : TRUE  */
> /* (a ? x : y) == (b ? y : x) --> (a^b | (x == y)) ? TRUE  : FALSE */
>
> This still produces better code than the original case and in many cases (x 
> != y) will
> still reduce to either false or true.
>
> With this change we also need to make sure `a`, `b` and the resulting types 
> are all
> the same for the same reason as the previous patch.
>
> I updated (well added) to the testcases to make sure there are the right 
> amount of
> comparisons left.
>
> Bootstrapped and tested on x86_64-linux-gnu with no regressions.
>
>       PR tree-optimization/116120
>
> [...]
> diff --git a/gcc/testsuite/g++.dg/torture/pr116120-1.c 
> b/gcc/testsuite/g++.dg/torture/pr116120-1.c
> new file mode 100644
> index 00000000000..cffb7fbdc5b
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/torture/pr116120-1.c
> @@ -0,0 +1,32 @@
> +// { dg-run }

dg-do run! Ditto elsewhere.

> [...]

thanks,
sam

Attachment: signature.asc
Description: PGP signature

Reply via email to