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

            Bug ID: 94589
           Summary: Optimize (i<=>0)>0 to i>0
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org
  Target Milestone: ---

g++-10 -std=gu++2a -O3

#include <compare>
bool k(int i){
  auto c=i<=>0;
  return c>0;
}

  <bb 2> [local count: 1073741824]:
  if (i_1(D) != 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 4>; [50.00%]

  <bb 3> [local count: 536870913]:
  _2 = i_1(D) >= 0;

  <bb 4> [local count: 1073741824]:
  # prephitmp_6 = PHI <_2(3), 0(2)>
  return prephitmp_6;

For most comparisons @ we do optimize (i<=>0)@0 to just i@0, but not for > and
<=. Spaceship operator<=> is very painful to use, but I expect we will end up
seeing a lot of it with C++20, and comparing its result with 0 is almost the
only way to use its output, so it seems important to optimize this common case.

(there is probably a very old dup, but I couldn't find it)

Reply via email to