Bug 53640 - Missed cmove with stores
Summary: Missed cmove with stores
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.7.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks: spec
  Show dependency treegraph
 
Reported: 2012-06-11 23:07 UTC by Andrew Pinski
Modified: 2012-06-12 09:29 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2012-06-11 23:07:50 UTC
Take:
int f(int a, int *b)
{
  if (a >= 2)
    *b = 1;
  else
    *b = 0;

  return *b;
}

int f1(int a, int *b)
{
  int t;
  if (a >= 2)
    t = 1;
  else
    t = 0;
  *b = t;

  return *b;
}

---- CUT ----
Both of these are the same.  f1 will produce better code.
Comment 1 Andrew Pinski 2012-06-11 23:08:50 UTC
Shows up in gobmk in spec 2006:
      else if (distance[pos] == -1)
 under_control[pos] = 0;
      else
 under_control[pos] = 1;
Comment 2 Richard Biener 2012-06-12 09:29:10 UTC
cond_if_else_store_replacement should do this, thus cselim.  But you need
-O3 as otherwise --param max-stores-to-sink is zero:

  /* Set PARAM_MAX_STORES_TO_SINK to 0 if either vectorization or if-conversion
     is disabled.  */
  if (!opts->x_flag_tree_vectorize || !opts->x_flag_tree_loop_if_convert)
    maybe_set_param_value (PARAM_MAX_STORES_TO_SINK, 0,
                           opts->x_param_values, opts_set->x_param_values);