public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Duplicating loops and virtual phis
@ 2017-05-12 20:42 Steve Ellcey
  2017-05-13  6:18 ` Richard Biener
  0 siblings, 1 reply; 8+ messages in thread
From: Steve Ellcey @ 2017-05-12 20:42 UTC (permalink / raw)
  To: gcc

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2148 bytes --]

(Short version of this email, is there a way to recalculate/rebuild virtual
phi nodes after modifying the CFG.)

I have a question about duplicating loops and virtual phi nodes.
I am trying to implement the following optimization as a pass:

Transform:

   for (i = 0; i < n; i++) {
	A[i] = A[i] + B[i];
	C[i] = C[i-1] + D[i];
   }

Into:

   if (noalias between A&B, A&C, A&D)
	for (i = 0; i < 100; i++)
		A[i] = A[i] + B[i];
	for (i = 0; i < 100; i++)
		C[i] = C[i-1] + D[i];
   else
	for (i = 0; i < 100; i++) {
		A[i] = A[i] + B[i];
		C[i] = C[i-1] + D[i];
	}

Right now the vectorizer sees that 'C[i] = C[i-1] + D[i];' cannot be
vectorized so it gives up and does not vectorize the loop.  If we split
up the loop into two loops then the vector add with A[i] could be vectorized
even if the one with C[i] could not.

Currently I can introduce the first 'if' that checks for aliasing by
using loop_version() and that seems to work OK.  (My actual compare
for aliasing is actually just an approximation for now.)

Where I am running into problems is with splitting up the single loop
under the noalias if condition into two sequential loops (which I then
intend to 'thin out' by removing one or the other set of instructions.
I am using slpeel_tree_duplicate_loop_to_edge_cfg() for that loop duplication
and while I get the CFG I want, the pass ends with verify_ssa failing due
to bad virtual/MEM PHI nodes.  Perhaps there is a different function that
I should use duplicate the loop.

a.c: In function ‘foo’:
a.c:2:5: error: PHI node with wrong VUSE on edge from BB 13
 int foo(int *a, int *b, int *c, int *d, int n)
     ^~~
.MEM_40 = PHI <.MEM_15(D)(13), .MEM_34(9)>
expected .MEM_58
a.c:2:5: internal compiler error: verify_ssa failed

I have tried to fix up the PHI node by hand using SET_PHI_ARG_DEF but
have not had any luck.  I was wondering if there was any kind of
'update all the phi nodes' function or just a 'update the virtual phi
nodes' function.  The non-virtual PHI nodes seem to be OK, it is just
the virtual ones that seem wrong after I duplicate the loop into two
consecutive loops.

Steve Ellcey
sellcey@cavium.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-05-22  8:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-12 20:42 Duplicating loops and virtual phis Steve Ellcey
2017-05-13  6:18 ` Richard Biener
2017-05-15 16:56   ` Steve Ellcey
2017-05-15 18:32     ` Richard Biener
2017-05-17  9:41       ` Bin.Cheng
2017-05-17 15:58         ` Steve Ellcey
2017-05-22  0:42         ` Kugan Vivekanandarajah
2017-05-22  8:31           ` Bin.Cheng

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).