aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-phiopt.cc
diff options
context:
space:
mode:
authorAndrew Pinski <quic_apinski@quicinc.com>2024-09-17 15:03:21 -0700
committerAndrew Pinski <quic_apinski@quicinc.com>2024-09-17 23:20:40 -0700
commit45cacfe7325bdbed4a2393927812561f64b9afd1 (patch)
tree76db09ab0292ac414a843f07da6d4ad142f65f8b /gcc/tree-ssa-phiopt.cc
parent8590dcd318151336261f8381e1a24caece9e2375 (diff)
downloadgcc-45cacfe7325bdbed4a2393927812561f64b9afd1.zip
gcc-45cacfe7325bdbed4a2393927812561f64b9afd1.tar.gz
gcc-45cacfe7325bdbed4a2393927812561f64b9afd1.tar.bz2
phiopt: C++ify cond_if_else_store_replacement
This C++ify cond_if_else_store_replacement by using range fors and changing using a std::pair instead of 2 vecs. I had a hard time understanding the code when there was 2 vecs so having a vec of a pair makes it easier to understand the relationship between the 2. gcc/ChangeLog: * tree-ssa-phiopt.cc (cond_if_else_store_replacement): Use range fors and use one vec for then/else stores instead of 2. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Diffstat (limited to 'gcc/tree-ssa-phiopt.cc')
-rw-r--r--gcc/tree-ssa-phiopt.cc25
1 files changed, 11 insertions, 14 deletions
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 488b450..d43832b 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -3587,9 +3587,6 @@ cond_if_else_store_replacement (basic_block then_bb, basic_block else_bb,
vec<ddr_p> then_ddrs, else_ddrs;
gimple *then_store, *else_store;
bool found, ok = false, res;
- struct data_dependence_relation *ddr;
- data_reference_p then_dr, else_dr;
- int i, j;
tree then_lhs, else_lhs;
basic_block blocks[3];
@@ -3640,8 +3637,8 @@ cond_if_else_store_replacement (basic_block then_bb, basic_block else_bb,
}
/* Find pairs of stores with equal LHS. */
- auto_vec<gimple *, 1> then_stores, else_stores;
- FOR_EACH_VEC_ELT (then_datarefs, i, then_dr)
+ auto_vec<std::pair<gimple *, gimple *>, 1> stores_pairs;
+ for (auto then_dr : then_datarefs)
{
if (DR_IS_READ (then_dr))
continue;
@@ -3652,7 +3649,7 @@ cond_if_else_store_replacement (basic_block then_bb, basic_block else_bb,
continue;
found = false;
- FOR_EACH_VEC_ELT (else_datarefs, j, else_dr)
+ for (auto else_dr : else_datarefs)
{
if (DR_IS_READ (else_dr))
continue;
@@ -3672,13 +3669,12 @@ cond_if_else_store_replacement (basic_block then_bb, basic_block else_bb,
if (!found)
continue;
- then_stores.safe_push (then_store);
- else_stores.safe_push (else_store);
+ stores_pairs.safe_push (std::make_pair (then_store, else_store));
}
/* No pairs of stores found. */
- if (!then_stores.length ()
- || then_stores.length () > (unsigned) param_max_stores_to_sink)
+ if (!stores_pairs.length ()
+ || stores_pairs.length () > (unsigned) param_max_stores_to_sink)
{
free_data_refs (then_datarefs);
free_data_refs (else_datarefs);
@@ -3706,7 +3702,7 @@ cond_if_else_store_replacement (basic_block then_bb, basic_block else_bb,
/* Check that there are no read-after-write or write-after-write dependencies
in THEN_BB. */
- FOR_EACH_VEC_ELT (then_ddrs, i, ddr)
+ for (auto ddr : then_ddrs)
{
struct data_reference *dra = DDR_A (ddr);
struct data_reference *drb = DDR_B (ddr);
@@ -3728,7 +3724,7 @@ cond_if_else_store_replacement (basic_block then_bb, basic_block else_bb,
/* Check that there are no read-after-write or write-after-write dependencies
in ELSE_BB. */
- FOR_EACH_VEC_ELT (else_ddrs, i, ddr)
+ for (auto ddr : else_ddrs)
{
struct data_reference *dra = DDR_A (ddr);
struct data_reference *drb = DDR_B (ddr);
@@ -3749,9 +3745,10 @@ cond_if_else_store_replacement (basic_block then_bb, basic_block else_bb,
}
/* Sink stores with same LHS. */
- FOR_EACH_VEC_ELT (then_stores, i, then_store)
+ for (auto &store_pair : stores_pairs)
{
- else_store = else_stores[i];
+ then_store = store_pair.first;
+ else_store = store_pair.second;
res = cond_if_else_store_replacement_1 (then_bb, else_bb, join_bb,
then_store, else_store);
ok = ok || res;