public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] vect: Use statement vectype for conditional mask.
@ 2023-11-08 16:18 Robin Dapp
  2023-11-10  9:33 ` Richard Biener
  0 siblings, 1 reply; 12+ messages in thread
From: Robin Dapp @ 2023-11-08 16:18 UTC (permalink / raw)
  To: gcc-patches, Tamar Christina; +Cc: rdapp.gcc

Hi,

as Tamar reported in PR112406 we still ICE on aarch64 in SPEC2017
when creating COND_OPs in ifcvt.

The problem is that we fail to deduce the mask's type from the statement
vectype and then end up with a non-matching mask in expand.  This patch
checks if the current op is equal to the mask operand and, if so, uses
the truth type from the stmt_vectype.  Is that a valid approach?  

Bootstrapped and regtested on aarch64, x86 is running.

Besides, the testcase is Tamar's reduced example, originally from
SPEC.  I hope it's ok to include it as is (as imagick is open source
anyway).

Regards
 Robin

gcc/ChangeLog:

	PR middle-end/112406

	* tree-vect-stmts.cc (vect_get_vec_defs_for_operand): Handle
	masks of conditional ops.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr112406.c: New test.
---
 gcc/testsuite/gcc.dg/pr112406.c | 37 +++++++++++++++++++++++++++++++++
 gcc/tree-vect-stmts.cc          | 20 +++++++++++++++++-
 2 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr112406.c

diff --git a/gcc/testsuite/gcc.dg/pr112406.c b/gcc/testsuite/gcc.dg/pr112406.c
new file mode 100644
index 00000000000..46459c68c4a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr112406.c
@@ -0,0 +1,37 @@
+/* { dg-do compile { target { aarch64*-*-* } } } */
+/* { dg-options "-march=armv8-a+sve -w -Ofast" } */
+
+typedef struct {
+  int red
+} MagickPixelPacket;
+
+GetImageChannelMoments_image, GetImageChannelMoments_image_0,
+    GetImageChannelMoments___trans_tmp_1, GetImageChannelMoments_M11_0,
+    GetImageChannelMoments_pixel_3, GetImageChannelMoments_y,
+    GetImageChannelMoments_p;
+
+double GetImageChannelMoments_M00_0, GetImageChannelMoments_M00_1,
+    GetImageChannelMoments_M01_1;
+
+MagickPixelPacket GetImageChannelMoments_pixel;
+
+SetMagickPixelPacket(int color, MagickPixelPacket *pixel) {
+  pixel->red = color;
+}
+
+GetImageChannelMoments() {
+  for (; GetImageChannelMoments_y; GetImageChannelMoments_y++) {
+    SetMagickPixelPacket(GetImageChannelMoments_p,
+                         &GetImageChannelMoments_pixel);
+    GetImageChannelMoments_M00_1 += GetImageChannelMoments_pixel.red;
+    if (GetImageChannelMoments_image)
+      GetImageChannelMoments_M00_1++;
+    GetImageChannelMoments_M01_1 +=
+        GetImageChannelMoments_y * GetImageChannelMoments_pixel_3;
+    if (GetImageChannelMoments_image_0)
+      GetImageChannelMoments_M00_0++;
+    GetImageChannelMoments_M01_1 +=
+        GetImageChannelMoments_y * GetImageChannelMoments_p++;
+  }
+  GetImageChannelMoments___trans_tmp_1 = atan(GetImageChannelMoments_M11_0);
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 65883e04ad7..6793b01bf44 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -1238,10 +1238,28 @@ vect_get_vec_defs_for_operand (vec_info *vinfo, stmt_vec_info stmt_vinfo,
       tree stmt_vectype = STMT_VINFO_VECTYPE (stmt_vinfo);
       tree vector_type;
 
+      /* For a COND_OP the mask operand's type must not be deduced from the
+	 scalar type but from the statement's vectype.  */
+      bool use_stmt_vectype = false;
+      gcall *call;
+      if ((call = dyn_cast <gcall *> (STMT_VINFO_STMT (stmt_vinfo)))
+	  && gimple_call_internal_p (call))
+	{
+	  internal_fn ifn = gimple_call_internal_fn (call);
+	  int mask_idx = -1;
+	  if (ifn != IFN_LAST
+	      && (mask_idx = internal_fn_mask_index (ifn)) != -1)
+	    {
+	      tree maskop = gimple_call_arg (call, mask_idx);
+	      if (op == maskop)
+		use_stmt_vectype = true;
+	    }
+	}
+
       if (vectype)
 	vector_type = vectype;
       else if (VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (op))
-	       && VECTOR_BOOLEAN_TYPE_P (stmt_vectype))
+	       && (use_stmt_vectype || VECTOR_BOOLEAN_TYPE_P (stmt_vectype)))
 	vector_type = truth_type_for (stmt_vectype);
       else
 	vector_type = get_vectype_for_scalar_type (loop_vinfo, TREE_TYPE (op));
-- 
2.41.0

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-12-03 18:59 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-08 16:18 [PATCH] vect: Use statement vectype for conditional mask Robin Dapp
2023-11-10  9:33 ` Richard Biener
2023-11-16 22:30   ` Robin Dapp
2023-11-17  8:24     ` Richard Biener
2023-11-17  8:45       ` Robin Dapp
2023-11-17  8:47         ` Richard Biener
2023-11-17 13:04           ` Robin Dapp
2023-12-03 18:32             ` [PATCH] testsuite: Fix up gcc.target/aarch64/pr112406.c for modern C [PR112406] Jakub Jelinek
2023-12-03 18:32               ` Jakub Jelinek
2023-12-03 18:59               ` Richard Biener
2023-11-17 19:20       ` [PATCH] vect: Use statement vectype for conditional mask Robin Dapp
2023-11-20  8:03         ` 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).