This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] vectorizer phi-used-after-loop bug fix
- From: Dorit Naishlos <DORIT at il dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 31 Jan 2005 18:07:07 +0200
- Subject: [patch] vectorizer phi-used-after-loop bug fix
- Reply-to:
- Sensitivity:
In mark_stmts_to_be_vectorized we try to identify all stmts that need to be
vectorized; in particular we want to identify which IVs can be ignored
(e.g, cause they are only used for array indexing) and which can't be
ignored (e.g, cause they are used outside the loop) and need special
handling (which we don't support yet, but we will soon). In the meantine,
the problem is that we neglect to check whether phi nodes are used out of
the loop (we only check the uses of regular stmts). Janis reported to us a
case of miscompilation in SPEC that suffers from this problem. This is the
situation that we weren't handling:
# ivtmp.1197_270 = PHI <256(34), ivtmp.1197_244(35)>;
# ch_269 = PHI <256(34), ch_118(35)>;
>> # sfirst_20 = PHI <sfirst_58(34), sfirst_113(35)>;
<LOOP>:;
*sfirst_20 = -1;
sfirst_113 = sfirst_20 + 4B;
ch_118 = ch_269 - 1;
ivtmp.1197_244 = ivtmp.1197_270 - 1;
if (ivtmp.1197_244 != 0) goto <L45>; else goto <LOOP_EXIT>;
<L45>:;
goto <bb 20> (<LOOP>);
>> # sfirst_194 = PHI <sfirst_20(20)>;
<LOOP_EXIT>:;
sfirst_72 = sfirst_194 + -1020B;
...
I can't reproduce this problem with the current mainline snapshot (I could
with an older one), but I guess this situation may occur, so we need to
detect such phis and avoid vectorization for now.
bootstrapped and tested on powerpc-darwin.
ok for mainline?
thanks,
dorit
Changelog:
* tree-vectorizer.c (vect_mark_stmts_to_be_vectorized): Check if
phis are used out of the loop.
Patch:
Index: tree-vectorizer.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-vectorizer.c,v
retrieving revision 2.64
diff -u -3 -p -r2.64 tree-vectorizer.c
--- tree-vectorizer.c 24 Jan 2005 20:47:43 -0000 2.64
+++ tree-vectorizer.c 31 Jan 2005 07:57:04 -0000
@@ -5142,17 +5142,36 @@ vect_mark_stmts_to_be_vectorized (loop_v
int j;
use_optype use_ops;
stmt_vec_info stmt_info;
+ basic_block bb;
+ tree phi;
if (vect_debug_details (NULL))
fprintf (dump_file, "\n<<vect_mark_stmts_to_be_vectorized>>\n");
+ bb = loop->header;
+ for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
+ {
+ if (vect_debug_details (NULL))
+ {
+ fprintf (dump_file, "init: phi relevant? ");
+ print_generic_expr (dump_file, phi, TDF_SLIM);
+ }
+
+ if (vect_stmt_relevant_p (phi, loop_vinfo))
+ {
+ if (vect_debug_details (NULL))
+ fprintf (dump_file, "unsupported reduction/induction.");
+ return false;
+ }
+ }
+
VARRAY_TREE_INIT (worklist, 64, "work list");
/* 1. Init worklist. */
for (i = 0; i < nbbs; i++)
{
- basic_block bb = bbs[i];
+ bb = bbs[i];
for (si = bsi_start (bb); !bsi_end_p (si); bsi_next (&si))
{
stmt = bsi_stmt (si);