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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[[likely]] attribute not    |[[likely]] attribute is
                   |propagated from function    |lost by phiopt1 in some
                   |body to callers             |cases
                 CC|                            |pinskia at gcc dot gnu.org
          Component|middle-end                  |tree-optimization
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot 
gnu.org

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
clang/LLVM optimize all 3 cases the same.

For aarch64 even uses csel:
        ldrb    w8, [x0, #4]
        ldr     w9, [x0]
        cmp     w8, #0
        csel    w0, w9, wzr, ne


phiopt1 makes the likely predicate to be lost.

For this:
```
  if (b_2(D) != 0)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :
  // predicted likely by hot label predictor.
  // predicted unlikely by early return (on trees) predictor.
  goto <bb 5>; [INV]

  <bb 4> :
  // predicted unlikely by early return (on trees) predictor.

  <bb 5> :
  # _1 = PHI <1(3), 0(4)>
```

phiopt1 turns that into just:
  return b_2(D);

I can think of a way to fix this is by rejecting it in (early) phiopt1 if the
predicates are not return types.
This will allow jump threading to handle it to get the correct predicate on the
branch.

And yes -fdisable-tree-phiopt1 fixes the issue.

Reply via email to