Bug 22493 - [4.1 Regression] with -fwrapv -INT_MIN is still not positive
Summary: [4.1 Regression] with -fwrapv -INT_MIN is still not positive
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: 4.1.0
Assignee: James A. Morrison
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: patch, wrong-code
Depends on:
Blocks: 22084
  Show dependency treegraph
 
Reported: 2005-07-14 18:48 UTC by Andrew Pinski
Modified: 2005-07-28 04:45 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-07-19 13:42:00


Attachments
Treat flag_wrapv and min value in a special way (1.06 KB, patch)
2005-07-17 00:28 UTC, James A. Morrison
Details | Diff
Updated patch (1.56 KB, patch)
2005-07-23 08:25 UTC, James A. Morrison
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2005-07-14 18:48:01 UTC
Take the following code:
#include <limits.h>
void abort ();
void f(int i)
{
  if (i>0)
    abort();
  i = -i;
  if (i<0)
    return;
  abort ();
}

int main(void)
{
  f(INT_MIN);
  return 0;
}

This should not abort but does at -O2 -fwrapv and above because VRP is folding the conditional which 
is not true as -INT_MIN = INT_MIN still.  This causes us to mis compile Long.toString in libjava.
Comment 1 Andrew Pinski 2005-07-16 21:33:42 UTC
Note I should give credit to Andrew Haley who pointed me to the mis compiling of Long.toString.
Comment 2 James A. Morrison 2005-07-17 00:28:18 UTC
Created attachment 9291 [details]
Treat flag_wrapv and min value in a special way
Comment 3 Pawel Sikora 2005-07-17 20:35:52 UTC
(In reply to comment #2) 
> Created an attachment (id=9291) 
> Treat flag_wrapv and min value in a special way 
>  
 
patch cointains typo-bug. 
 
--- gcc-pr22493.patch   Sun Jul 17 20:07:13 2005 
+++ gcc-pr22493.patch   Sun Jul 17 22:33:27 2005 
@@ -53,7 +53,7 @@ 
 -      max = (vr0.min == TYPE_MIN_VALUE (TREE_TYPE (expr))) 
 -          ? TYPE_MAX_VALUE (TREE_TYPE (expr)) 
 -          : fold_unary_to_constant (code, TREE_TYPE (expr), vr0.min); 
-+        type = VR_ANTI_RANGE; 
++        vr_type = VR_ANTI_RANGE; 
 +        max = fold_unary_to_constant (code, TREE_TYPE (expr), vr0.max); 
 +        max = int_const_binop (MINUS_EXPR, max, one, 0); 
 +        min = int_const_binop (PLUS_EXPR, min, one, 0); 
 
Comment 4 James A. Morrison 2005-07-19 07:15:09 UTC
 The attached patch, with the typo fixed and using
 int_const_binop (PLUS_EXPR, vr0.min, one, 0) fixed the optimization failures of
Divide_1 in the testsuite.
Comment 5 Andrew Pinski 2005-07-19 13:41:59 UTC
Confirmed.
Comment 6 James A. Morrison 2005-07-23 08:25:32 UTC
Created attachment 9336 [details]
Updated patch

 This should also fix:
/* { dg-do run } */
/* { dg-options "-O1 -ftree-vrp" } */

extern void abort ();
extern void exit (int);

int f (int a) {
	if (a != 2) {
		a = -a;
		if (a == 2)
		  return 0;
		return 1;
	}
	return 1;
}

int main (int argc, char *argv[]) {
	if (f (-2))
		abort ();
	exit (0);
}

 which fails right now.
Comment 7 Andrew Pinski 2005-07-25 00:11:07 UTC
Patch posted here: <http://gcc.gnu.org/ml/gcc-patches/2005-07/msg01566.html>.
Comment 9 James A. Morrison 2005-07-28 04:45:44 UTC
 Fixed in the commit above.