Avoid PHI node re-allocation in loop copying

Message ID 20250109130443.64E103858D33@sourceware.org
State New
Headers
Series Avoid PHI node re-allocation in loop copying |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Richard Biener Jan. 9, 2025, 12:58 p.m. UTC
  duplicate_loop_body_to_header_edge redirects the original loop entry
edge to the loop copy header and the copied loop exit to the old
loop header.  But it does so in the order that requires temporary
space for an extra edge on the original loop header, causing
unnecessary re-allocations.  The following avoids this by swapping
the order of the redirects.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

This originally surfaced with the location_t work which effectively
changed PHI allocations and thus made some passes unexpectedly
get their PHI nodes re-allocated when calling loop_version.  Mitigation
for this was provided which might or might not be completely
resolved by this (the vectorizer change is, as far as my testing goes).

Pushed to trunk.

I don't plan to revert the location_t changes in this area though,
not at this stage at least.

Richard.

	* cfgloopmanip.cc (duplicate_loop_body_to_header_edge): When
	copying to the header edge first redirect the entry to the
	new loop and then the exit to the old to avoid PHI node
	re-allocation.
---
 gcc/cfgloopmanip.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/gcc/cfgloopmanip.cc b/gcc/cfgloopmanip.cc
index 534e556e1e4..17bcf9f4acc 100644
--- a/gcc/cfgloopmanip.cc
+++ b/gcc/cfgloopmanip.cc
@@ -1447,9 +1447,9 @@  duplicate_loop_body_to_header_edge (class loop *loop, edge e,
 	}
       else
 	{
+	  redirect_edge_and_branch_force (e, new_bbs[0]);
 	  redirect_edge_and_branch_force (new_spec_edges[SE_LATCH],
 					  loop->header);
-	  redirect_edge_and_branch_force (e, new_bbs[0]);
 	  set_immediate_dominator (CDI_DOMINATORS, new_bbs[0], e->src);
 	  e = new_spec_edges[SE_LATCH];
 	}