aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Hubicka <jh@suse.cz>2023-08-10 18:39:33 +0200
committerJan Hubicka <jh@suse.cz>2023-08-10 18:39:33 +0200
commit546bf79bd72df0e024323345a5d08f9ceba513f6 (patch)
tree07253b4f0aa9d70b08393a5e45c5299016d4b1ca
parente41103081bfa341bdb1037e94d6b8f7a0af39067 (diff)
downloadgcc-546bf79bd72df0e024323345a5d08f9ceba513f6.zip
gcc-546bf79bd72df0e024323345a5d08f9ceba513f6.tar.gz
gcc-546bf79bd72df0e024323345a5d08f9ceba513f6.tar.bz2
Fix profile updating bug in tree-ssa-threadupdate
ssa_fix_duplicate_block_edges later calls update_profile to correct profile after threading. In the testcase this does not work since we lose track of the duplicated edge. This happens because redirect_edge_and_branch returns NULL if the edge already has correct destination which is the case. gcc/ChangeLog: * tree-ssa-threadupdate.cc (ssa_fix_duplicate_block_edges): Fix profile update. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/phi_on_compare-1.c: Check profile consistency.
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/phi_on_compare-1.c3
-rw-r--r--gcc/tree-ssa-threadupdate.cc21
2 files changed, 15 insertions, 9 deletions
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi_on_compare-1.c b/gcc/testsuite/gcc.dg/tree-ssa/phi_on_compare-1.c
index be504dd..923497f 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/phi_on_compare-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi_on_compare-1.c
@@ -1,5 +1,5 @@
/* { dg-do compile } */
-/* { dg-options "-Ofast -fdump-tree-dom2" } */
+/* { dg-options "-Ofast -fdump-tree-dom2 -fdump-tree-optimized-details-blocks" } */
void g (int);
void g1 (int);
@@ -33,3 +33,4 @@ f (long a, long b, long c, long d, long x)
optimization in the backward threader before killing the forward
threader. Similarly for the other phi_on_compare-*.c tests. */
/* { dg-final { scan-tree-dump-times "Removing basic block" 1 "dom2" } } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "optimized" } } */
diff --git a/gcc/tree-ssa-threadupdate.cc b/gcc/tree-ssa-threadupdate.cc
index d5416b2..a5b9a00 100644
--- a/gcc/tree-ssa-threadupdate.cc
+++ b/gcc/tree-ssa-threadupdate.cc
@@ -1059,14 +1059,19 @@ ssa_fix_duplicate_block_edges (struct redirection_data *rd,
threading path. */
if (!any_remaining_duplicated_blocks (path, i))
{
- e2 = redirect_edge_and_branch (victim, elast->dest);
- /* If we redirected the edge, then we need to copy PHI arguments
- at the target. If the edge already existed (e2 != victim
- case), then the PHIs in the target already have the correct
- arguments. */
- if (e2 == victim)
- copy_phi_args (e2->dest, elast, e2,
- path, multi_incomings ? 0 : i);
+ if (victim->dest != elast->dest)
+ {
+ e2 = redirect_edge_and_branch (victim, elast->dest);
+ /* If we redirected the edge, then we need to copy PHI arguments
+ at the target. If the edge already existed (e2 != victim
+ case), then the PHIs in the target already have the correct
+ arguments. */
+ if (e2 == victim)
+ copy_phi_args (e2->dest, elast, e2,
+ path, multi_incomings ? 0 : i);
+ }
+ else
+ e2 = victim;
}
else
{