public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/28045]  New: Bitfield, &&, and optimization => bad code generation
@ 2006-06-15 19:34 Jerry dot James at usu dot edu
  2006-06-15 20:07 ` [Bug c/28045] " rguenth at gcc dot gnu dot org
                   ` (12 more replies)
  0 siblings, 13 replies; 15+ messages in thread
From: Jerry dot James at usu dot edu @ 2006-06-15 19:34 UTC (permalink / raw)
  To: gcc-bugs

This is a stripped-down bit of code representing a bad code generation problem
we've been having with XEmacs 21.5 + gcc 4.X + optimization.  I can reproduce
with Fedora Core 5's packaging of gcc 4.1.1 on the x86_64 platform, and with
Ubuntu's packaging of gcc 4.0.3 on the i386 platform.

Compile the following code without optimization, and it reports that the
negation of 1 is -1, which is in bounds.  Compile with any -O flag (confirmed
for -O, -O2, -O3, and -Os) and the code reports that the negation of 1 is -1,
which is out of bounds.  If I break the && expression up into 2 consecutive if
statements to see which bound is supposedly violated, the optimized code
reports that -1 is within each bound individually.

Things that have no effect: int/long are interchangeable; the size of the "tag"
bitfield doesn't seem to matter, so long as the "tag" size and the "val" size
add up to "INT_BITS".

I also tried compiling with all of the flags turned on by -O, but without -O
itself.  Good code is generated in that case.

#include <stdio.h>

#define INT_BITS (sizeof(int) * 8)
#define MAX_VALUE (int)((1UL << (INT_BITS - 2)) - 1UL)
#define MIN_VALUE (-MAX_VALUE - 1)

struct tagged_int
{
  int tag: 2;
  int val: INT_BITS - 2;
};

static void
negate (struct tagged_int accum)
{
  printf ("min = %d, max = %d\n", MIN_VALUE, MAX_VALUE);
  printf ("The negation of 1 is %d, which is ", -(int)accum.val);
  if (-(int)accum.val <= MAX_VALUE && -(int)accum.val >= MIN_VALUE) {
    puts ("in bounds.");
  } else {
    puts ("out of bounds.");
  }
}

int
main ()
{
  struct tagged_int obj;

  obj.tag = 0;
  obj.val = 1L;
  negate(obj);
  return 0;
}


-- 
           Summary: Bitfield, &&, and optimization => bad code generation
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Jerry dot James at usu dot edu
 GCC build triplet: x86_64-redhat-linux
  GCC host triplet: x86_64-redhat-linux
GCC target triplet: x86_64-redhat-linux


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


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

* [Bug c/28045] Bitfield, &&, and optimization => bad code generation
  2006-06-15 19:34 [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation Jerry dot James at usu dot edu
@ 2006-06-15 20:07 ` rguenth at gcc dot gnu dot org
  2006-06-17 21:05 ` Jerry dot James at usu dot edu
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-06-15 20:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2006-06-15 20:04 -------
Works for me on the mainline.


-- 


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


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

* [Bug c/28045] Bitfield, &&, and optimization => bad code generation
  2006-06-15 19:34 [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation Jerry dot James at usu dot edu
  2006-06-15 20:07 ` [Bug c/28045] " rguenth at gcc dot gnu dot org
@ 2006-06-17 21:05 ` Jerry dot James at usu dot edu
  2006-06-17 22:06 ` Jerry dot James at usu dot edu
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Jerry dot James at usu dot edu @ 2006-06-17 21:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from Jerry dot James at usu dot edu  2006-06-17 21:04 -------
Created an attachment (id=11688)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=11688&action=view)
Testcase showing an optimizaton bug


-- 


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


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

* [Bug c/28045] Bitfield, &&, and optimization => bad code generation
  2006-06-15 19:34 [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation Jerry dot James at usu dot edu
  2006-06-15 20:07 ` [Bug c/28045] " rguenth at gcc dot gnu dot org
  2006-06-17 21:05 ` Jerry dot James at usu dot edu
@ 2006-06-17 22:06 ` Jerry dot James at usu dot edu
  2006-06-17 22:07 ` pinskia at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Jerry dot James at usu dot edu @ 2006-06-17 22:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from Jerry dot James at usu dot edu  2006-06-17 21:05 -------
I can confirm that both the mainline and the current 4.1 branch compile the
testcase correctly.  Nevertheless, both the current 4.1 branch and the mainline
(revision 114741) are still miscompiling XEmacs when any optimization at all is
used, so the testcase must be too simple.  I just attached a more complex
testcase that includes much of the actual code from XEmacs.  I trimmed this
down quite a bit from the original code, but it's still over 600 lines.  This
code illustrates the bug on both the i386 and x86_64 platforms.  You have to
link with the GMP library (-lgmp) when compiling.


-- 


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


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

* [Bug c/28045] Bitfield, &&, and optimization => bad code generation
  2006-06-15 19:34 [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation Jerry dot James at usu dot edu
                   ` (2 preceding siblings ...)
  2006-06-17 22:06 ` Jerry dot James at usu dot edu
@ 2006-06-17 22:07 ` pinskia at gcc dot gnu dot org
  2006-06-18 15:19 ` rguenth at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-06-17 22:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2006-06-17 22:06 -------
Reduced testcase:
struct a
{
   unsigned int bits : 1;
   signed long val : ((sizeof(long) * 8) - 1);
};
int Fnegate (struct a b)
{
  if ((-((long)b.val)) <= ((long) ((1UL << (((sizeof(long) * 8) - 1) - 1))
-1UL)) && (-((long)b.val)) >= (-(((long) ((1UL << (((sizeof(long) * 8) - 1) -
1)) -1UL))) - 1))
     return 0 ;
     abort ();
}
int main ()
{
  struct a b = {1, 1};
  Fnegate (b);
  return 0;
}


-- 


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


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

* [Bug c/28045] Bitfield, &&, and optimization => bad code generation
  2006-06-15 19:34 [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation Jerry dot James at usu dot edu
                   ` (3 preceding siblings ...)
  2006-06-17 22:07 ` pinskia at gcc dot gnu dot org
@ 2006-06-18 15:19 ` rguenth at gcc dot gnu dot org
  2006-06-18 16:35 ` [Bug middle-end/28045] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-06-18 15:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2006-06-18 10:58 -------
operand_equal_p (bD.1525.valD.1524, (long intD.2) bD.1525.valD.1524, 0)

is true.  make_range preserved the cast to (long int) for a reason, though.

If we fix operand_equal_p, we no longer fold the test, but keep

  if (-(long int) b.val <= 1073741823 && -(long int) b.val >= -1073741824)
    {
      return 0;
    }
  abort ();

so, I have a patch.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rguenth at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-06-18 10:58:42
               date|                            |


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


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

* [Bug middle-end/28045] [4.0/4.1/4.2 Regression] Bitfield, &&, and optimization => bad code generation
  2006-06-15 19:34 [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation Jerry dot James at usu dot edu
                   ` (4 preceding siblings ...)
  2006-06-18 15:19 ` rguenth at gcc dot gnu dot org
@ 2006-06-18 16:35 ` pinskia at gcc dot gnu dot org
  2006-06-19 14:49 ` rguenth at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-06-18 16:35 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu dot
                   |                            |org
          Component|c                           |middle-end
           Keywords|                            |wrong-code
      Known to fail|                            |4.0.0 4.1.0 4.2.0
      Known to work|                            |3.4.0
            Summary|Bitfield, &&, and           |[4.0/4.1/4.2 Regression]
                   |optimization => bad code    |Bitfield, &&, and
                   |generation                  |optimization => bad code
                   |                            |generation
   Target Milestone|---                         |4.0.4


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


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

* [Bug middle-end/28045] [4.0/4.1/4.2 Regression] Bitfield, &&, and optimization => bad code generation
  2006-06-15 19:34 [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation Jerry dot James at usu dot edu
                   ` (5 preceding siblings ...)
  2006-06-18 16:35 ` [Bug middle-end/28045] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
@ 2006-06-19 14:49 ` rguenth at gcc dot gnu dot org
  2006-06-19 14:57 ` [Bug middle-end/28045] [4.0/4.1 " rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-06-19 14:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from rguenth at gcc dot gnu dot org  2006-06-19 14:48 -------
Subject: Bug 28045

Author: rguenth
Date: Mon Jun 19 14:48:47 2006
New Revision: 114772

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114772
Log:
2006-06-19  Richard Guenther  <rguenther@suse.de>

        PR middle-end/28045
        * fold-const.c (operand_equal_p): Check if the argument types
        have the same precision before stripping NOPs.

        * gcc.dg/torture/pr28045.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr28045.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fold-const.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug middle-end/28045] [4.0/4.1 Regression] Bitfield, &&, and optimization => bad code generation
  2006-06-15 19:34 [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation Jerry dot James at usu dot edu
                   ` (6 preceding siblings ...)
  2006-06-19 14:49 ` rguenth at gcc dot gnu dot org
@ 2006-06-19 14:57 ` rguenth at gcc dot gnu dot org
  2006-06-19 16:31 ` Jerry dot James at usu dot edu
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-06-19 14:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2006-06-19 14:49 -------
Fixed on the mainline.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[4.0/4.1/4.2 Regression]    |[4.0/4.1 Regression]
                   |Bitfield, &&, and           |Bitfield, &&, and
                   |optimization => bad code    |optimization => bad code
                   |generation                  |generation


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


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

* [Bug middle-end/28045] [4.0/4.1 Regression] Bitfield, &&, and optimization => bad code generation
  2006-06-15 19:34 [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation Jerry dot James at usu dot edu
                   ` (7 preceding siblings ...)
  2006-06-19 14:57 ` [Bug middle-end/28045] [4.0/4.1 " rguenth at gcc dot gnu dot org
@ 2006-06-19 16:31 ` Jerry dot James at usu dot edu
  2006-06-23  9:57 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Jerry dot James at usu dot edu @ 2006-06-19 16:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from Jerry dot James at usu dot edu  2006-06-19 16:27 -------
On behalf of the XEmacs team, I thank you for your amazingly speedy attention
to this bug report.


-- 


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


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

* [Bug middle-end/28045] [4.0/4.1 Regression] Bitfield, &&, and optimization => bad code generation
  2006-06-15 19:34 [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation Jerry dot James at usu dot edu
                   ` (8 preceding siblings ...)
  2006-06-19 16:31 ` Jerry dot James at usu dot edu
@ 2006-06-23  9:57 ` rguenth at gcc dot gnu dot org
  2006-06-23  9:58 ` rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-06-23  9:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from rguenth at gcc dot gnu dot org  2006-06-23 09:52 -------
Subject: Bug 28045

Author: rguenth
Date: Fri Jun 23 09:52:40 2006
New Revision: 114929

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114929
Log:
2006-06-23  Richard Guenther  <rguenther@suse.de>

        PR middle-end/28045
        * fold-const.c (operand_equal_p): Check if the argument types
        have the same precision before stripping NOPs.

        * gcc.dg/torture/pr28045.c: New testcase.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/torture/pr28045.c
      - copied unchanged from r114772,
trunk/gcc/testsuite/gcc.dg/torture/pr28045.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/fold-const.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug middle-end/28045] [4.0/4.1 Regression] Bitfield, &&, and optimization => bad code generation
  2006-06-15 19:34 [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation Jerry dot James at usu dot edu
                   ` (9 preceding siblings ...)
  2006-06-23  9:57 ` rguenth at gcc dot gnu dot org
@ 2006-06-23  9:58 ` rguenth at gcc dot gnu dot org
  2006-06-23  9:59 ` rguenth at gcc dot gnu dot org
  2006-06-29 21:40 ` patchapp at dberlin dot org
  12 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-06-23  9:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from rguenth at gcc dot gnu dot org  2006-06-23 09:57 -------
Subject: Bug 28045

Author: rguenth
Date: Fri Jun 23 09:57:37 2006
New Revision: 114930

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=114930
Log:
2006-06-23  Richard Guenther  <rguenther@suse.de>

        PR middle-end/28045
        * fold-const.c (operand_equal_p): Check if the argument types
        have the same precision before stripping NOPs.

        * gcc.dg/torture/pr28045.c: New testcase.

Added:
    branches/gcc-4_0-branch/gcc/testsuite/gcc.dg/torture/pr28045.c
      - copied unchanged from r114772,
trunk/gcc/testsuite/gcc.dg/torture/pr28045.c
Modified:
    branches/gcc-4_0-branch/gcc/ChangeLog
    branches/gcc-4_0-branch/gcc/fold-const.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug middle-end/28045] [4.0/4.1 Regression] Bitfield, &&, and optimization => bad code generation
  2006-06-15 19:34 [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation Jerry dot James at usu dot edu
                   ` (10 preceding siblings ...)
  2006-06-23  9:58 ` rguenth at gcc dot gnu dot org
@ 2006-06-23  9:59 ` rguenth at gcc dot gnu dot org
  2006-06-29 21:40 ` patchapp at dberlin dot org
  12 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-06-23  9:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from rguenth at gcc dot gnu dot org  2006-06-23 09:57 -------
Fixed.


-- 

rguenth at gcc dot gnu dot org changed:

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


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


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

* [Bug middle-end/28045] [4.0/4.1 Regression] Bitfield, &&, and optimization => bad code generation
  2006-06-15 19:34 [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation Jerry dot James at usu dot edu
                   ` (11 preceding siblings ...)
  2006-06-23  9:59 ` rguenth at gcc dot gnu dot org
@ 2006-06-29 21:40 ` patchapp at dberlin dot org
  12 siblings, 0 replies; 15+ messages in thread
From: patchapp at dberlin dot org @ 2006-06-29 21:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from patchapp at dberlin dot org  2006-06-29 21:37 -------
Subject: Bug number PR28045

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is
http://gcc.gnu.org/ml/gcc-patches/2006-06/msg01000.html


-- 


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


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

* [Bug middle-end/28045] [4.0/4.1 Regression] Bitfield, &&, and optimization => bad code generation
       [not found] <bug-28045-4@http.gcc.gnu.org/bugzilla/>
@ 2014-02-16 13:17 ` jackie.rosen at hushmail dot com
  0 siblings, 0 replies; 15+ messages in thread
From: jackie.rosen at hushmail dot com @ 2014-02-16 13:17 UTC (permalink / raw)
  To: gcc-bugs

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

Jackie Rosen <jackie.rosen at hushmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jackie.rosen at hushmail dot com

--- Comment #13 from Jackie Rosen <jackie.rosen at hushmail dot com> ---
*** Bug 260998 has been marked as a duplicate of this bug. ***
Seen from the domain http://volichat.com
Page where seen: http://volichat.com/adult-chat-rooms
Marked for reference. Resolved as fixed @bugzilla.


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

end of thread, other threads:[~2014-02-16 13:17 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-15 19:34 [Bug c/28045] New: Bitfield, &&, and optimization => bad code generation Jerry dot James at usu dot edu
2006-06-15 20:07 ` [Bug c/28045] " rguenth at gcc dot gnu dot org
2006-06-17 21:05 ` Jerry dot James at usu dot edu
2006-06-17 22:06 ` Jerry dot James at usu dot edu
2006-06-17 22:07 ` pinskia at gcc dot gnu dot org
2006-06-18 15:19 ` rguenth at gcc dot gnu dot org
2006-06-18 16:35 ` [Bug middle-end/28045] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
2006-06-19 14:49 ` rguenth at gcc dot gnu dot org
2006-06-19 14:57 ` [Bug middle-end/28045] [4.0/4.1 " rguenth at gcc dot gnu dot org
2006-06-19 16:31 ` Jerry dot James at usu dot edu
2006-06-23  9:57 ` rguenth at gcc dot gnu dot org
2006-06-23  9:58 ` rguenth at gcc dot gnu dot org
2006-06-23  9:59 ` rguenth at gcc dot gnu dot org
2006-06-29 21:40 ` patchapp at dberlin dot org
     [not found] <bug-28045-4@http.gcc.gnu.org/bugzilla/>
2014-02-16 13:17 ` jackie.rosen at hushmail 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).