aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-phiopt.cc
diff options
context:
space:
mode:
authorAndrew Pinski <quic_apinski@quicinc.com>2024-09-13 10:47:29 -0700
committerAndrew Pinski <quic_apinski@quicinc.com>2024-09-14 22:53:36 -0700
commit6e4244e8ceac939fe8a24470b4ff31c82e8bff21 (patch)
treec70e3bac90cf56bcc31cd009f1481fb15e9f4661 /gcc/tree-ssa-phiopt.cc
parent0b3133572edbd2b382e160ac78d7caf321f7f05b (diff)
downloadgcc-6e4244e8ceac939fe8a24470b4ff31c82e8bff21.zip
gcc-6e4244e8ceac939fe8a24470b4ff31c82e8bff21.tar.gz
gcc-6e4244e8ceac939fe8a24470b4ff31c82e8bff21.tar.bz2
phi-opt: Improve heuristics for factoring out with constant (again) [PR116699]
The heuristics for factoring out with a constant checks that the assignment statement is the last statement of the basic block but sometimes there is a predicate or a nop statement after the assignment. Rejecting this case does not make sense since both predicates and nop statements are removed and don't contribute any instructions. So we should skip over them when checking if the assignment statement was the last statement in the basic block. phi-opt-factor-1.c's f0 is such an example where it should catch it at phiopt1 (before predicates are removed) and should happen in a similar way as f1 (which uses a temporary variable rather than return). Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/116699 gcc/ChangeLog: * tree-ssa-phiopt.cc (factor_out_conditional_operation): Skip over nop/predicates for seeing the assignment is the last statement. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/phi-opt-factor-1.c: New test. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Diffstat (limited to 'gcc/tree-ssa-phiopt.cc')
-rw-r--r--gcc/tree-ssa-phiopt.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index e5413e4..7b12692 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -360,6 +360,12 @@ factor_out_conditional_operation (edge e0, edge e1, gphi *phi,
}
gsi = gsi_for_stmt (arg0_def_stmt);
gsi_next_nondebug (&gsi);
+ /* Skip past nops and predicates. */
+ while (!gsi_end_p (gsi)
+ && (gimple_code (gsi_stmt (gsi)) == GIMPLE_NOP
+ || gimple_code (gsi_stmt (gsi)) == GIMPLE_PREDICT))
+ gsi_next_nondebug (&gsi);
+ /* Reject if the statement was not at the end of the block. */
if (!gsi_end_p (gsi))
return NULL;
}