[COMMITTED] Add a few testcases for fix missed optimization regressions

Message ID 20240113043706.2216775-1-quic_apinski@quicinc.com
State Accepted
Headers
Series [COMMITTED] Add a few testcases for fix missed optimization regressions |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Andrew Pinski (QUIC) Jan. 13, 2024, 4:37 a.m. UTC
  Adds a few new testcases for some missed optimization regressions.
The analysis on how each should be optimized is in the testcases
themselves (and in the bug report).

Committed as obvious after running the testsuite to make sure they pass.

	PR tree-optimization/107823
	PR tree-optimization/110768
	PR tree-optimization/110941
	PR tree-optimization/110450
	PR tree-optimization/110841

gcc/testsuite/ChangeLog:

	* gcc.dg/tree-ssa/ssa-thread-22.c: New test.
	* gcc.dg/tree-ssa/vrp-loop-1.c: New test.
	* gcc.dg/tree-ssa/vrp-loop-2.c: New test.
	* gcc.dg/tree-ssa/vrp-unreachable-1.c: New test.
	* gcc.dg/tree-ssa/vrp-unreachable-2.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
---
 gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-22.c | 23 +++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-1.c    | 34 +++++++++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-2.c    | 33 ++++++++++++++++++
 .../gcc.dg/tree-ssa/vrp-unreachable-1.c       | 26 ++++++++++++++
 .../gcc.dg/tree-ssa/vrp-unreachable-2.c       | 29 ++++++++++++++++
 5 files changed, 145 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-22.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-2.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-1.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-2.c
  

Patch

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-22.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-22.c
new file mode 100644
index 00000000000..f605009d8b5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-thread-22.c
@@ -0,0 +1,23 @@ 
+/* { dg-do compile } */
+/* { dg-options "-Os -fdump-tree-optimized" } */
+/* PR tree-optimization/107823 */
+/* With jump threading across the loop header,
+   we should figure out that b is always 0 and remove
+   the call to foo.  */
+
+int a;
+void bar64_(void);
+void foo();
+int main() {
+  signed char b = a = 6;
+  for (; a; a = 0) {
+    bar64_();
+    b = 0;
+  }
+  if (b <= 0)
+    ;
+  else
+    foo();
+}
+
+/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-1.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-1.c
new file mode 100644
index 00000000000..09de8924308
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-1.c
@@ -0,0 +1,34 @@ 
+/* { dg-do compile } */
+/* { dg-options "-Os -fdump-tree-optimized" } */
+/* PR tree-optimization/110768 */
+/* The call to foo should be able to removed,
+   The branch to unreachable is unreachable as
+   VRP (ranger) figure out that c there can only
+   be -20409 or 0. before r14-5109-ga291237b628f41
+   ranger could not figure that out.  */
+   
+
+void foo(void);
+static int a, b;
+int main() {
+    {
+        short c = 45127;
+        signed char d;
+        b = 0;
+        for (; b <= 3; b++) {
+            if (b) continue;
+            d = 0;
+            for (; d <= 100; d++) {
+                if (!(((c) >= -20409) && ((c) <= 1))) {
+                    __builtin_unreachable();
+                }
+                if (~(0 == a) & 1) return b;
+                c = 0;
+                for (; c <= 0; c++) a = 3;
+            }
+        }
+        foo();
+    }
+}
+
+/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-2.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-2.c
new file mode 100644
index 00000000000..7438c55aaef
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-loop-2.c
@@ -0,0 +1,33 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O3 -fdump-tree-optimized" } */
+/* PR tree-optimization/110941 */
+/* The call to foo should be able to removed,
+   VRP should figure out `(c >= 2 && c <= 26)`
+   is always true.  */  
+
+static int a;
+void foo(void);
+void bar349_(void);
+void bar363_(void);
+void bar275_(void);
+int main() {
+  {
+    {
+      short b = 26;
+      for (; b >= 1; b = b - 4) {
+        if (b >= 2 && b <= 26)
+          bar275_();
+        if (a)
+          bar363_();
+        if (a)
+          bar349_();
+        int c = b;
+        if (!(c >= 2 && c <= 26))
+          foo();
+      }
+    }
+    a = 0;
+  }
+}
+
+/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-1.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-1.c
new file mode 100644
index 00000000000..76ef5017577
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-1.c
@@ -0,0 +1,26 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* PR tree-optimization/110450 */
+/* the ranger should be able to figure out that based on the
+   unreachable part of d not being zero, *b is also never 0.
+*/
+
+
+void foo(void);
+static int a = 1;
+static int *b = &a, *c = &a;
+static short d, e;
+static signed char f = 11;
+static signed char(g)(signed char h, int i) { return h << i; }
+int main() {
+    if (f) *c = g(0 >= a, 3);
+    e = *c;
+    d = e % f;
+    if (d) {
+        __builtin_unreachable();
+    } else if (*b)
+        foo();
+    ;
+}
+
+/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-2.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-2.c
new file mode 100644
index 00000000000..44b1ba5c687
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-unreachable-2.c
@@ -0,0 +1,29 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* PR tree-optimization/110841  */
+/* The call to foo should be able to removed */
+
+void foo(void);
+static int b, c, d;
+static signed char(a)(signed char e, signed char f) { return e - f; }
+int main() {
+    for (; b <= 4; b++)
+        ;
+    c = 0;
+    for (; c >= -16; c = a(c, 4))
+        ;
+    signed char g = b;
+    for (; d <= 0; d++) {
+        if (!(((g) >= 5) && ((g) <= 5))) {
+            __builtin_unreachable();
+        }
+        if (c) return 0;
+        g = 0;
+        for (;;) {
+            foo();
+            break;
+        }
+    }
+}
+
+/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */