Bug 23657 - [4.1 Regression] Wrong code generated: too much optimized out
Summary: [4.1 Regression] Wrong code generated: too much optimized out
Status: RESOLVED DUPLICATE of bug 23509
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.1.0
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: alias, patch, wrong-code
Depends on:
Blocks:
 
Reported: 2005-08-31 16:05 UTC by Marcin 'Qrczak' Kowalczyk
Modified: 2005-08-31 22:23 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-08-31 16:19:38


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcin 'Qrczak' Kowalczyk 2005-08-31 16:05:23 UTC
/* The result should be 7. When compiled with
   gcc version 4.1.0 20050815 (experimental)
   with some patches from PLD (incl. PR7776, PR20297, PR23128, PR22533, PR23386)
   with -O, the result is 0. */
#include <stdio.h>
int arr[100];
int *alloc(void) {return arr;}
void fill(int n) {
   int *result = alloc();
   int *dest = result;
   for(;;) {
      int *next;
      dest[0] = 7;
      if (--n == 0) break;
      next = dest + 1;
      dest = next;
   }
}
int main(void) {
   fill(5);
   printf("%d\n", arr[1]);
   return 0;
}
/* Looking at the generated assembly code, the whole loop is optimized out,
   except for filling the first element. Using less temporaries or inlining
   alloc() makes the bug disappear. The bug manifests only with optimization 
   turned on. */
Comment 1 Andrew Pinski 2005-08-31 16:19:38 UTC
Confirmed, between t41.copyrename2 and t42.dom2, the V_MAY_DEF is removed.
After
  *next_8 = 7;

Before:
  #   TMT.51_18 = V_MAY_DEF <TMT.51_4>;
  *dest_2 = 7;

I think we are forgetting to copy the alias info.
I think this is fixed by the patch for PR 23509:
http://gcc.gnu.org/ml/gcc-patches/2005-08/msg01647.html

The tree-cfg.c part that is.
Comment 2 Marcin 'Qrczak' Kowalczyk 2005-08-31 22:11:06 UTC
> I think this is fixed by the patch for PR 23509:
> http://gcc.gnu.org/ml/gcc-patches/2005-08/msg01647.html

Indeed, applying this patch and recompiling gcc fixed the bug. Thanks.
Comment 3 Andrew Pinski 2005-08-31 22:14:45 UTC
(In reply to comment #2)
> Indeed, applying this patch and recompiling gcc fixed the bug. Thanks.

Thanks for trying the patch. I only thought about this patch because of the symptom was about the 
same as other bug was.
Comment 4 Marcin 'Qrczak' Kowalczyk 2005-08-31 22:23:02 UTC

*** This bug has been marked as a duplicate of 23509 ***