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/64454] New: optimize (x%5)%5


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

            Bug ID: 64454
           Summary: optimize (x%5)%5
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org

unsigned f(unsigned x){
  return (x%5)%5;
}

gives:

  _2 = x_1(D) % 5;
  _3 = _2 % 5;
  return _3;

It seems we could easily do better in 2 ways:

1) (x%y)%y could be simplified to x%y in match.pd. This would work even when y
is not a constant.

2) with VRP, depending on the interval for x, we may be able to simplify x%CST
to just x (or sometimes x+CST).


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