Bug 32244 - bit-field: optimization BUG
Summary: bit-field: optimization BUG
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Richard Biener
URL:
Keywords: wrong-code
Depends on: 30332
Blocks:
  Show dependency treegraph
 
Reported: 2007-06-07 13:36 UTC by s.nakayama
Modified: 2024-01-24 06:36 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.0
Known to fail: 2.95.4 4.1.2 4.2.0
Last reconfirmed: 2008-01-25 13:23:02


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description s.nakayama 2007-06-07 13:36:16 UTC
The output is different by the optimization.

testcase:
#include <stdio.h>

struct foo
{
  unsigned long long b:33;
};


int main()
{
  struct foo x = {2};
  printf("%llx\n",(x.b<<32));
  return 0;
}

result:
$ gcc bit.c -o bit; ./bit
200000000

$ gcc -O bit.c -o bit; ./bit
0
Comment 1 Richard Biener 2007-06-08 10:28:26 UTC
Confirmed.  We are wrongly expanding

;; D.2027 = D.2026 << 32
(insn 18 17 0 (parallel [
            (set (reg:DI 59 [ D.2027 ])
                (ashift:DI (reg:DI 60 [ D.2026 ])
                    (const_int 32 [0x20])))
            (clobber (reg:CC 17 flags))
        ]) -1 (nil)
    (nil))

without properly truncating the result to 33 bit precision.

Not a regression.
Comment 2 Richard Biener 2007-12-11 13:54:59 UTC
Very similar (apart from typeof) to PR30332.
Comment 3 Richard Biener 2008-01-25 13:23:02 UTC
Uh, all is broken ;)

  1) we don't reduce shift or rotate results

  2) we do wrong folding of rotates

  3) we do wrong expansion of rotates

struct foo
{
  unsigned long long b:40;
} x;

extern void abort (void);

void test1(unsigned long long res)
{
  /* Build a rotate expression on a 40 bit argument.  */
  if ((x.b<<8) + (x.b>>32) != res)
    abort ();
}

int main()
{
  x.b = 0x0100000001;
  test1(0x0000000101);
  x.b = 0x0100000000;
  test1(0x0000000001);
  return 0;
}
Comment 4 Richard Biener 2008-01-25 14:21:53 UTC
I split off the rotate issues to PR34971.
Comment 5 Richard Biener 2008-01-25 15:33:54 UTC
Subject: Bug 32244

Author: rguenth
Date: Fri Jan 25 15:33:09 2008
New Revision: 131828

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131828
Log:
2008-01-25  Richard Guenther  <rguenther@suse.de>

	PR middle-end/32244
	* expr.c (expand_expr_real_1): Reduce result of LSHIFT_EXPR
	to its bitfield precision if required.

	* gcc.c-torture/execute/pr32244-1.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr32244-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/expr.c
    trunk/gcc/testsuite/ChangeLog

Comment 6 Richard Biener 2008-01-25 15:37:11 UTC
Fixed.