https://gcc.gnu.org/g:f3b7007bbabea686e133b001de1cac089afbd11f
commit r13-9972-gf3b7007bbabea686e133b001de1cac089afbd11f Author: Richard Biener <[email protected]> Date: Fri Nov 14 12:08:32 2025 +0000 middle-end: fix missing converts in vec_cond_expr simplification [PR122724] 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. gcc/ChangeLog: PR tree-optimization/112469 PR tree-optimization/122724 * match.pd (cond ? op a : b -> .COND_op (cond, a, b)): Add missing view_converts. gcc/testsuite/ChangeLog: PR tree-optimization/112469 PR tree-optimization/122724 * gcc.target/aarch64/sve/pr122724.c: New test. Co-Authored-By: Alex Coplan <[email protected]> Diff: --- gcc/match.pd | 4 ++-- gcc/testsuite/gcc.target/aarch64/sve/pr122724.c | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index d3af36f8de3e..bbcc6587569d 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/pr122724.c b/gcc/testsuite/gcc.target/aarch64/sve/pr122724.c new file mode 100644 index 000000000000..3c347b2e9868 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/pr122724.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; + } +}
