Bug 27285 - [4.1 regression] ivopts postgresql miscompilation
Summary: [4.1 regression] ivopts postgresql miscompilation
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.1
: P3 critical
Target Milestone: 4.1.1
Assignee: Jakub Jelinek
URL:
Keywords: wrong-code
Depends on: 25985
Blocks:
  Show dependency treegraph
 
Reported: 2006-04-24 15:33 UTC by Jakub Jelinek
Modified: 2006-05-08 15:29 UTC (History)
4 users (show)

See Also:
Host:
Target: i686-linux
Build:
Known to work: 4.1.0
Known to fail: 4.1.1 4.2.0
Last reconfirmed: 2006-04-25 07:37:02


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2006-04-24 15:33:03 UTC
extern void abort (void);

struct S { unsigned char a, b, c, d[16]; };

void __attribute__ ((noinline))
foo (struct S *x, struct S *y)
{
  int a, b;
  unsigned char c, *d, *e;

  b = x->b;
  d = x->d;
  e = y->d;
  a = 0;
  while (b)
    {
      if (b >= 8)
        {
          c = 0xff;
          b -= 8;
        }
      else
        {
          c = 0xff << (8 - b);
          b = 0;
        }

      e[a] = d[a] & c;
      a++;
    }
}

int
main (void)
{
  struct S x = { 0, 25, 0, { 0xaa, 0xbb, 0xcc, 0xdd }};
  struct S y = { 0, 0, 0, { 0 }};

  foo (&x, &y);
  if (x.d[0] != y.d[0] || x.d[1] != y.d[1]
      || x.d[2] != y.d[2] || (x.d[3] & 0x80) != y.d[3])
    abort ();
   return 0;
}

On i686-linux with -O2 -m32 the loop is miscompiled, it copies over just
first 24 bits and not the 25th bit.  From quick skimming of the tree dumps,
this looks messed up by ivopts pass.  Seems to be a recent regression,
at least 20060304 GCC 4.1.x worked fine, while 20060420 does not.
Comment 1 Jakub Jelinek 2006-04-24 15:50:23 UTC
Caused by http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=112675
Comment 2 Andrew Pinski 2006-04-24 16:18:53 UTC
Does the mainline work if so something else that was needed was not backported.
Comment 3 Andrew Pinski 2006-04-24 21:39:58 UTC
Can you try the patch for PR25985 and see if it fixes your bug?
Comment 4 Andrew Pinski 2006-04-24 21:41:37 UTC
Actually it looks 100% the same testcase so that patch just needs backporting (I don't have time to test it at all).
Comment 5 Jakub Jelinek 2006-04-25 07:37:02 UTC
Yes, it fixes it.  Will regression test it on a bunch of arches and post to
gcc-patches.  Thanks.
Comment 6 Jakub Jelinek 2006-05-04 06:40:24 UTC
Subject: Bug 27285

Author: jakub
Date: Thu May  4 06:40:15 2006
New Revision: 113515

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113515
Log:
	PR tree-optimization/27285

	Backport from mainline:

	2006-03-28  Zdenek Dvorak  <dvorakz@suse.cz>

	PR tree-optimization/25985
	* tree-ssa-loop-niter.c (number_of_iterations_le,
	number_of_iterations_ne): Make comments more precise.
	(number_of_iterations_cond): Add only_exit argument.  Use the
	fact that signed variables do not overflow only when only_exit
	is true.
	(loop_only_exit_p): New.
	(number_of_iterations_exit): Pass result of loop_only_exit_p to
	number_of_iterations_cond.

	* gcc.c-torture/execute/pr27285.c: New test.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.c-torture/execute/pr27285.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_1-branch/gcc/tree-ssa-loop-niter.c

Comment 7 Jakub Jelinek 2006-05-04 06:44:06 UTC
Subject: Bug 27285

Author: jakub
Date: Thu May  4 06:43:50 2006
New Revision: 113516

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113516
Log:
	PR tree-optimization/27285
	* gcc.c-torture/execute/pr27285.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr27285.c
Modified:
    trunk/gcc/testsuite/ChangeLog

Comment 8 roger 2006-05-08 15:29:50 UTC
I've now reconfirmed that this has been fixed on the gcc-4_1-branch by
Jakub's backport of Zdenek's patch.  Thanks to you both.