From: Richard Biener <[email protected]>
The following avoids type inconsistencies in .COND_op generated by
simplifications of VEC_COND_EXPRs.
This is a backport of r14-5317-g20aa06490ab57da7729a24bae7c4ec2f5918ec91
but with a testcase that triggered an ICE on the 13 branch (with the
same root cause as the original PR). It isn't an exact cherry-pick
because some of the patterns that were patched in the original fix don't
exist in GCC 13.
Bootstrapped/regtested on aarch64-linux-gnu, arm-linux-gnueabihf, and
x86_64-linux-gnu. OK for the 13 branch?
Thanks,
Alex
gcc/ChangeLog:
PR middle-end/112469
* match.pd (cond ? op a : b -> .COND_op (cond, a, b)): Add
missing view_converts.
gcc/testsuite/ChangeLog:
PR middle-end/112469
* gcc.target/aarch64/sve/pr112469.c: New test.
Co-Authored-By: Alex Coplan <[email protected]>
diff --git a/gcc/match.pd b/gcc/match.pd
index d3af36f8de3..bbcc6587569 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -7934,13 +7934,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)))))
/* Simplify:
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pr112469.c
b/gcc/testsuite/gcc.target/aarch64/sve/pr112469.c
new file mode 100644
index 00000000000..3c347b2e986
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/pr112469.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+_Float16 in[128];
+short out[128];
+void foo(void) {
+ for (int i = 0; i < 128; i++) {
+ _Float16 x = in[i];
+ _Float16 y = x ? -x : 0.0;
+ short dst;
+ __builtin_memcpy (&dst, &y, sizeof(dst));
+ out[i] = dst;
+ }
+}