public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-7618] icf: Check return type of internal fn calls [PR99517]
@ 2021-03-11 10:18 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-03-11 10:18 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:070ab283d16d8e8e8bb70f9801aca347f008cbd0

commit r11-7618-g070ab283d16d8e8e8bb70f9801aca347f008cbd0
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Mar 11 10:59:18 2021 +0100

    icf: Check return type of internal fn calls [PR99517]
    
    The following testcase is miscompiled, because IPA-ICF considers the two
    functions identical.  They aren't, the types of the .VEC_CONVERT call
    lhs is different.  But for calls to internal functions, there is no
    fntype nor callee with a function type to compare, so all we compare
    is just the ifn, arguments and some call flags.
    
    The following patch fixes it by checking the internal fn calls like e.g. gimple
    assignments where the type of the lhs is checked too.
    
    2021-03-11  Jakub Jelinek  <jakub@redhat.com>
    
            PR ipa/99517
            * ipa-icf-gimple.c (func_checker::compare_gimple_call): For internal
            function calls with lhs fail if the lhs don't have compatible types.
    
            * gcc.target/i386/avx2-pr99517-1.c: New test.
            * gcc.target/i386/avx2-pr99517-2.c: New test.

Diff:
---
 gcc/ipa-icf-gimple.c                           | 10 +++++++++-
 gcc/testsuite/gcc.target/i386/avx2-pr99517-1.c | 25 +++++++++++++++++++++++++
 gcc/testsuite/gcc.target/i386/avx2-pr99517-2.c | 20 ++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c
index 3bc168d8a38..edf5f025627 100644
--- a/gcc/ipa-icf-gimple.c
+++ b/gcc/ipa-icf-gimple.c
@@ -667,7 +667,7 @@ func_checker::compare_gimple_call (gcall *s1, gcall *s2)
   tree fntype1 = gimple_call_fntype (s1);
   tree fntype2 = gimple_call_fntype (s2);
 
-  /* For direct calls we verify that types are comopatible so if we matced
+  /* For direct calls we verify that types are compatible so if we matched
      callees, callers must match, too.  For indirect calls however verify
      function type.  */
   if (!gimple_call_fndecl (s1))
@@ -703,6 +703,14 @@ func_checker::compare_gimple_call (gcall *s1, gcall *s2)
   t1 = gimple_get_lhs (s1);
   t2 = gimple_get_lhs (s2);
 
+  /* For internal calls, lhs types need to be verified, as neither fntype nor
+     callee comparisons can catch that.  */
+  if (gimple_call_internal_p (s1)
+      && t1
+      && t2
+      && !compatible_types_p (TREE_TYPE (t1), TREE_TYPE (t2)))
+    return return_false_with_msg ("GIMPLE internal call LHS type mismatch");
+
   return compare_operand (t1, t2, get_operand_access_type (&map, t1));
 }
 
diff --git a/gcc/testsuite/gcc.target/i386/avx2-pr99517-1.c b/gcc/testsuite/gcc.target/i386/avx2-pr99517-1.c
new file mode 100644
index 00000000000..f1d7f82cde8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx2-pr99517-1.c
@@ -0,0 +1,25 @@
+/* PR ipa/99517 */
+/* { dg-do run { target avx2 } } */
+/* { dg-additional-sources "avx2-pr99517-2.c" } */
+/* { dg-options "-O2 -mavx2" } */
+
+#include "avx2-check.h"
+
+typedef signed char v32qi __attribute__((vector_size(32)));
+typedef int v4si __attribute__((vector_size(16)));
+typedef long long int v4di __attribute__((vector_size(32)));
+typedef double v4df __attribute__((vector_size(32)));
+extern v32qi foo (v4si);
+extern v32qi bar (v4si);
+
+static void
+avx2_test (void)
+{
+  v4si a = { 1, -2, 3, -4 };
+  __asm ("" : "+x" (a));
+  v4di b = (v4di) bar (a);
+  v4df c = (v4df) foo (a);
+  if (b[0] != 1 || c[0] != 1.0 || b[1] != -2 || c[1] != -2.0
+      || b[2] != 3 || c[2] != 3.0 || b[3] != -4 || c[3] != -4.0)
+    __builtin_abort ();
+}
diff --git a/gcc/testsuite/gcc.target/i386/avx2-pr99517-2.c b/gcc/testsuite/gcc.target/i386/avx2-pr99517-2.c
new file mode 100644
index 00000000000..80bd39585cb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx2-pr99517-2.c
@@ -0,0 +1,20 @@
+/* PR ipa/99517 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx2" } */
+
+typedef signed char v32qi __attribute__((vector_size(32)));
+typedef int v4si __attribute__((vector_size(16)));
+typedef long long int v4di __attribute__((vector_size(32)));
+typedef double v4df __attribute__((vector_size(32)));
+
+v32qi
+foo (v4si x)
+{
+  return (v32qi) __builtin_convertvector (x, v4df);
+}
+
+v32qi
+bar (v4si x)
+{
+  return (v32qi) __builtin_convertvector (x, v4di);
+}


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

only message in thread, other threads:[~2021-03-11 10:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-11 10:18 [gcc r11-7618] icf: Check return type of internal fn calls [PR99517] 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).