public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59845] New: loop optimization problem when profiling
@ 2014-01-16 18:12 arshamidi at gmail dot com
  2014-01-16 19:08 ` [Bug c++/59845] " arshamidi at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: arshamidi at gmail dot com @ 2014-01-16 18:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59845

            Bug ID: 59845
           Summary: loop optimization problem when profiling
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arshamidi at gmail dot com

I'm using g++ with GCC 4.8.1; when I use fprofile-generate too optimize my
code, it actually slows down the process time: (constant folding problem within
loop?)

int main(){

    int n;
    int i;
    //int n2;
    printf("Enter a number: ");
    scanf("%d", &n);
    //n2 = n/2;
    printf("divisors are:\n\n");

    for (i=1; i <= /*n2*/ n/2; i++)
        if (n%i == 0)
            printf("\n%d", i);

    printf("\n\n end.\n");

    return 0;
}

Here I must use the constant 'n2' (commented out) too actually get the desired
speed -in combination with -fprofile-generate. 
I'm using the following switches:
-Ofast;-fomit-frame-pointer;-march=core2; -mfpmath=sse; -fprofile-generate;
-Wall

no problem without -fprofile-generate and -fprofile-use


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/59845] loop optimization problem when profiling
  2014-01-16 18:12 [Bug c++/59845] New: loop optimization problem when profiling arshamidi at gmail dot com
@ 2014-01-16 19:08 ` arshamidi at gmail dot com
  2014-01-16 19:18 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: arshamidi at gmail dot com @ 2014-01-16 19:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59845

--- Comment #1 from ArshaGCC <arshamidi at gmail dot com> ---
I found that only when I use very high vales for input the problem persists.
for example when using 123456 as input for profiling it generates incorrect
code but when using 12345 as input the correct code will be generated.

Input is an integer and I can specify very long values for input like:
123456789.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/59845] loop optimization problem when profiling
  2014-01-16 18:12 [Bug c++/59845] New: loop optimization problem when profiling arshamidi at gmail dot com
  2014-01-16 19:08 ` [Bug c++/59845] " arshamidi at gmail dot com
@ 2014-01-16 19:18 ` pinskia at gcc dot gnu.org
  2014-01-17  8:52 ` arshamidi at gmail dot com
  2015-02-15 10:59 ` arshamidi at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-01-16 19:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59845

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>(constant folding problem within loop?)

No it is doing the following:

if (n>=1)
{
  i = 1;
  while (true)
    {
      if (n%i == 0)
        {
          printf("\n%d", i);
          i++;
          if (n/2 < i) break;
        }
      else
        {
          i++;
          if (n/2 < i) break;
        }
    }

}


Notice the load from n is not pulled out of the loop and that is because the
compiler thinks n escapes via scanf.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/59845] loop optimization problem when profiling
  2014-01-16 18:12 [Bug c++/59845] New: loop optimization problem when profiling arshamidi at gmail dot com
  2014-01-16 19:08 ` [Bug c++/59845] " arshamidi at gmail dot com
  2014-01-16 19:18 ` pinskia at gcc dot gnu.org
@ 2014-01-17  8:52 ` arshamidi at gmail dot com
  2015-02-15 10:59 ` arshamidi at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: arshamidi at gmail dot com @ 2014-01-17  8:52 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59845

--- Comment #3 from ArshaGCC <arshamidi at gmail dot com> ---
I further analyzed and found an interesting issue:

The optimizer bug (profile optimizer) occurs when input > 32768. When input is
less than or equal to 32768 (2^15) it always generate the correct optimized
code.

Could it be an optimization bug found in profile optimizer?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/59845] loop optimization problem when profiling
  2014-01-16 18:12 [Bug c++/59845] New: loop optimization problem when profiling arshamidi at gmail dot com
                   ` (2 preceding siblings ...)
  2014-01-17  8:52 ` arshamidi at gmail dot com
@ 2015-02-15 10:59 ` arshamidi at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: arshamidi at gmail dot com @ 2015-02-15 10:59 UTC (permalink / raw)
  To: gcc-bugs

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

ArshaGCC <arshamidi at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from ArshaGCC <arshamidi at gmail dot com> ---
With the new GCC 4.9 (GCC 4.9.2 currently i'm using), the problem seems to be
resolved.

Thanks.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-02-15 10:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-16 18:12 [Bug c++/59845] New: loop optimization problem when profiling arshamidi at gmail dot com
2014-01-16 19:08 ` [Bug c++/59845] " arshamidi at gmail dot com
2014-01-16 19:18 ` pinskia at gcc dot gnu.org
2014-01-17  8:52 ` arshamidi at gmail dot com
2015-02-15 10:59 ` arshamidi at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).