public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] middle-end/112469 - fix missing converts in vec_cond_expr simplification
@ 2023-11-10 10:58 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-11-10 10:58 UTC (permalink / raw)
  To: gcc-patches

The following avoids type inconsistencies in .COND_op generated by
simplifications of VEC_COND_EXPRs.

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

	PR middle-end/112469
	* match.pd (cond ? op a : b -> .COND_op (cond, a, b)): Add
	missing view_converts.

	* gcc.dg/torture/pr112469.c: New testcase.
---
 gcc/match.pd                            |  8 ++++----
 gcc/testsuite/gcc.dg/torture/pr112469.c | 12 ++++++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr112469.c

diff --git a/gcc/match.pd b/gcc/match.pd
index f559bfa4f2b..281c6c087e6 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -8959,13 +8959,13 @@ and,
    (with { tree op_type = TREE_TYPE (@3); }
     (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type)
         && is_truth_type_for (op_type, TREE_TYPE (@0)))
-     (cond_op @0 @1 @2))))
+     (cond_op @0 (view_convert @1) @2))))
  (simplify
   (vec_cond @0 @1 (view_convert? (uncond_op@3 @2)))
    (with { tree op_type = TREE_TYPE (@3); }
     (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type)
         && is_truth_type_for (op_type, TREE_TYPE (@0)))
-     (cond_op (bit_not @0) @2 @1)))))
+     (cond_op (bit_not @0) (view_convert @2) @1)))))
 
 (for uncond_op (UNCOND_UNARY)
      cond_op (COND_LEN_UNARY)
@@ -8974,13 +8974,13 @@ and,
    (with { tree op_type = TREE_TYPE (@3); }
     (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type)
         && is_truth_type_for (op_type, TREE_TYPE (@0)))
-     (cond_op @0 @1 @2 @4 @5))))
+     (cond_op @0 (view_convert @1) @2 @4 @5))))
  (simplify
   (IFN_VCOND_MASK_LEN @0 @1 (view_convert? (uncond_op@3 @2)) @4 @5)
    (with { tree op_type = TREE_TYPE (@3); }
     (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type)
         && is_truth_type_for (op_type, TREE_TYPE (@0)))
-     (cond_op (bit_not @0) @2 @1 @4 @5)))))
+     (cond_op (bit_not @0) (view_convert @2) @1 @4 @5)))))
 
 /* `(a ? -1 : 0) ^ b` can be converted into a conditional not.  */
 (simplify
diff --git a/gcc/testsuite/gcc.dg/torture/pr112469.c b/gcc/testsuite/gcc.dg/torture/pr112469.c
new file mode 100644
index 00000000000..9978bcd4560
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr112469.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+int a, b, c;
+static int *d = &a;
+int e(int f) { return f == 0 ? 1 : f; }
+void g() {
+  a = 1;
+  for (; a <= 8; a++) {
+    b = e(*d);
+    c = -b;
+  }
+}
-- 
2.35.3

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

only message in thread, other threads:[~2023-11-10 10:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-10 10:58 [PATCH] middle-end/112469 - fix missing converts in vec_cond_expr simplification 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).