]> git.ipfire.org Git - thirdparty/gcc.git/commit
[PATCH] match: simplify `VCE<bool>({0,1}) ==/!= 0` to `{0,1} ==/!= 0` [PR105749]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Mon, 6 Oct 2025 05:39:35 +0000 (22:39 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Mon, 27 Oct 2025 22:59:13 +0000 (15:59 -0700)
commit2f7edefc54e6967168c3cce3a4347cc0bc6a8155
tree39fdef6b1af82bc6dc0f952581f51756edd2c920
parent374ec67294fc4f66e87e88fa67d13ee829008559
[PATCH] match: simplify `VCE<bool>({0,1}) ==/!= 0` to `{0,1} ==/!= 0` [PR105749]

SRA likes to create VCE<bool>(a) when it comes to bool. This confuses
a few different passes including jump threading and uninitialization
warning. This removes the VCE in one case where it will help and when it
is known not to have any undefined behavior since the ranges of a is known
to be 0/1.

This implements similar was done for PR 80635 but without VRP's help; ccp
provides enough on the range/non-zeroness to implement this in match.

This will fix many of the std::optional reported warnings at -O1 too.
pr80635-[34].C are the same as pr80635-[12].C but compiled at -O1 rather
than just -O2.

PR tree-optimization/105749
PR tree-optimization/80635

gcc/ChangeLog:

* match.pd (`VCE<bool>(zero_one_valued_p) ==\!= 0`): New pattern.

gcc/testsuite/ChangeLog:

* g++.dg/warn/pr80635-3.C: New test.
* g++.dg/warn/pr80635-4.C: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/match.pd
gcc/testsuite/g++.dg/warn/pr80635-3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/pr80635-4.C [new file with mode: 0644]