public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/redhat/heads/gcc-8-branch)] fold-const: Fix division folding with vector operands [PR94412]
@ 2020-09-17 17:21 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-09-17 17:21 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1d633231f0fff2a692e3991bcb7bb4d349c0c385

commit 1d633231f0fff2a692e3991bcb7bb4d349c0c385
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Mar 31 11:06:43 2020 +0200

    fold-const: Fix division folding with vector operands [PR94412]
    
    The following testcase is miscompiled since 4.9, we treat unsigned
    vector types as if they were signed and "optimize" negations across it.
    
    2020-03-31  Marc Glisse  <marc.glisse@inria.fr>
                Jakub Jelinek  <jakub@redhat.com>
    
            PR middle-end/94412
            * fold-const.c (fold_binary_loc) <case TRUNC_DIV_EXPR>: Use
            ANY_INTEGRAL_TYPE_P instead of INTEGRAL_TYPE_P.
    
            * gcc.c-torture/execute/pr94412.c: New test.
    
    Co-authored-by: Marc Glisse <marc.glisse@inria.fr>
    (cherry picked from commit 8f99f9e6ccec167a5ba67dcc08e6c14948595b82)

Diff:
---
 gcc/fold-const.c                              |  8 ++++----
 gcc/testsuite/gcc.c-torture/execute/pr94412.c | 28 +++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 9183c3752ce..85b85398933 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -10416,11 +10416,11 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
 
       /* Convert -A / -B to A / B when the type is signed and overflow is
 	 undefined.  */
-      if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
+      if ((!ANY_INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
 	  && TREE_CODE (op0) == NEGATE_EXPR
 	  && negate_expr_p (op1))
 	{
-	  if (INTEGRAL_TYPE_P (type))
+	  if (ANY_INTEGRAL_TYPE_P (type))
 	    fold_overflow_warning (("assuming signed overflow does not occur "
 				    "when distributing negation across "
 				    "division"),
@@ -10430,11 +10430,11 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
 						    TREE_OPERAND (arg0, 0)),
 				  negate_expr (op1));
 	}
-      if ((!INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
+      if ((!ANY_INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))
 	  && TREE_CODE (arg1) == NEGATE_EXPR
 	  && negate_expr_p (op0))
 	{
-	  if (INTEGRAL_TYPE_P (type))
+	  if (ANY_INTEGRAL_TYPE_P (type))
 	    fold_overflow_warning (("assuming signed overflow does not occur "
 				    "when distributing negation across "
 				    "division"),
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr94412.c b/gcc/testsuite/gcc.c-torture/execute/pr94412.c
new file mode 100644
index 00000000000..6c806bbd90c
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr94412.c
@@ -0,0 +1,28 @@
+/* PR middle-end/94412 */
+
+typedef unsigned V __attribute__ ((__vector_size__ (sizeof (unsigned) * 2)));
+
+void
+foo (V *v, V *w)
+{
+  *w = -*v / 11;
+}
+
+void
+bar (V *v, V *w)
+{
+  *w = -18 / -*v;
+}
+
+int
+main ()
+{
+  V a = (V) { 1, 0 };
+  V b = (V) { 3, __INT_MAX__ };
+  V c, d;
+  foo (&a, &c);
+  bar (&b, &d);
+  if (c[0] != -1U / 11 || c[1] != 0 || d[0] != 0 || d[1] != -18U / -__INT_MAX__)
+    __builtin_abort ();
+  return 0;
+}


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

only message in thread, other threads:[~2020-09-17 17:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 17:21 [gcc(refs/vendors/redhat/heads/gcc-8-branch)] fold-const: Fix division folding with vector operands [PR94412] 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).