Hi David and others,
  I am in the process of improving phi-opt and moving what was handled
in value_replacement to match-and-simplify and ran into a few failures
in the analyzer testsuite.
For an example c-c++-common/analyzer/inlining-3-multiline.c (and
c-c++-common/analyzer/inlining-3.c) now fails due to optimizing away
the if statement in get_input_file_name so it just returns its
argument and we don't get a comparison against NULL any more.

Should we change the testcase to avoid this transformation or should
we avoid this transformation early on during optimization phases? Or
something else like move analyzer earlier before phiopt?

Attached is the patch which shows the 2 testsuite failures. I have not
done a full bootstrap with it; just a build and run the testsuite.

Thanks,
Andrew
From 02324ac702fb5e39ccfdbd4910b5240762679593 Mon Sep 17 00:00:00 2001
From: Andrew Pinski <pins...@gmail.com>
Date: Thu, 26 Oct 2023 16:06:33 -0700
Subject: [PATCH] MATCH: Move jump_function_from_stmt support to match.pd

This moves the value_replacement support for jump_function_from_stmt
to match pattern.
This allows us to optimize things earlier in phiopt1 rather than waiting
to phiopt2. Which means phiopt1 needs to be disable for vrp03.c testcase.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

        * match.pd (PTR == 0 ? 0 : &PTR->field): New pattern.

gcc/testsuite/ChangeLog:

        * gcc.dg/tree-ssa/vrp03.c: Disable phiopt1.
---
 gcc/match.pd                          | 21 +++++++++++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/vrp03.c |  2 +-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index eed3083a827..eebd64b24ad 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4135,6 +4135,27 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (cond (eq @0 integer_zerop) @1 (op@2 @1 @0))
    @2))
 
+/* PTR == 0 ? 0 : &PTR->field -> PTR if field offset was 0. */
+(simplify
+ (cond (eq @0 integer_zerop) integer_zerop ADDR_EXPR@1)
+ (with {
+   poly_int64 offset;
+   tree res = NULL_TREE;
+   tree tem = @1;
+   if (TREE_CODE (tem) == SSA_NAME)
+     if (gassign *def = dyn_cast <gassign *> (SSA_NAME_DEF_STMT (tem)))
+       if (gimple_assign_rhs_code (def) == ADDR_EXPR)
+         tem = gimple_assign_rhs1 (def);
+
+   if (TREE_CODE (tem) == ADDR_EXPR)
+     res = get_addr_base_and_unit_offset (TREE_OPERAND (tem, 0), &offset);
+  }
+  (if (res
+       && TREE_CODE (res) == MEM_REF
+       && known_eq (mem_ref_offset (res) + offset, 0)
+       && operand_equal_p (TREE_OPERAND (res, 0), @0))
+   (convert @0))))
+
 /* Simplifications of shift and rotates.  */
 
 (for rotate (lrotate rrotate)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp03.c 
b/gcc/testsuite/gcc.dg/tree-ssa/vrp03.c
index 4cbaca41332..1adbf33cad3 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/vrp03.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp03.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdisable-tree-evrp -fdump-tree-vrp1 -fno-thread-jumps" } 
*/
+/* { dg-options "-O2 -fdisable-tree-evrp -fdump-tree-vrp1 -fno-thread-jumps 
-fdisable-tree-phiopt1" } */
 
 struct A
 {
-- 
2.39.3

Reply via email to