public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-9204] graphite: Fix non-INTEGER_TYPE integral comparison handling [PR114041]
@ 2024-02-28  9:00 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2024-02-28  9:00 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d6479050ecef10fd5e67b4da989229e4cfac53ee

commit r14-9204-gd6479050ecef10fd5e67b4da989229e4cfac53ee
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Feb 28 09:59:45 2024 +0100

    graphite: Fix non-INTEGER_TYPE integral comparison handling [PR114041]
    
    The following testcases are miscompiled, because graphite ignores boolean,
    enumerated or _BitInt comparisons, rewrites the code as if the comparisons
    were always true or always false.
    
    The INTEGER_TYPE checks were initially added in r6-2239 but at that point
    it was both in add_conditions_to_domain and in parameter_index_in_region.
    Later on the check was also added to stmt_simple_for_scop_p, and finally
    r8-3931 changed the stmt_simple_for_scop_p check to INTEGRAL_TYPE_P
    and turned the parameter_index_in_region -> assign_parameter_index_in_region
    into INTEGRAL_TYPE_P assertion, but the add_conditions_to_domain check
    for INTEGER_TYPE remained.
    
    The following patch uses INTEGRAL_TYPE_P to complete the change.
    
    2024-02-28  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/114041
            * graphite-sese-to-poly.cc (add_conditions_to_domain): Check for
            INTEGRAL_TYPE_P check rather than INTEGER_TYPE.
    
            * gcc.dg/graphite/run-id-pr114041-1.c: New test.
            * gcc.dg/graphite/run-id-pr114041-2.c: New test.

Diff:
---
 gcc/graphite-sese-to-poly.cc                      |  5 +++--
 gcc/testsuite/gcc.dg/graphite/run-id-pr114041-1.c | 23 +++++++++++++++++++
 gcc/testsuite/gcc.dg/graphite/run-id-pr114041-2.c | 27 +++++++++++++++++++++++
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/gcc/graphite-sese-to-poly.cc b/gcc/graphite-sese-to-poly.cc
index 547d66105d3..4f614a3ba82 100644
--- a/gcc/graphite-sese-to-poly.cc
+++ b/gcc/graphite-sese-to-poly.cc
@@ -391,8 +391,9 @@ add_conditions_to_domain (poly_bb_p pbb)
       {
       case GIMPLE_COND:
 	  {
-            /* Don't constrain on anything else than INTEGER_TYPE.  */
-	    if (TREE_CODE (TREE_TYPE (gimple_cond_lhs (stmt))) != INTEGER_TYPE)
+	    /* Don't constrain on anything else than INTEGRAL_TYPE_P.  */
+	    tree cmp_type = TREE_TYPE (gimple_cond_lhs (stmt));
+	    if (!INTEGRAL_TYPE_P (cmp_type))
               break;
 
 	    gcond *cond_stmt = as_a <gcond *> (stmt);
diff --git a/gcc/testsuite/gcc.dg/graphite/run-id-pr114041-1.c b/gcc/testsuite/gcc.dg/graphite/run-id-pr114041-1.c
new file mode 100644
index 00000000000..1ffdd746e52
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/graphite/run-id-pr114041-1.c
@@ -0,0 +1,23 @@
+/* PR tree-optimization/114041 */
+/* { dg-require-effective-target bitint } */
+/* { dg-options "-O -fgraphite-identity" } */
+
+unsigned a[24], b[24];
+
+__attribute__((noipa)) unsigned
+foo (unsigned _BitInt(8) x)
+{
+  for (int i = 0; i < 24; ++i)
+    a[i] = i;
+  unsigned e = __builtin_stdc_bit_ceil (x);
+  for (int i = 0; i < 24; ++i)
+    b[i] = i;
+  return e;
+}
+
+int
+main ()
+{
+  if (foo (0) != 1)
+    __builtin_abort ();
+}
diff --git a/gcc/testsuite/gcc.dg/graphite/run-id-pr114041-2.c b/gcc/testsuite/gcc.dg/graphite/run-id-pr114041-2.c
new file mode 100644
index 00000000000..c935255fe8f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/graphite/run-id-pr114041-2.c
@@ -0,0 +1,27 @@
+/* PR tree-optimization/114041 */
+/* { dg-options "-O -fgraphite-identity" } */
+
+unsigned a[24], b[24];
+enum E { E0 = 0, E1 = 1, E42 = 42, E56 = 56 };
+
+__attribute__((noipa)) unsigned
+foo (enum E x)
+{
+  for (int i = 0; i < 24; ++i)
+    a[i] = i;
+  unsigned e;
+  if (x >= E42)
+    e = __builtin_clz ((unsigned) x);
+  else
+    e = 42;
+  for (int i = 0; i < 24; ++i)
+    b[i] = i;
+  return e;
+}
+
+int
+main ()
+{
+  if (foo (E1) != 42 || foo (E56) != __SIZEOF_INT__ * __CHAR_BIT__ - 6)
+    __builtin_abort ();
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-28  9:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-28  9:00 [gcc r14-9204] graphite: Fix non-INTEGER_TYPE integral comparison handling [PR114041] Jakub Jelinek

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).