https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127440

            Bug ID: 127440
           Summary: cond_store_replacement_limited should support diamond
                    shapped bb
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Created attachment 65614
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65614&action=edit
testcase

Sometimes (and due to other factoring), we are left with diamond shapped cfg
and cond_store_replacement_limited will not do anything with it.

This is wrong as we should be able to handle it as long as the store is before
the condition.

A reduced example is attached; though this can show up with some more complex
factoring in really; an example is gcc.dg/tree-ssa/ssa-dom-cse-3.c if we factor
out the load and we are left with:
```
  <bb 2> :
  a = 0;
  if (b_5(D) != 0)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :
  a = 1;
  // predicted unlikely by early return (on trees) predictor.
  goto <bb 5>; [INV]

  <bb 4>:

  <bb 5> :
  _1 = a;
  return _1;
```

Which then we can do a cs-elim too on the a but currently do because of the
extra bb.

Reply via email to