This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/71149] New: missing modulo 2 optimization converting result to bool


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

            Bug ID: 71149
           Summary: missing modulo 2 optimization converting result to
                    bool
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

One would expect GCC to emit comparably efficient code for all three functions
below, but it only does so for odd_mod and odd_and but not for the equivalent
odd_mod_cvt function.  Clang emits the same optimal code for all three
functions.

$ cat xxx.cpp && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc
-Dbool=_Bool -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout -o/dev/null
-xc xxx.cpp
int odd_mod (int a) {
    return (a % 2) != 0;
}

_Bool odd_mod_cvt (int a) {
    return a % 2;
}

int odd_and (int a) {
    return (a & 1) != 0;
}


;; Function odd_mod (odd_mod, funcdef_no=0, decl_uid=1745, cgraph_uid=0,
symbol_order=0)

odd_mod (int a)
{
  int _1;

  <bb 2>:
  _1 = a_4(D) & 1;
  return _1;

}



;; Function odd_mod_cvt (odd_mod_cvt, funcdef_no=1, decl_uid=1748,
cgraph_uid=1, symbol_order=1)

odd_mod_cvt (int a)
{
  int _1;
  _Bool _3;

  <bb 2>:
  _1 = a_2(D) % 2;
  _3 = _1 != 0;
  return _3;

}



;; Function odd_and (odd_and, funcdef_no=2, decl_uid=1751, cgraph_uid=2,
symbol_order=2)

odd_and (int a)
{
  int _1;

  <bb 2>:
  _1 = a_3(D) & 1;
  return _1;

}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]