https://gcc.gnu.org/g:540cb6b0dd2a9ece734e927d520a9ca15e8afff8
commit 540cb6b0dd2a9ece734e927d520a9ca15e8afff8 Author: Mikael Morin <mik...@gcc.gnu.org> Date: Thu Jul 4 12:59:34 2024 +0200 match: Simplify double not and double negate to a non_lvalue gcc/ChangeLog: * match.pd: Add a NON_LVALUE_EXPR wrapper around the simplification of doubled unary operators NEGATE_EXPR and BIT_NOT_EXPR. gcc/testsuite/ChangeLog: * gfortran.dg/non_lvalue_1.f90: New test. Diff: --- gcc/match.pd | 4 ++-- gcc/testsuite/gfortran.dg/non_lvalue_1.f90 | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 4edfa2ae2c9..d0859545ada 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2294,7 +2294,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* ~~x -> x */ (simplify (bit_not (bit_not @0)) - @0) + (non_lvalue @0)) /* zero_one_valued_p will match when a value is known to be either 0 or 1 including constants 0 or 1. @@ -3674,7 +3674,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (negate (nop_convert? (negate @1))) (if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_SANITIZED (TREE_TYPE (@1))) - (view_convert @1))) + (non_lvalue (view_convert @1)))) /* We can't reassociate floating-point unless -fassociative-math or fixed-point plus or minus because of saturation to +-Inf. */ diff --git a/gcc/testsuite/gfortran.dg/non_lvalue_1.f90 b/gcc/testsuite/gfortran.dg/non_lvalue_1.f90 new file mode 100644 index 00000000000..ac52b272094 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/non_lvalue_1.f90 @@ -0,0 +1,21 @@ +! { dg-do compile } +! { dg-additional-options "-fdump-tree-original" } +! +! Check the generation of NON_LVALUE_EXPR trees in cases where a unary operator expression +! simplifies to a data reference. + +! A NON_LVALUE_EXPR is generated for a double negation that simplifies to a data reference. */ +function f1 (f1_arg1) + integer, value :: f1_arg1 + integer :: f1 + f1 = -(-f1_arg1) +end function +! { dg-final { scan-tree-dump "__result_f1 = NON_LVALUE_EXPR <f1_arg1>;" "original" } } + +! A NON_LVALUE_EXPR is generated for a double complement that simplifies to a data reference. */ +function f2 (f2_arg1) + integer, value :: f2_arg1 + integer :: f2 + f2 = not(not(f2_arg1)) +end function +! { dg-final { scan-tree-dump "__result_f2 = NON_LVALUE_EXPR <f2_arg1>;" "original" } }