From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3510 invoked by alias); 3 Aug 2008 00:26:17 -0000 Received: (qmail 3502 invoked by uid 22791); 3 Aug 2008 00:26:16 -0000 X-Spam-Check-By: sourceware.org Received: from dessent.net (HELO dessent.net) (69.60.119.225) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 03 Aug 2008 00:25:37 +0000 Received: from localhost.localdomain ([127.0.0.1] helo=dessent.net) by dessent.net with esmtp (Exim 4.50) id 1KPRPj-0005wi-9q; Sun, 03 Aug 2008 00:25:35 +0000 Message-ID: <4894FAFE.5982D164@dessent.net> Date: Sun, 03 Aug 2008 00:26:00 -0000 From: Brian Dessent Reply-To: gcc-help@gcc.gnu.org X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) MIME-Version: 1.0 To: Alexey Neyman CC: gcc-help@gcc.gnu.org Subject: Re: Bug with -ftree-vrp? References: <200808021704.38246.stilor@att.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-08/txt/msg00013.txt.bz2 Alexey Neyman wrote: > The problem is that with -O2, the second conditional gets optimized > away. However, such optimization results in a misbehavior for the > minimum number representable in 32 bits, 0x80000000. The option which > triggers this optimization is -ftree-vrp. Signed integer overflow is undefined in ISO C. If v = INT_MIN then v = -v is undefined, and hence the compiler can assume this won't occur and optimize away the test since a conformant program does not invoke undefined behavior. Yes, there is some debate around the legitimacy of this optimization because "traditional" C has more or less held that signed integer overflow is perfectly defined on all two's compliment machines (i.e. everywhere.) But the standard leaves it undefined and so gcc is within its right to do this optimization, so say the language lawyers. You may be interested in the options -fno-strict-overflow, -fwrapv, and -Wstrict-overflow. Brian