aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/class.c
diff options
context:
space:
mode:
authorRoger Sayle <roger@nextmovesoftware.com>2021-08-17 14:59:14 +0100
committerRoger Sayle <roger@nextmovesoftware.com>2021-08-17 14:59:14 +0100
commit897a15f355632bdc31871554892eca5512b3c370 (patch)
tree0dcb079fabc7c687f132b215ae4b97d4faab9729 /gcc/cp/class.c
parent408579c9c9b8fee20e1d8114489ce2b93872767c (diff)
downloadgcc-897a15f355632bdc31871554892eca5512b3c370.zip
gcc-897a15f355632bdc31871554892eca5512b3c370.tar.gz
gcc-897a15f355632bdc31871554892eca5512b3c370.tar.bz2
Improved handling of MINUS_EXPR in bit CCP.
This patch improves the bit bounds for MINUS_EXPR during tree-ssa's conditional constant propagation (CCP) pass (and as an added bonus adds support for POINTER_DIFF_EXPR). The pessimistic assumptions made by the current algorithm are demonstrated by considering 1 - (x&1). Intuitively this should have possible values 0 and 1, and therefore an unknown mask of 1. Alas by treating subtraction as a negation followed by addition, the second operand first becomes 0 or -1, with an unknown mask of all ones, which results in the addition containing no known bits. Improved bounds are achieved by using the same approach used for PLUS_EXPR, determining the result with the minimum number of borrows, the result from the maximum number of borrows, and examining the bits they have in common. One additional benefit of this approach is that it is applicable to POINTER_DIFF_EXPR, where previously the negation of a pointer didn't/doesn't make sense. A more convincing example, where a transformation missed by .032t.cpp isn't caught a few passes later by .038t.evrp, is the expression (7 - (x&5)) & 2, which (in the new test case) currently survives the tree-level optimizers but with this patch is now simplified to the constant value 2. 2021-08-17 Roger Sayle <roger@nextmovesoftware.com> gcc/ChangeLog * tree-ssa-ccp.c (bit_value_binop) [MINUS_EXPR]: Use same algorithm as PLUS_EXPR to improve subtraction bit bounds. [POINTER_DIFF_EXPR]: Treat as synonymous with MINUS_EXPR. gcc/testsuite/ChangeLog * gcc.dg/tree-ssa/ssa-ccp-40.c: New test case.
Diffstat (limited to 'gcc/cp/class.c')
0 files changed, 0 insertions, 0 deletions