aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.cc
diff options
context:
space:
mode:
authorAndrew Pinski <quic_apinski@quicinc.com>2023-11-11 15:54:10 -0800
committerAndrew Pinski <quic_apinski@quicinc.com>2023-12-11 07:55:54 -0800
commit85c5efcffed19ca6160eeecc2d4faebd9fee63aa (patch)
tree2956a87f3925de51b474b91a65298c71a0901f71 /gcc/fold-const.cc
parent4eaaf7f5a378e81bbcd180cb10bf58726a68f229 (diff)
downloadgcc-85c5efcffed19ca6160eeecc2d4faebd9fee63aa.zip
gcc-85c5efcffed19ca6160eeecc2d4faebd9fee63aa.tar.gz
gcc-85c5efcffed19ca6160eeecc2d4faebd9fee63aa.tar.bz2
MATCH: (convert)(zero_one !=/== 0/1) for outer type and zero_one type are the same
When I moved two_value to match.pd, I removed the check for the {0,+-1} as I had placed it after the {0,+-1} case for cond in match.pd. In the case of {0,+-1} and non boolean, before we would optmize those case to just `(convert)a` but after we would get `(convert)(a != 0)` which was not handled anyways to just `(convert)a`. So this adds a pattern to match `(convert)(zeroone != 0)` and simplify to `(convert)zeroone`. Also this optimizes (convert)(zeroone == 0) into (zeroone^1) if the type match. Removing the opposite transformation from fold. The opposite transformation was added with https://gcc.gnu.org/pipermail/gcc-patches/2006-February/190514.html It is no longer considered the canonicalization either, even VRP will transform it back into `(~a) & 1` so removing it is a good idea. Note the testcase pr69270.c needed a slight update due to not matching exactly a scan pattern, this update makes it more robust and will match before and afterwards and if there are other changes in this area too. Note the testcase gcc.target/i386/pr110790-2.c needs a slight update for better code generation in LP64 bit mode. Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR tree-optimization/111972 PR tree-optimization/110637 * match.pd (`(convert)(zeroone !=/== CST)`): Match and simplify to ((convert)zeroone){,^1}. * fold-const.cc (fold_binary_loc): Remove transformation of `(~a) & 1` and `(a ^ 1) & 1` into `(convert)(a == 0)`. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr110637-1.c: New test. * gcc.dg/tree-ssa/pr110637-2.c: New test. * gcc.dg/tree-ssa/pr110637-3.c: New test. * gcc.dg/tree-ssa/pr111972-1.c: New test. * gcc.dg/tree-ssa/pr69270.c: Update testcase. * gcc.target/i386/pr110790-2.c: Update testcase. * gcc.dg/fold-even-1.c: Removed. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Diffstat (limited to 'gcc/fold-const.cc')
-rw-r--r--gcc/fold-const.cc27
1 files changed, 0 insertions, 27 deletions
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 2692b98..f5d68ac 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -12077,33 +12077,6 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
goto bit_rotate;
case BIT_AND_EXPR:
- /* Fold (X ^ 1) & 1 as (X & 1) == 0. */
- if (TREE_CODE (arg0) == BIT_XOR_EXPR
- && INTEGRAL_TYPE_P (type)
- && integer_onep (TREE_OPERAND (arg0, 1))
- && integer_onep (arg1))
- {
- tree tem2;
- tem = TREE_OPERAND (arg0, 0);
- tem2 = fold_convert_loc (loc, TREE_TYPE (tem), arg1);
- tem2 = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (tem),
- tem, tem2);
- return fold_build2_loc (loc, EQ_EXPR, type, tem2,
- build_zero_cst (TREE_TYPE (tem)));
- }
- /* Fold ~X & 1 as (X & 1) == 0. */
- if (TREE_CODE (arg0) == BIT_NOT_EXPR
- && INTEGRAL_TYPE_P (type)
- && integer_onep (arg1))
- {
- tree tem2;
- tem = TREE_OPERAND (arg0, 0);
- tem2 = fold_convert_loc (loc, TREE_TYPE (tem), arg1);
- tem2 = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (tem),
- tem, tem2);
- return fold_build2_loc (loc, EQ_EXPR, type, tem2,
- build_zero_cst (TREE_TYPE (tem)));
- }
/* Fold !X & 1 as X == 0. */
if (TREE_CODE (arg0) == TRUTH_NOT_EXPR
&& integer_onep (arg1))