]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR rtl-optimization/14669 (Wrong code with -O for enum values expression E4 <...
authorRoger Sayle <sayle@gcc.gnu.org>
Tue, 23 Mar 2004 14:26:43 +0000 (14:26 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Tue, 23 Mar 2004 14:26:43 +0000 (14:26 +0000)
2004-03-23  Kazu Hirata  <kazu@cs.umass.edu>

PR optimization/14669
* fold-const.c (fold): Only unwiden integer comparisons for equality
or inequality operators, or when the signedness is the same.

* g++.dg/opt/fold2.C: New test case.

From-SVN: r79859

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/fold2.C [new file with mode: 0644]

index deb8826cd2518ed1b6397217339a9929785b823a..5343f2cce94f2e5c5ca731929a52b1a41c7d5398 100644 (file)
@@ -1,3 +1,9 @@
+2004-03-23  Kazu Hirata  <kazu@cs.umass.edu>
+
+       PR optimization/14669
+       * fold-const.c (fold): Only unwiden integer comparisons for equality
+       and inequality operators, or when the signedness doesn't change.
+
 2004-03-23  Jakub Jelinek  <jakub@redhat.com>
 
        * config.gcc (sparc-*-linux*): Add sparc/t-linux to tmake_file.
index 84c605528baf8af20a9537d7605e0b12e50abebe..ab43be8d880a52797c3def2ae35ca062933a3afb 100644 (file)
@@ -7535,6 +7535,9 @@ fold (tree expr)
       else if (TREE_CODE (TREE_TYPE (arg0)) == INTEGER_TYPE
               && TREE_CODE (arg0) == NOP_EXPR
               && (tem = get_unwidened (arg0, NULL_TREE)) != arg0
+              && (code == EQ_EXPR || code == NE_EXPR
+                  || TREE_UNSIGNED (TREE_TYPE (arg0))
+                     == TREE_UNSIGNED (TREE_TYPE (tem)))
               && (t1 = get_unwidened (arg1, TREE_TYPE (tem))) != 0
               && (TREE_TYPE (t1) == TREE_TYPE (tem)
                   || (TREE_CODE (t1) == INTEGER_CST
index 359124ca2c854c405cb30a1886dfe6cebf6a9eaa..c111369c3e378ed4d8b7061eab894cbe2e2273ca 100644 (file)
@@ -1,3 +1,8 @@
+2004-03-23  Roger Sayle  <roger@eyesopen.com>
+
+       PR optimization/14669
+       * g++.dg/opt/fold2.C: New test case.
+
 2004-03-22  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/14069
diff --git a/gcc/testsuite/g++.dg/opt/fold2.C b/gcc/testsuite/g++.dg/opt/fold2.C
new file mode 100644 (file)
index 0000000..95063d7
--- /dev/null
@@ -0,0 +1,19 @@
+// PR optimization/14669
+// { dg-do run }
+// { dg-options "-O2" }
+
+extern "C" void abort (void);
+extern "C" void exit (int);
+
+enum ActionType { EE=-1, E0=0, E1, E2 };
+
+int main(void)
+{
+  ActionType t = E0;
+
+  if (E1 <= t && t <= E2)
+    abort ();
+
+  exit (0);
+}
+