public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/3] start of moving value replacement from phiopt to match
@ 2023-10-29 16:40 Andrew Pinski
  2023-10-29 16:40 ` [PATCH 1/3] MATCH: first of the value replacement moving from phiopt Andrew Pinski
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Andrew Pinski @ 2023-10-29 16:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew Pinski

This set of 3 patches, copy what is being done in value replacement and
puts it into match-and-simplify form. I will be rewriting value_replacement
in phiopt to use match and simplify directly in the next few months but
I thought getting these into match form earlier on can help improve code
generation independently of that move.

Note this does not add the absorbing_element_p optimizations yet; I filed PR 112271
to record that move.

Andrew Pinski (3):
  MATCH: first of the value replacement moving from phiopt
  MATCH: Move jump_function_from_stmt support to match.pd
  MATCH: Add some more value_replacement simplifications to match

 gcc/match.pd                                  | 53 +++++++++++++++++++
 .../analyzer/inlining-3-multiline.c           |  5 +-
 .../c-c++-common/analyzer/inlining-3.c        |  3 ++
 gcc/testsuite/gcc.dg/tree-ssa/cond-1.c        | 17 ++++++
 .../gcc.dg/tree-ssa/phi-opt-value-1.c         | 17 ++++++
 .../gcc.dg/tree-ssa/phi-opt-value-1a.c        | 19 +++++++
 .../gcc.dg/tree-ssa/phi-opt-value-2.c         | 19 +++++++
 .../gcc.dg/tree-ssa/phi-opt-value-3.c         | 22 ++++++++
 .../gcc.dg/tree-ssa/phi-opt-value-4.c         | 36 +++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/vrp03.c         |  2 +-
 10 files changed, 191 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/cond-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1a.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-2.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-4.c

-- 
2.39.3


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] MATCH: first of the value replacement moving from phiopt
  2023-10-29 16:40 [PATCH 0/3] start of moving value replacement from phiopt to match Andrew Pinski
@ 2023-10-29 16:40 ` Andrew Pinski
  2023-10-30  9:32   ` Richard Biener
  2023-10-29 16:40 ` [PATCH 2/3] MATCH: Move jump_function_from_stmt support to match.pd Andrew Pinski
  2023-10-29 16:40 ` [PATCH 3/3] MATCH: Add some more value_replacement simplifications to match Andrew Pinski
  2 siblings, 1 reply; 8+ messages in thread
From: Andrew Pinski @ 2023-10-29 16:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew Pinski

This moves a few simple patterns that are done in value replacement
in phiopt over to match.pd. Just the simple ones which might show up
in other code.

This allows some optimizations to happen even without depending
on sinking from happening and in some cases where phiopt is not
invoked (cond-1.c is an example there).

Changes since v1:
* v2: Add an extra testcase to showcase improvements at -O1.

Bootstrapped and tested on x86_64-linux-gnu with no regressions.

gcc/ChangeLog:

	* match.pd: (`a == 0 ? b : b + a`,
	`a == 0 ? b : b - a`): New patterns.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/cond-1.c: New test.
	* gcc.dg/tree-ssa/phi-opt-value-1.c: New test.
	* gcc.dg/tree-ssa/phi-opt-value-1a.c: New test.
	* gcc.dg/tree-ssa/phi-opt-value-2.c: New test.
---
 gcc/match.pd                                  | 14 ++++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/cond-1.c        | 17 +++++++++++++++++
 .../gcc.dg/tree-ssa/phi-opt-value-1.c         | 17 +++++++++++++++++
 .../gcc.dg/tree-ssa/phi-opt-value-1a.c        | 19 +++++++++++++++++++
 .../gcc.dg/tree-ssa/phi-opt-value-2.c         | 19 +++++++++++++++++++
 5 files changed, 86 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/cond-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1a.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-2.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 7d651a6582d..22899c51a2f 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4145,6 +4145,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        && (INTEGRAL_TYPE_P (TREE_TYPE (@0))))
        (op (mult (convert:type @0) @2) @1))))
 
+/* ?: Value replacement. */
+/* a == 0 ? b : b + a  -> b + a */
+(for op (plus bit_ior bit_xor)
+ (simplify
+  (cond (eq @0 integer_zerop) @1 (op:c@2 @1 @0))
+   @2))
+/* a == 0 ? b : b - a  -> b - a */
+/* a == 0 ? b : b ptr+ a  -> b ptr+ a */
+/* a == 0 ? b : b shift/rotate a -> b shift/rotate a */
+(for op (lrotate rrotate lshift rshift minus pointer_plus)
+ (simplify
+  (cond (eq @0 integer_zerop) @1 (op@2 @1 @0))
+   @2))
+
 /* Simplifications of shift and rotates.  */
 
 (for rotate (lrotate rrotate)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cond-1.c b/gcc/testsuite/gcc.dg/tree-ssa/cond-1.c
new file mode 100644
index 00000000000..478a818b206
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/cond-1.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized-raw" } */
+
+int sub(int a, int b, int c, int d) {
+  int e = (a == 0);
+  int f = !e;
+  c = b;
+  d = b - a ;
+  return ((-e & c) | (-f & d));
+}
+
+/* In the end we end up with `(a == 0) ? (b - a) : b`
+   which then can be optimized to just `(b - a)`. */
+
+/* { dg-final { scan-tree-dump-not "cond_expr," "optimized" } } */
+/* { dg-final { scan-tree-dump-not "eq_expr," "optimized" } } */
+/* { dg-final { scan-tree-dump-times "minus_expr," 1 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1.c
new file mode 100644
index 00000000000..a90de8926c6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* Phi-OPT should be able to optimize this without sinking being invoked. */
+/* { dg-options "-O -fdump-tree-phiopt2 -fdump-tree-optimized -fno-tree-sink" } */
+
+char *f(char *a, __SIZE_TYPE__ b) {
+  char *d = a + b;
+  if (b == 0) return a;
+  return d;
+}
+int sub(int a, int b, int c) {
+  int d = a - b;
+  if (b == 0) return a;
+  return d;
+}
+
+/* { dg-final { scan-tree-dump-not "goto" "phiopt2" } } */
+/* { dg-final { scan-tree-dump-not "goto" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1a.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1a.c
new file mode 100644
index 00000000000..b884f94ddd2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1a.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+[[gnu::const]]
+int constcall(int);
+
+int f(int a, int b)
+{
+  int c = b+a;
+  int t = constcall(c);
+  int d;
+  if (a == 0) d= b; else d= c;
+  return constcall(d) + t;
+}
+
+/* There should be no if statement and 2 calls to call1. */
+/* { dg-final { scan-tree-dump-not "if " "optimized" } } */
+/* { dg-final { scan-tree-dump-times "constcall " 1 "optimized" } } */
+
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-2.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-2.c
new file mode 100644
index 00000000000..809ccfe1479
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-2.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* Phi-OPT should be able to optimize this without sinking being invoked. */
+/* { dg-options "-O -fdump-tree-phiopt2 -fdump-tree-optimized -fno-tree-sink" } */
+
+int f(int a, int b, int c) {
+  int d = a + b;
+  if (c > 5) return c;
+  if (a == 0) return b;
+  return d;
+}
+
+unsigned rot(unsigned x, int n) {
+  const int bits = __CHAR_BIT__ * __SIZEOF_INT__;
+  int t = ((x << n) | (x >> (bits - n)));
+  return (n == 0) ? x : t;
+}
+
+/* { dg-final { scan-tree-dump-times "goto" 2 "phiopt2" } } */
+/* { dg-final { scan-tree-dump-times "goto" 2 "optimized" } } */
-- 
2.39.3


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/3] MATCH: Move jump_function_from_stmt support to match.pd
  2023-10-29 16:40 [PATCH 0/3] start of moving value replacement from phiopt to match Andrew Pinski
  2023-10-29 16:40 ` [PATCH 1/3] MATCH: first of the value replacement moving from phiopt Andrew Pinski
@ 2023-10-29 16:40 ` Andrew Pinski
  2023-10-30  9:29   ` Richard Biener
  2023-10-29 16:40 ` [PATCH 3/3] MATCH: Add some more value_replacement simplifications to match Andrew Pinski
  2 siblings, 1 reply; 8+ messages in thread
From: Andrew Pinski @ 2023-10-29 16:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew Pinski

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.
	* c-c++-common/analyzer/inlining-3-multiline.c: Likewise.
	* c-c++-common/analyzer/inlining-3.c: Likewise.
	* gcc.dg/tree-ssa/phi-opt-value-3.c: New testcase.
---
 gcc/match.pd                                  | 21 ++++++++++++++++++
 .../analyzer/inlining-3-multiline.c           |  5 ++++-
 .../c-c++-common/analyzer/inlining-3.c        |  3 +++
 .../gcc.dg/tree-ssa/phi-opt-value-3.c         | 22 +++++++++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/vrp03.c         |  2 +-
 5 files changed, 51 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 22899c51a2f..9bc945ccada 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4159,6 +4159,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/c-c++-common/analyzer/inlining-3-multiline.c b/gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c
index fbd20e949b6..9741b91abee 100644
--- a/gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c
+++ b/gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c
@@ -3,6 +3,9 @@
 
 /* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
 /* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
+/* Disable phi-opt1 because get_input_file_name gets optimized to just
+   `return inpf;`. */
+/* { dg-additional-options "-fdisable-tree-phiopt1" } */
 
 #include "../../gcc.dg/analyzer/analyzer-decls.h"
 typedef __SIZE_TYPE__ size_t;
@@ -96,4 +99,4 @@ test (const input_file *inpf)
     |                           (4) ...to here
     |                           (5) argument 1 ('<unknown>') NULL where non-null expected
     |
-   { dg-end-multiline-output "" { target c++ } } */
\ No newline at end of file
+   { dg-end-multiline-output "" { target c++ } } */
diff --git a/gcc/testsuite/c-c++-common/analyzer/inlining-3.c b/gcc/testsuite/c-c++-common/analyzer/inlining-3.c
index 0345585bed2..2b2b4858d45 100644
--- a/gcc/testsuite/c-c++-common/analyzer/inlining-3.c
+++ b/gcc/testsuite/c-c++-common/analyzer/inlining-3.c
@@ -2,6 +2,9 @@
    after early inlining.  */
 
 /* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
+/* Disable phi-opt1 because get_input_file_name gets optimized to just
+   `return inpf;`. */
+/* { dg-additional-options "-fdisable-tree-phiopt1" } */
 
 #include "../../gcc.dg/analyzer/analyzer-decls.h"
 typedef __SIZE_TYPE__ size_t;
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c
new file mode 100644
index 00000000000..ad55bd288b9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c
@@ -0,0 +1,22 @@
+/* { dg-do compile }  */
+/* { dg-options "-O1 -fdump-tree-optimized" }  */
+struct a
+{
+        int b[1];
+};
+
+int call1(int *a);
+
+int f(struct a *b)
+{
+  int *c = b->b;
+  int t = call1(c);
+  int *d;
+  if (b) d = b->b; else d = 0;
+  int t1 = call1(d);
+  return t+t1;
+}
+
+/* There should be no if statement and 2 calls to call1. */
+/* { dg-final { scan-tree-dump-not "if " "optimized" } } */
+/* { dg-final { scan-tree-dump-times "call1 " 2 "optimized"  } } */
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/3] MATCH: Add some more value_replacement simplifications to match
  2023-10-29 16:40 [PATCH 0/3] start of moving value replacement from phiopt to match Andrew Pinski
  2023-10-29 16:40 ` [PATCH 1/3] MATCH: first of the value replacement moving from phiopt Andrew Pinski
  2023-10-29 16:40 ` [PATCH 2/3] MATCH: Move jump_function_from_stmt support to match.pd Andrew Pinski
@ 2023-10-29 16:40 ` Andrew Pinski
  2023-10-30  9:30   ` Richard Biener
  2 siblings, 1 reply; 8+ messages in thread
From: Andrew Pinski @ 2023-10-29 16:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew Pinski

This moves a few more value_replacements simplifications to match.
/* a == 1 ? b : a * b -> a * b */
/* a == 1 ? b : b / a  -> b / a */
/* a == -1 ? b : a & b -> a & b */

Also adds a testcase to show can we catch these where value_replacement would not
(but other passes would).

Bootstrapped and tested on x86_64-linux-gnu with no regressions.

gcc/ChangeLog:

	* match.pd (`a == 1 ? b : a OP b`): New pattern.
	(`a == -1 ? b : a & b`): New pattern.

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/phi-opt-value-4.c: New test.
---
 gcc/match.pd                                  | 18 ++++++++++
 .../gcc.dg/tree-ssa/phi-opt-value-4.c         | 36 +++++++++++++++++++
 2 files changed, 54 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-4.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 9bc945ccada..6efa97cc6ae 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4159,6 +4159,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (cond (eq @0 integer_zerop) @1 (op@2 @1 @0))
    @2))
 
+/* a == 1 ? b : b / a  -> b / a */
+(for op (trunc_div ceil_div floor_div round_div exact_div)
+ (simplify
+  (cond (eq @0 integer_onep) @1 (op@2 @1 @0))
+   @2))
+
+/* a == 1 ? b : a * b -> a * b */
+(for op (mult)
+ (simplify
+  (cond (eq @0 integer_onep) @1 (op:c@2 @1 @0))
+   @2))
+
+/* a == -1 ? b : a & b -> a & b */
+(for op (bit_and)
+ (simplify
+  (cond (eq @0 integer_all_onesp) @1 (op:c@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)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-4.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-4.c
new file mode 100644
index 00000000000..380082cb463
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-4.c
@@ -0,0 +1,36 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-fre3 -fdump-tree-phiopt1 -fdump-tree-optimized" } */
+
+[[gnu::const]]
+int constcall(int);
+
+int fdiv(int a, int b)
+{
+  int c = b/a;
+  int t = constcall(c);
+  int d;
+  if (a == 1) d = b; else d = c;
+  return constcall(d) + t;
+}
+int fmult(int a, int b)
+{
+  int c = b*a;
+  int t = constcall(c);
+  int d;
+  if (a == 1) d = b; else d = c;
+  return constcall(d) + t;
+}
+int fand(int a, int b)
+{
+  int c = b&a;
+  int t = constcall(c);
+  int d;
+  if (a == -1) d = b; else d = c;
+  return constcall(d) + t;
+}
+
+/* Should be able to optimize away the if statements in phiopt1. */
+/* { dg-final { scan-tree-dump-not "if " "phiopt1" } } */
+/* fre3 should be optimize each function to just `return constcall(a OP b) * 2;`. */
+/* { dg-final { scan-tree-dump-times "constcall " 3 "fre3" } } */
+/* { dg-final { scan-tree-dump-times "constcall " 3 "optimized" } } */
-- 
2.39.3


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] MATCH: Move jump_function_from_stmt support to match.pd
  2023-10-29 16:40 ` [PATCH 2/3] MATCH: Move jump_function_from_stmt support to match.pd Andrew Pinski
@ 2023-10-30  9:29   ` Richard Biener
  2023-10-30 20:36     ` Andrew Pinski
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Biener @ 2023-10-30  9:29 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-patches

On Sun, Oct 29, 2023 at 5:41 PM Andrew Pinski <pinskia@gmail.com> wrote:
>
> 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.

Do we need to make sure to only do this after pass_early_object_sizes
at least?  IIRC early PHI-opt didn't do value-replacement, so maybe
even after late object-size?  There's PROP_objsz, but no
function similar to optimize_vectors_before_lowering_p in
{generic,gimple}-match-head.cc

Richard.

> gcc/ChangeLog:
>
>         * match.pd (PTR == 0 ? 0 : &PTR->field): New pattern.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.dg/tree-ssa/vrp03.c: Disable phiopt1.
>         * c-c++-common/analyzer/inlining-3-multiline.c: Likewise.
>         * c-c++-common/analyzer/inlining-3.c: Likewise.
>         * gcc.dg/tree-ssa/phi-opt-value-3.c: New testcase.
> ---
>  gcc/match.pd                                  | 21 ++++++++++++++++++
>  .../analyzer/inlining-3-multiline.c           |  5 ++++-
>  .../c-c++-common/analyzer/inlining-3.c        |  3 +++
>  .../gcc.dg/tree-ssa/phi-opt-value-3.c         | 22 +++++++++++++++++++
>  gcc/testsuite/gcc.dg/tree-ssa/vrp03.c         |  2 +-
>  5 files changed, 51 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 22899c51a2f..9bc945ccada 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -4159,6 +4159,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/c-c++-common/analyzer/inlining-3-multiline.c b/gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c
> index fbd20e949b6..9741b91abee 100644
> --- a/gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c
> +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c
> @@ -3,6 +3,9 @@
>
>  /* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
>  /* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
> +/* Disable phi-opt1 because get_input_file_name gets optimized to just
> +   `return inpf;`. */
> +/* { dg-additional-options "-fdisable-tree-phiopt1" } */
>
>  #include "../../gcc.dg/analyzer/analyzer-decls.h"
>  typedef __SIZE_TYPE__ size_t;
> @@ -96,4 +99,4 @@ test (const input_file *inpf)
>      |                           (4) ...to here
>      |                           (5) argument 1 ('<unknown>') NULL where non-null expected
>      |
> -   { dg-end-multiline-output "" { target c++ } } */
> \ No newline at end of file
> +   { dg-end-multiline-output "" { target c++ } } */
> diff --git a/gcc/testsuite/c-c++-common/analyzer/inlining-3.c b/gcc/testsuite/c-c++-common/analyzer/inlining-3.c
> index 0345585bed2..2b2b4858d45 100644
> --- a/gcc/testsuite/c-c++-common/analyzer/inlining-3.c
> +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-3.c
> @@ -2,6 +2,9 @@
>     after early inlining.  */
>
>  /* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
> +/* Disable phi-opt1 because get_input_file_name gets optimized to just
> +   `return inpf;`. */
> +/* { dg-additional-options "-fdisable-tree-phiopt1" } */
>
>  #include "../../gcc.dg/analyzer/analyzer-decls.h"
>  typedef __SIZE_TYPE__ size_t;
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c
> new file mode 100644
> index 00000000000..ad55bd288b9
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c
> @@ -0,0 +1,22 @@
> +/* { dg-do compile }  */
> +/* { dg-options "-O1 -fdump-tree-optimized" }  */
> +struct a
> +{
> +        int b[1];
> +};
> +
> +int call1(int *a);
> +
> +int f(struct a *b)
> +{
> +  int *c = b->b;
> +  int t = call1(c);
> +  int *d;
> +  if (b) d = b->b; else d = 0;
> +  int t1 = call1(d);
> +  return t+t1;
> +}
> +
> +/* There should be no if statement and 2 calls to call1. */
> +/* { dg-final { scan-tree-dump-not "if " "optimized" } } */
> +/* { dg-final { scan-tree-dump-times "call1 " 2 "optimized"  } } */
> 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
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] MATCH: Add some more value_replacement simplifications to match
  2023-10-29 16:40 ` [PATCH 3/3] MATCH: Add some more value_replacement simplifications to match Andrew Pinski
@ 2023-10-30  9:30   ` Richard Biener
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Biener @ 2023-10-30  9:30 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-patches

On Sun, Oct 29, 2023 at 5:41 PM Andrew Pinski <pinskia@gmail.com> wrote:
>
> This moves a few more value_replacements simplifications to match.
> /* a == 1 ? b : a * b -> a * b */
> /* a == 1 ? b : b / a  -> b / a */
> /* a == -1 ? b : a & b -> a & b */
>
> Also adds a testcase to show can we catch these where value_replacement would not
> (but other passes would).
>
> Bootstrapped and tested on x86_64-linux-gnu with no regressions.

OK.

> gcc/ChangeLog:
>
>         * match.pd (`a == 1 ? b : a OP b`): New pattern.
>         (`a == -1 ? b : a & b`): New pattern.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.dg/tree-ssa/phi-opt-value-4.c: New test.
> ---
>  gcc/match.pd                                  | 18 ++++++++++
>  .../gcc.dg/tree-ssa/phi-opt-value-4.c         | 36 +++++++++++++++++++
>  2 files changed, 54 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-4.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 9bc945ccada..6efa97cc6ae 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -4159,6 +4159,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>    (cond (eq @0 integer_zerop) @1 (op@2 @1 @0))
>     @2))
>
> +/* a == 1 ? b : b / a  -> b / a */
> +(for op (trunc_div ceil_div floor_div round_div exact_div)
> + (simplify
> +  (cond (eq @0 integer_onep) @1 (op@2 @1 @0))
> +   @2))
> +
> +/* a == 1 ? b : a * b -> a * b */
> +(for op (mult)
> + (simplify
> +  (cond (eq @0 integer_onep) @1 (op:c@2 @1 @0))
> +   @2))
> +
> +/* a == -1 ? b : a & b -> a & b */
> +(for op (bit_and)
> + (simplify
> +  (cond (eq @0 integer_all_onesp) @1 (op:c@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)
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-4.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-4.c
> new file mode 100644
> index 00000000000..380082cb463
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-4.c
> @@ -0,0 +1,36 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O1 -fdump-tree-fre3 -fdump-tree-phiopt1 -fdump-tree-optimized" } */
> +
> +[[gnu::const]]
> +int constcall(int);
> +
> +int fdiv(int a, int b)
> +{
> +  int c = b/a;
> +  int t = constcall(c);
> +  int d;
> +  if (a == 1) d = b; else d = c;
> +  return constcall(d) + t;
> +}
> +int fmult(int a, int b)
> +{
> +  int c = b*a;
> +  int t = constcall(c);
> +  int d;
> +  if (a == 1) d = b; else d = c;
> +  return constcall(d) + t;
> +}
> +int fand(int a, int b)
> +{
> +  int c = b&a;
> +  int t = constcall(c);
> +  int d;
> +  if (a == -1) d = b; else d = c;
> +  return constcall(d) + t;
> +}
> +
> +/* Should be able to optimize away the if statements in phiopt1. */
> +/* { dg-final { scan-tree-dump-not "if " "phiopt1" } } */
> +/* fre3 should be optimize each function to just `return constcall(a OP b) * 2;`. */
> +/* { dg-final { scan-tree-dump-times "constcall " 3 "fre3" } } */
> +/* { dg-final { scan-tree-dump-times "constcall " 3 "optimized" } } */
> --
> 2.39.3
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] MATCH: first of the value replacement moving from phiopt
  2023-10-29 16:40 ` [PATCH 1/3] MATCH: first of the value replacement moving from phiopt Andrew Pinski
@ 2023-10-30  9:32   ` Richard Biener
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Biener @ 2023-10-30  9:32 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-patches

On Sun, Oct 29, 2023 at 5:41 PM Andrew Pinski <pinskia@gmail.com> wrote:
>
> This moves a few simple patterns that are done in value replacement
> in phiopt over to match.pd. Just the simple ones which might show up
> in other code.
>
> This allows some optimizations to happen even without depending
> on sinking from happening and in some cases where phiopt is not
> invoked (cond-1.c is an example there).
>
> Changes since v1:
> * v2: Add an extra testcase to showcase improvements at -O1.
>
> Bootstrapped and tested on x86_64-linux-gnu with no regressions.

OK.

> gcc/ChangeLog:
>
>         * match.pd: (`a == 0 ? b : b + a`,
>         `a == 0 ? b : b - a`): New patterns.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.dg/tree-ssa/cond-1.c: New test.
>         * gcc.dg/tree-ssa/phi-opt-value-1.c: New test.
>         * gcc.dg/tree-ssa/phi-opt-value-1a.c: New test.
>         * gcc.dg/tree-ssa/phi-opt-value-2.c: New test.
> ---
>  gcc/match.pd                                  | 14 ++++++++++++++
>  gcc/testsuite/gcc.dg/tree-ssa/cond-1.c        | 17 +++++++++++++++++
>  .../gcc.dg/tree-ssa/phi-opt-value-1.c         | 17 +++++++++++++++++
>  .../gcc.dg/tree-ssa/phi-opt-value-1a.c        | 19 +++++++++++++++++++
>  .../gcc.dg/tree-ssa/phi-opt-value-2.c         | 19 +++++++++++++++++++
>  5 files changed, 86 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/cond-1.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1a.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-2.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 7d651a6582d..22899c51a2f 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -4145,6 +4145,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>         && (INTEGRAL_TYPE_P (TREE_TYPE (@0))))
>         (op (mult (convert:type @0) @2) @1))))
>
> +/* ?: Value replacement. */
> +/* a == 0 ? b : b + a  -> b + a */
> +(for op (plus bit_ior bit_xor)
> + (simplify
> +  (cond (eq @0 integer_zerop) @1 (op:c@2 @1 @0))
> +   @2))
> +/* a == 0 ? b : b - a  -> b - a */
> +/* a == 0 ? b : b ptr+ a  -> b ptr+ a */
> +/* a == 0 ? b : b shift/rotate a -> b shift/rotate a */
> +(for op (lrotate rrotate lshift rshift minus pointer_plus)
> + (simplify
> +  (cond (eq @0 integer_zerop) @1 (op@2 @1 @0))
> +   @2))
> +
>  /* Simplifications of shift and rotates.  */
>
>  (for rotate (lrotate rrotate)
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cond-1.c b/gcc/testsuite/gcc.dg/tree-ssa/cond-1.c
> new file mode 100644
> index 00000000000..478a818b206
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/cond-1.c
> @@ -0,0 +1,17 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O -fdump-tree-optimized-raw" } */
> +
> +int sub(int a, int b, int c, int d) {
> +  int e = (a == 0);
> +  int f = !e;
> +  c = b;
> +  d = b - a ;
> +  return ((-e & c) | (-f & d));
> +}
> +
> +/* In the end we end up with `(a == 0) ? (b - a) : b`
> +   which then can be optimized to just `(b - a)`. */
> +
> +/* { dg-final { scan-tree-dump-not "cond_expr," "optimized" } } */
> +/* { dg-final { scan-tree-dump-not "eq_expr," "optimized" } } */
> +/* { dg-final { scan-tree-dump-times "minus_expr," 1 "optimized" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1.c
> new file mode 100644
> index 00000000000..a90de8926c6
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1.c
> @@ -0,0 +1,17 @@
> +/* { dg-do compile } */
> +/* Phi-OPT should be able to optimize this without sinking being invoked. */
> +/* { dg-options "-O -fdump-tree-phiopt2 -fdump-tree-optimized -fno-tree-sink" } */
> +
> +char *f(char *a, __SIZE_TYPE__ b) {
> +  char *d = a + b;
> +  if (b == 0) return a;
> +  return d;
> +}
> +int sub(int a, int b, int c) {
> +  int d = a - b;
> +  if (b == 0) return a;
> +  return d;
> +}
> +
> +/* { dg-final { scan-tree-dump-not "goto" "phiopt2" } } */
> +/* { dg-final { scan-tree-dump-not "goto" "optimized" } } */
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1a.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1a.c
> new file mode 100644
> index 00000000000..b884f94ddd2
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-1a.c
> @@ -0,0 +1,19 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +
> +[[gnu::const]]
> +int constcall(int);
> +
> +int f(int a, int b)
> +{
> +  int c = b+a;
> +  int t = constcall(c);
> +  int d;
> +  if (a == 0) d= b; else d= c;
> +  return constcall(d) + t;
> +}
> +
> +/* There should be no if statement and 2 calls to call1. */
> +/* { dg-final { scan-tree-dump-not "if " "optimized" } } */
> +/* { dg-final { scan-tree-dump-times "constcall " 1 "optimized" } } */
> +
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-2.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-2.c
> new file mode 100644
> index 00000000000..809ccfe1479
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-2.c
> @@ -0,0 +1,19 @@
> +/* { dg-do compile } */
> +/* Phi-OPT should be able to optimize this without sinking being invoked. */
> +/* { dg-options "-O -fdump-tree-phiopt2 -fdump-tree-optimized -fno-tree-sink" } */
> +
> +int f(int a, int b, int c) {
> +  int d = a + b;
> +  if (c > 5) return c;
> +  if (a == 0) return b;
> +  return d;
> +}
> +
> +unsigned rot(unsigned x, int n) {
> +  const int bits = __CHAR_BIT__ * __SIZEOF_INT__;
> +  int t = ((x << n) | (x >> (bits - n)));
> +  return (n == 0) ? x : t;
> +}
> +
> +/* { dg-final { scan-tree-dump-times "goto" 2 "phiopt2" } } */
> +/* { dg-final { scan-tree-dump-times "goto" 2 "optimized" } } */
> --
> 2.39.3
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3] MATCH: Move jump_function_from_stmt support to match.pd
  2023-10-30  9:29   ` Richard Biener
@ 2023-10-30 20:36     ` Andrew Pinski
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Pinski @ 2023-10-30 20:36 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Mon, Oct 30, 2023 at 2:29 AM Richard Biener
<richard.guenther@gmail.com> wrote:
>
> On Sun, Oct 29, 2023 at 5:41 PM Andrew Pinski <pinskia@gmail.com> wrote:
> >
> > 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.
>
> Do we need to make sure to only do this after pass_early_object_sizes
> at least?  IIRC early PHI-opt didn't do value-replacement, so maybe
> even after late object-size?  There's PROP_objsz, but no
> function similar to optimize_vectors_before_lowering_p in
> {generic,gimple}-match-head.cc

Let me look into that.
But I suspect any which way we might end up with the same issue as the
problems you found in PR 112266 really.
So I am going to put this patch on the backburner for now (but still
look into this and the fall out from PR 112266 ).

Thanks,
Andrew

>
> Richard.
>
> > gcc/ChangeLog:
> >
> >         * match.pd (PTR == 0 ? 0 : &PTR->field): New pattern.
> >
> > gcc/testsuite/ChangeLog:
> >
> >         * gcc.dg/tree-ssa/vrp03.c: Disable phiopt1.
> >         * c-c++-common/analyzer/inlining-3-multiline.c: Likewise.
> >         * c-c++-common/analyzer/inlining-3.c: Likewise.
> >         * gcc.dg/tree-ssa/phi-opt-value-3.c: New testcase.
> > ---
> >  gcc/match.pd                                  | 21 ++++++++++++++++++
> >  .../analyzer/inlining-3-multiline.c           |  5 ++++-
> >  .../c-c++-common/analyzer/inlining-3.c        |  3 +++
> >  .../gcc.dg/tree-ssa/phi-opt-value-3.c         | 22 +++++++++++++++++++
> >  gcc/testsuite/gcc.dg/tree-ssa/vrp03.c         |  2 +-
> >  5 files changed, 51 insertions(+), 2 deletions(-)
> >  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c
> >
> > diff --git a/gcc/match.pd b/gcc/match.pd
> > index 22899c51a2f..9bc945ccada 100644
> > --- a/gcc/match.pd
> > +++ b/gcc/match.pd
> > @@ -4159,6 +4159,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/c-c++-common/analyzer/inlining-3-multiline.c b/gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c
> > index fbd20e949b6..9741b91abee 100644
> > --- a/gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c
> > +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-3-multiline.c
> > @@ -3,6 +3,9 @@
> >
> >  /* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
> >  /* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
> > +/* Disable phi-opt1 because get_input_file_name gets optimized to just
> > +   `return inpf;`. */
> > +/* { dg-additional-options "-fdisable-tree-phiopt1" } */
> >
> >  #include "../../gcc.dg/analyzer/analyzer-decls.h"
> >  typedef __SIZE_TYPE__ size_t;
> > @@ -96,4 +99,4 @@ test (const input_file *inpf)
> >      |                           (4) ...to here
> >      |                           (5) argument 1 ('<unknown>') NULL where non-null expected
> >      |
> > -   { dg-end-multiline-output "" { target c++ } } */
> > \ No newline at end of file
> > +   { dg-end-multiline-output "" { target c++ } } */
> > diff --git a/gcc/testsuite/c-c++-common/analyzer/inlining-3.c b/gcc/testsuite/c-c++-common/analyzer/inlining-3.c
> > index 0345585bed2..2b2b4858d45 100644
> > --- a/gcc/testsuite/c-c++-common/analyzer/inlining-3.c
> > +++ b/gcc/testsuite/c-c++-common/analyzer/inlining-3.c
> > @@ -2,6 +2,9 @@
> >     after early inlining.  */
> >
> >  /* { dg-additional-options "-O2 -fdiagnostics-show-path-depths" } */
> > +/* Disable phi-opt1 because get_input_file_name gets optimized to just
> > +   `return inpf;`. */
> > +/* { dg-additional-options "-fdisable-tree-phiopt1" } */
> >
> >  #include "../../gcc.dg/analyzer/analyzer-decls.h"
> >  typedef __SIZE_TYPE__ size_t;
> > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c
> > new file mode 100644
> > index 00000000000..ad55bd288b9
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-value-3.c
> > @@ -0,0 +1,22 @@
> > +/* { dg-do compile }  */
> > +/* { dg-options "-O1 -fdump-tree-optimized" }  */
> > +struct a
> > +{
> > +        int b[1];
> > +};
> > +
> > +int call1(int *a);
> > +
> > +int f(struct a *b)
> > +{
> > +  int *c = b->b;
> > +  int t = call1(c);
> > +  int *d;
> > +  if (b) d = b->b; else d = 0;
> > +  int t1 = call1(d);
> > +  return t+t1;
> > +}
> > +
> > +/* There should be no if statement and 2 calls to call1. */
> > +/* { dg-final { scan-tree-dump-not "if " "optimized" } } */
> > +/* { dg-final { scan-tree-dump-times "call1 " 2 "optimized"  } } */
> > 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
> >

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-10-30 20:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-29 16:40 [PATCH 0/3] start of moving value replacement from phiopt to match Andrew Pinski
2023-10-29 16:40 ` [PATCH 1/3] MATCH: first of the value replacement moving from phiopt Andrew Pinski
2023-10-30  9:32   ` Richard Biener
2023-10-29 16:40 ` [PATCH 2/3] MATCH: Move jump_function_from_stmt support to match.pd Andrew Pinski
2023-10-30  9:29   ` Richard Biener
2023-10-30 20:36     ` Andrew Pinski
2023-10-29 16:40 ` [PATCH 3/3] MATCH: Add some more value_replacement simplifications to match Andrew Pinski
2023-10-30  9:30   ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).