[PATCH] Fix PR34027, SCEV const-prop pessimizes -Os

Richard Guenther richard.guenther@gmail.com
Sun Nov 11 22:34:00 GMT 2007


With the now famous enough testcase

unsigned long long foobar(unsigned long long ns)
{
  while(ns >= 1000000000L)
    ns -= 1000000000L;
  return ns;
}

SCEV const-prop creates the expression

  ns + (ns /[fl] 1000000000L) / -1000000000L

for the final value of ns and we are not able to fold this
to the more efficient modulus expression,

The following patch does extend fold to handle this
case, but as it was very late when I wrote this patch I'd
appreciate another eye on possible corner-cases that
we could get wrong.

Thanks,
Richard.

2007-11-11  Richard Guenther  <rguenther@suse.de>

        PR middle-end/34027
        * fold-const.c (fold_binary): Fold n - (n / m) * m to n % m.

        * gcc.dg/pr34027-1.c: New testcase.
        * gcc.dg/pr34027-2.c: Likewise.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-pr34027.diff
Type: text/x-patch
Size: 3531 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20071111/57024ebf/attachment.bin>


More information about the Gcc-patches mailing list