diff options
author | Richard Sandiford <richard.sandiford@arm.com> | 2025-03-04 10:44:35 +0000 |
---|---|---|
committer | Richard Sandiford <richard.sandiford@arm.com> | 2025-03-04 10:44:35 +0000 |
commit | 78380fd7f743e23dfdf013d68a2f0347e1511550 (patch) | |
tree | dc3efa7ba78270b62d73aa25c1c8c780ee8c2d7c /gcc | |
parent | 1ff01a88c484775fe8b5f1ca46fa24dfe0b14f3d (diff) | |
download | gcc-78380fd7f743e23dfdf013d68a2f0347e1511550.zip gcc-78380fd7f743e23dfdf013d68a2f0347e1511550.tar.gz gcc-78380fd7f743e23dfdf013d68a2f0347e1511550.tar.bz2 |
Fix folding of BIT_NOT_EXPR for POLY_INT_CST [PR118976]
There was an embarrassing typo in the folding of BIT_NOT_EXPR for
POLY_INT_CSTs: it used - rather than ~ on the poly_int. Not sure
how that happened, but it might have been due to the way that
~x is implemented as -1 - x internally.
gcc/
PR tree-optimization/118976
* fold-const.cc (const_unop): Use ~ rather than - for BIT_NOT_EXPR.
* config/aarch64/aarch64.cc (aarch64_test_sve_folding): New function.
(aarch64_run_selftests): Run it.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/config/aarch64/aarch64.cc | 11 | ||||
-rw-r--r-- | gcc/fold-const.cc | 2 |
2 files changed, 12 insertions, 1 deletions
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index fe76730..af3871c 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -31336,6 +31336,16 @@ aarch64_test_sysreg_encoding_clashes (void) } } +/* Test SVE arithmetic folding. */ + +static void +aarch64_test_sve_folding () +{ + tree res = fold_unary (BIT_NOT_EXPR, ssizetype, + ssize_int (poly_int64 (1, 1))); + ASSERT_TRUE (operand_equal_p (res, ssize_int (poly_int64 (-2, -1)))); +} + /* Run all target-specific selftests. */ static void @@ -31344,6 +31354,7 @@ aarch64_run_selftests (void) aarch64_test_loading_full_dump (); aarch64_test_fractional_cost (); aarch64_test_sysreg_encoding_clashes (); + aarch64_test_sve_folding (); } } // namespace selftest diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index f9f7f4d..fef7a6c 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -1964,7 +1964,7 @@ const_unop (enum tree_code code, tree type, tree arg0) if (TREE_CODE (arg0) == INTEGER_CST) return fold_not_const (arg0, type); else if (POLY_INT_CST_P (arg0)) - return wide_int_to_tree (type, -poly_int_cst_value (arg0)); + return wide_int_to_tree (type, ~poly_int_cst_value (arg0)); /* Perform BIT_NOT_EXPR on each element individually. */ else if (TREE_CODE (arg0) == VECTOR_CST) { |