diff options
author | Tamar Christina <tamar.christina@arm.com> | 2024-01-12 15:26:29 +0000 |
---|---|---|
committer | Tamar Christina <tamar.christina@arm.com> | 2024-01-12 15:31:48 +0000 |
commit | e79c5855ab39d96baa7c6bec63eb97715abcf68d (patch) | |
tree | 7c291f505d5ece701a8ba7a64129d11feb4f69f6 /gcc | |
parent | 99c0a540d6689ede068f9ba98af6f38c3cd71362 (diff) | |
download | gcc-e79c5855ab39d96baa7c6bec63eb97715abcf68d.zip gcc-e79c5855ab39d96baa7c6bec63eb97715abcf68d.tar.gz gcc-e79c5855ab39d96baa7c6bec63eb97715abcf68d.tar.bz2 |
middle-end: fill in reduction PHI for all alt exits [PR113178]
When we have a loop with more than 2 exits and a reduction I forgot to fill in
the PHI value for all alternate exits.
All alternate exits use the same PHI value so we should loop over the new
PHI elements and copy the value across since we call the reduction calculation
code only once for all exits. This was normally covered up by earlier parts of
the compiler rejecting loops incorrectly (which has been fixed now).
Note that while I can use the loop in all cases, the reason I separated out the
main and alt exit is so that if you pass the wrong edge the macro will assert.
gcc/ChangeLog:
PR tree-optimization/113178
* tree-vect-loop.cc (vect_create_epilog_for_reduction): Fill in all
alternate exits.
gcc/testsuite/ChangeLog:
PR tree-optimization/113178
* gcc.dg/vect/vect-early-break_101-pr113178.c: New test.
* gcc.dg/vect/vect-early-break_102-pr113178.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/vect-early-break_101-pr113178.c | 22 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/vect-early-break_102-pr113178.c | 19 | ||||
-rw-r--r-- | gcc/tree-vect-loop.cc | 8 |
3 files changed, 48 insertions, 1 deletions
diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_101-pr113178.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_101-pr113178.c new file mode 100644 index 0000000..8b91112 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_101-pr113178.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break } */ +/* { dg-require-effective-target vect_int } */ + +struct PixelWeight { + int m_SrcStart; + int m_Weights[16]; +}; +char h; +void f(struct PixelWeight *pPixelWeights) { + int dest_g_m; + long tt; + for (int j = 0; j < 16; j++) { + int *p = 0; + if (j < pPixelWeights->m_SrcStart) + p = tt ? &pPixelWeights->m_Weights[0] : 0; + int pWeight = *p; + dest_g_m += pWeight; + } + h = dest_g_m; +} diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_102-pr113178.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_102-pr113178.c new file mode 100644 index 0000000..ad7582e --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_102-pr113178.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-additional-options "-std=gnu99 -fpermissive -fgnu89-inline -Ofast -fprofile-generate -w" } */ + +extern int replace_reg_with_saved_mem_i, replace_reg_with_saved_mem_nregs, + replace_reg_with_saved_mem_mem_1; +replace_reg_with_saved_mem_mode() { + if (replace_reg_with_saved_mem_i) + return; + while (++replace_reg_with_saved_mem_i < replace_reg_with_saved_mem_nregs) + if (replace_reg_with_saved_mem_i) + break; + if (replace_reg_with_saved_mem_i) + if (replace_reg_with_saved_mem_mem_1) + adjust_address_1(); + replace_reg_with_saved_mem_mem_1 ? fancy_abort() : 0; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 0f4a557..44022bf 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -6247,7 +6247,13 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo, phi = create_phi_node (new_def, exit_bb); if (j) def = gimple_get_lhs (vec_stmts[j]); - SET_PHI_ARG_DEF (phi, loop_exit->dest_idx, def); + if (LOOP_VINFO_IV_EXIT (loop_vinfo) == loop_exit) + SET_PHI_ARG_DEF (phi, loop_exit->dest_idx, def); + else + { + for (unsigned k = 0; k < gimple_phi_num_args (phi); k++) + SET_PHI_ARG_DEF (phi, k, def); + } new_def = gimple_convert (&stmts, vectype, new_def); reduc_inputs.quick_push (new_def); } |