]> git.ipfire.org Git - thirdparty/gcc.git/commit
match: Fix A || B not optimized to true when !B implies A [PR114326]
authorKonstantinos Eleftheriou <konstantinos.eleftheriou@vrull.eu>
Wed, 7 Aug 2024 15:54:30 +0000 (17:54 +0200)
committerPhilipp Tomsich <philipp.tomsich@vrull.eu>
Wed, 25 Sep 2024 14:25:26 +0000 (16:25 +0200)
commita88d6c6d777ad7c9235e2e620318f26e5347e50a
tree8c606b0cce462459c9095d0c768a89ab5ee16d76
parent0e095df4b4c61bc57413cf3cbca56ff1a038de40
match: Fix A || B not optimized to true when !B implies A [PR114326]

In expressions like (a != b || ((a ^ b) & c) == d) and
(a != b || (a ^ b) == c), (a ^ b) is folded to false.
In the equivalent expressions (((a ^ b) & c) == d || a != b) and
((a ^ b) == c || a != b) this is not happening.

This patch adds the following simplifications in match.pd:
((a ^ b) & c) cmp d || a != b --> 0 cmp d || a != b
(a ^ b) cmp c || a != b --> 0 cmp c || a != b

PR tree-optimization/114326

gcc/ChangeLog:

* match.pd: Add two patterns to fold a ^ b to 0, when a == b.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/fold-xor-and-or.c: New test.
* gcc.dg/tree-ssa/fold-xor-or.c: New test.

Tested-by: Christoph Müllner <christoph.muellner@vrull.eu>
Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Signed-off-by: Konstantinos Eleftheriou <konstantinos.eleftheriou@vrull.eu>
gcc/match.pd
gcc/testsuite/gcc.dg/tree-ssa/fold-xor-and-or.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/fold-xor-or.c [new file with mode: 0644]