public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bruno at clisp dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/30267]  New: missed optimization due to bad range propagation without -fwrapv
Date: Wed, 20 Dec 2006 14:35:00 -0000	[thread overview]
Message-ID: <bug-30267-128@http.gcc.gnu.org/bugzilla/> (raw)

This program shows that some range propagation became worse between
gcc 4.0.2 and gcc 4.1.1.

=========================== foo.c ========================
int notneg (int x)
{
  return (~ -x) >= (-2147483647-1);
}
int negnot (int x)
{
  return (- ~x) <= 2147483647;
}
==========================================================


# With gcc 4.0.2 on i686-pc-linux-gnu the code is fully optimized:

$ gcc -O2 -fomit-frame-pointer -S foo.c && cat foo.s
        .file   "foo.c"
        .text
        .p2align 4,,15
.globl notneg
        .type   notneg, @function
notneg:
        movl    $1, %eax
        ret
        .size   notneg, .-notneg
        .p2align 4,,15
.globl negnot
        .type   negnot, @function
negnot:
        movl    $1, %eax
        ret
        .size   negnot, .-negnot
        .ident  "GCC: (GNU) 4.0.2"
        .section        .note.GNU-stack,"",@progbits


# With gcc 4.1.1 on i686-pc-linux-gnu the code is fully optimized with -fwrapv
# but not without -fwrapv:

$ gcc -O2 -fomit-frame-pointer -S foo.c && cat foo.s
        .file   "foo.c"
        .text
        .p2align 4,,15
.globl notneg
        .type   notneg, @function
notneg:
        xorl    %eax, %eax
        cmpl    $-2147483648, 4(%esp)
        setne   %al
        ret
        .size   notneg, .-notneg
        .p2align 4,,15
.globl negnot
        .type   negnot, @function
negnot:
        xorl    %eax, %eax
        cmpl    $2147483647, 4(%esp)
        setne   %al
        ret
        .size   negnot, .-negnot
        .ident  "GCC: (GNU) 4.1.1"
        .section        .note.GNU-stack,"",@progbits

$ gcc -O2 -fomit-frame-pointer -fwrapv -S foo.c && cat foo.s
        .file   "foo.c"
        .text
        .p2align 4,,15
.globl notneg
        .type   notneg, @function
notneg:
        movl    $1, %eax
        ret
        .size   notneg, .-notneg
        .p2align 4,,15
.globl negnot
        .type   negnot, @function
negnot:
        movl    $1, %eax
        ret
        .size   negnot, .-negnot
        .ident  "GCC: (GNU) 4.1.1"
        .section        .note.GNU-stack,"",@progbits

So somehow this seems to be linked to flag_wrapv. But regardless which
value is the result after signed overflow, any int >= INT_MIN and
any int <= INT_MAX should evaluate to 1 unconditionally.


-- 
           Summary: missed optimization due to bad range propagation without
                    -fwrapv
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bruno at clisp dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


             reply	other threads:[~2006-12-20 14:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-20 14:35 bruno at clisp dot org [this message]
2006-12-27 16:48 ` [Bug middle-end/30267] folding (~ -x) >= (-2147483647-1) to x != -2147483648 rguenth at gcc dot gnu dot org
2006-12-27 17:01 ` pinskia at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-30267-128@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).