aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-phiopt.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-03-09 19:13:11 +0100
committerJakub Jelinek <jakub@redhat.com>2021-03-09 19:13:11 +0100
commitb610c30453d8e4cc88693d85a5a100d089640be5 (patch)
treea7927f20db4d10668770625a9b0b59c447d676df /gcc/tree-ssa-phiopt.c
parentc60ad1c5fe0249f48362be0f989184ca447f9d17 (diff)
downloadgcc-b610c30453d8e4cc88693d85a5a100d089640be5.zip
gcc-b610c30453d8e4cc88693d85a5a100d089640be5.tar.gz
gcc-b610c30453d8e4cc88693d85a5a100d089640be5.tar.bz2
phiopt: Fix up conditional_replacement [PR99305]
Before my PR97690 changes, conditional_replacement would not set neg when the nonzero arg was boolean true. I've simplified the testing, so that it first finds the zero argument and then checks the other argument for all the handled cases (1, -1 and 1 << X, where the last case is what the patch added support for). But, unfortunately I've placed the integer_all_onesp test first. For unsigned precision 1 types such as bool integer_all_onesp, integer_onep and integer_pow2p can all be true and the code set neg to true in that case, which is undesirable. The following patch tests integer_pow2p first (which is trivially true for integer_onep too and tree_log2 in that case gives shift == 0) and only if that isn't the case, integer_all_onesp. 2021-03-09 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/99305 * tree-ssa-phiopt.c (conditional_replacement): Test integer_pow2p before integer_all_onesp instead of vice versa. * g++.dg/opt/pr99305.C: New test.
Diffstat (limited to 'gcc/tree-ssa-phiopt.c')
-rw-r--r--gcc/tree-ssa-phiopt.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index ddd9d53..aa48f44 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -808,14 +808,14 @@ conditional_replacement (basic_block cond_bb, basic_block middle_bb,
nonzero_arg = arg0;
else
return false;
- if (integer_all_onesp (nonzero_arg))
- neg = true;
- else if (integer_pow2p (nonzero_arg))
+ if (integer_pow2p (nonzero_arg))
{
shift = tree_log2 (nonzero_arg);
if (shift && POINTER_TYPE_P (TREE_TYPE (nonzero_arg)))
return false;
}
+ else if (integer_all_onesp (nonzero_arg))
+ neg = true;
else
return false;