re PR tree-optimization/19283 (Bad code generated in final_cleanup)
authorJakub Jelinek <jakub@redhat.com>
Fri, 7 Jan 2005 09:08:10 +0000 (10:08 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 7 Jan 2005 09:08:10 +0000 (10:08 +0100)
PR tree-optimization/19283
* fold-const.c (fold_widened_comparison): Return NULL if shorter_type
is not shorter than the original type.

* gcc.c-torture/execute/20050106-1.c: New test.

From-SVN: r93043

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20050106-1.c [new file with mode: 0644]

index 6d610b49226bed85461fdb1671082b40aa8ee3d8..7b8fca5672fb94cfd0f20a30f7b092251066b750 100644 (file)
@@ -1,5 +1,9 @@
 2005-01-07  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/19283
+       * fold-const.c (fold_widened_comparison): Return NULL if shorter_type
+       is not shorter than the original type.
+
        PR rtl-optimization/19012
        * config/i386/i386.md (addqi_1_slp): Set memory attribute.
 
index a3d1f1d5350b64e24469ed07047104ed30bb741e..21ee14cc5635796d6420ec24252c73bfbb707fe0 100644 (file)
@@ -5993,7 +5993,10 @@ fold_widened_comparison (enum tree_code code, tree type, tree arg0, tree arg1)
   if (arg0_unw == arg0)
     return NULL_TREE;
   shorter_type = TREE_TYPE (arg0_unw);
-  
+
+  if (TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (shorter_type))
+    return NULL_TREE;
+
   arg1_unw = get_unwidened (arg1, shorter_type);
   if (!arg1_unw)
     return NULL_TREE;
index fdfd6012c8a7e21ce9c569e80f5c6d5e48e4f96d..321a27a61eb0e745a39f4e74da21dac5439dcfdb 100644 (file)
@@ -1,5 +1,8 @@
 2005-01-07  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/19283
+       * gcc.c-torture/execute/20050106-1.c: New test.
+
        PR rtl-optimization/18861
        * gcc.dg/20050105-1.c: New test.
 
diff --git a/gcc/testsuite/gcc.c-torture/execute/20050106-1.c b/gcc/testsuite/gcc.c-torture/execute/20050106-1.c
new file mode 100644 (file)
index 0000000..e49732d
--- /dev/null
@@ -0,0 +1,19 @@
+/* PR tree-optimization/19283 */
+
+void abort (void);
+
+static inline unsigned short
+foo (unsigned int *p)
+{
+  return *p;
+};
+
+unsigned int u;
+
+int
+main ()
+{
+  if ((foo (&u) & 0x8000) != 0)
+    abort ();
+  return 0;
+}