Message ID | patch-17717-tamar@arm.com |
---|---|
State | New |
Headers | show |
Series | middle-end ifcvt: replace C++ sort with vec::qsort [PR109154] | expand |
On Tue, 19 Sep 2023, Tamar Christina wrote: > Hi All, > > As requested later on, this replaces the C++ sort with vec::qsort. > > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > Ok for master? OK. > Thanks, > Tamar > > gcc/ChangeLog: > > PR tree-optimization/109154 > * tree-if-conv.cc (INCLUDE_ALGORITHM): Remove. > (cmp_arg_entry): New. > (predicate_scalar_phi): Use it. > > --- inline copy of patch -- > diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc > index 799f071965e5c41eb352b5530cf1d9c7ecf7bf25..0d7ac82986f399f1c5ff91c04ddb524813ab27de 100644 > --- a/gcc/tree-if-conv.cc > +++ b/gcc/tree-if-conv.cc > @@ -80,7 +80,6 @@ along with GCC; see the file COPYING3. If not see > <L18>:; > */ > > -#define INCLUDE_ALGORITHM > #include "config.h" > #include "system.h" > #include "coretypes.h" > @@ -2045,6 +2044,28 @@ gen_phi_nest_statement (gphi *phi, gimple_stmt_iterator *gsi, > return lhs; > } > > +typedef std::pair <tree, std::pair <unsigned, unsigned>> ArgEntry; > +static int > +cmp_arg_entry (const void *p1, const void *p2) > +{ > + const ArgEntry sval1 = *(const ArgEntry *)p1; > + const ArgEntry sval2 = *(const ArgEntry *)p2; > + auto x1 = sval1.second; > + auto x2 = sval2.second; > + > + if (x1.first < x2.first) > + return -1; > + else if (x1.first > x2.first) > + return 1; > + > + if (x1.second < x2.second) > + return -1; > + else if (x1.second > x2.second) > + return 1; > + > + return 0; > +} > + > /* Replace a scalar PHI node with a COND_EXPR using COND as condition. > This routine can handle PHI nodes with more than two arguments. > > @@ -2186,7 +2207,6 @@ predicate_scalar_phi (gphi *phi, gimple_stmt_iterator *gsi) > /* Determine element with max number of occurrences and complexity. Looking at only > number of occurrences as a measure for complexity isn't enough as all usages can > be unique but the comparisons to reach the PHI node differ per branch. */ > - typedef std::pair <tree, std::pair <unsigned, unsigned>> ArgEntry; > auto_vec<ArgEntry> argsKV; > for (i = 0; i < args.length (); i++) > { > @@ -2204,10 +2224,7 @@ predicate_scalar_phi (gphi *phi, gimple_stmt_iterator *gsi) > } > > /* Sort elements based on rankings ARGS. */ > - std::sort(argsKV.begin(), argsKV.end(), [](const ArgEntry &left, > - const ArgEntry &right) { > - return left.second < right.second; > - }); > + argsKV.qsort (cmp_arg_entry); > > for (i = 0; i < args.length (); i++) > args[i] = argsKV[i].first; > > > > >
--- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -80,7 +80,6 @@ along with GCC; see the file COPYING3. If not see <L18>:; */ -#define INCLUDE_ALGORITHM #include "config.h" #include "system.h" #include "coretypes.h" @@ -2045,6 +2044,28 @@ gen_phi_nest_statement (gphi *phi, gimple_stmt_iterator *gsi, return lhs; } +typedef std::pair <tree, std::pair <unsigned, unsigned>> ArgEntry; +static int +cmp_arg_entry (const void *p1, const void *p2) +{ + const ArgEntry sval1 = *(const ArgEntry *)p1; + const ArgEntry sval2 = *(const ArgEntry *)p2; + auto x1 = sval1.second; + auto x2 = sval2.second; + + if (x1.first < x2.first) + return -1; + else if (x1.first > x2.first) + return 1; + + if (x1.second < x2.second) + return -1; + else if (x1.second > x2.second) + return 1; + + return 0; +} + /* Replace a scalar PHI node with a COND_EXPR using COND as condition. This routine can handle PHI nodes with more than two arguments. @@ -2186,7 +2207,6 @@ predicate_scalar_phi (gphi *phi, gimple_stmt_iterator *gsi) /* Determine element with max number of occurrences and complexity. Looking at only number of occurrences as a measure for complexity isn't enough as all usages can be unique but the comparisons to reach the PHI node differ per branch. */ - typedef std::pair <tree, std::pair <unsigned, unsigned>> ArgEntry; auto_vec<ArgEntry> argsKV; for (i = 0; i < args.length (); i++) { @@ -2204,10 +2224,7 @@ predicate_scalar_phi (gphi *phi, gimple_stmt_iterator *gsi) } /* Sort elements based on rankings ARGS. */ - std::sort(argsKV.begin(), argsKV.end(), [](const ArgEntry &left, - const ArgEntry &right) { - return left.second < right.second; - }); + argsKV.qsort (cmp_arg_entry); for (i = 0; i < args.length (); i++) args[i] = argsKV[i].first;