public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/111082 - bogus promoted min
@ 2023-08-21  9:47 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-08-21  9:47 UTC (permalink / raw)
  To: gcc-patches

vectorize_slp_instance_root_stmt promotes operations with undefined
overflow to unsigned arithmetic but fails to consider operations
that do not overflow like MIN which it turned into MIN with wrong
signedness and in the case of the PR an unsupported operation.
The following rectifies this.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/111082
	* tree-vect-slp.cc (vectorize_slp_instance_root_stmt): Only
	pun operations that can overflow.

	* gcc.dg/pr111082.c: New testcase.
---
 gcc/testsuite/gcc.dg/pr111082.c | 10 ++++++++++
 gcc/tree-vect-slp.cc            |  3 ++-
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr111082.c

diff --git a/gcc/testsuite/gcc.dg/pr111082.c b/gcc/testsuite/gcc.dg/pr111082.c
new file mode 100644
index 00000000000..46e36e320d1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr111082.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fno-vect-cost-model" } */
+/* { dg-additional-options "-mavx512f" { target { x86_64-*-* i?86-*-* } } } */
+
+long minarray2(const long *input)
+{
+  if (input[0] < input[1])
+    return input[0] ;
+  return input[1];
+}
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 51f3466805c..e8484401bc9 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -9180,7 +9180,8 @@ vectorize_slp_instance_root_stmt (slp_tree node, slp_instance instance)
       tree vectype = TREE_TYPE (vec_def);
       tree compute_vectype = vectype;
       bool pun_for_overflow_p = (ANY_INTEGRAL_TYPE_P (vectype)
-				 && TYPE_OVERFLOW_UNDEFINED (vectype));
+				 && TYPE_OVERFLOW_UNDEFINED (vectype)
+				 && operation_can_overflow (reduc_code));
       if (pun_for_overflow_p)
 	{
 	  compute_vectype = unsigned_type_for (vectype);
-- 
2.35.3

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

only message in thread, other threads:[~2023-08-21  9:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-21  9:47 [PATCH] tree-optimization/111082 - bogus promoted min 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).