]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR tree-optimization/36881
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 15 Oct 2008 06:43:19 +0000 (06:43 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 15 Oct 2008 06:43:19 +0000 (06:43 +0000)
* tree-switch-conversion.c (check_final_bb): For flag_pic, check
that each value doesn't need runtime relocations, for !flag_pic
check that each value is just a valid initializer constant.

* gcc.dg/tree-ssa/pr36881.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@141129 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr36881.c [new file with mode: 0644]
gcc/tree-switch-conversion.c

index 84625a1f2b1a37036631b7d9ecc6c98f5dab1e79..200958413d4cf00f6ad7eab7ae496a5799bcf236 100644 (file)
@@ -1,3 +1,10 @@
+2008-10-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/36881
+       * tree-switch-conversion.c (check_final_bb): For flag_pic, check
+       that each value doesn't need runtime relocations, for !flag_pic
+       check that each value is just a valid initializer constant.
+
 2008-10-14  Richard Sandiford  <rdsandiford@googlemail.com>
 
        * config/mips/mips.h (reg_class): Remove HI_AND_GR_REGS,
index 12090cc227de45f47f395d55f14480096bf78bd7..731785cb5a9af9ad8cf3b362d38dd81df396f20c 100644 (file)
@@ -1,3 +1,8 @@
+2008-10-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/36881
+       * gcc.dg/tree-ssa/pr36881.c: New test.
+
 2008-10-14  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/37819
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr36881.c b/gcc/testsuite/gcc.dg/tree-ssa/pr36881.c
new file mode 100644 (file)
index 0000000..742dd9d
--- /dev/null
@@ -0,0 +1,23 @@
+/* PR tree-optimization/36881 */
+/* { dg-do compile { target fpic } } */
+/* { dg-options "-O2 -fpic -fdump-tree-switchconv-all" } */
+
+const char *foo (int i)
+{
+  const char *p;
+  switch (i)
+    {
+    case 0:
+    case 6: p = ""; break;
+    case 1:
+    case 7: p = "abc"; break;
+    case 2:
+    case 8: p = "def"; break;
+    default: p = "ghi"; break;
+    }
+  return p;
+}
+
+/* { dg-final { scan-assembler-not "CSWTCH" } } */
+/* { dg-final { scan-tree-dump "need runtime relocations" "switchconv" } } */
+/* { dg-final { cleanup-tree-dump "switchconv" } } */
index e9757454f21923c1197d5098b2e9d841949c396c..798cf161569460d8713feb2f6ac9d6be4e623b34 100644 (file)
@@ -296,12 +296,29 @@ check_final_bb (void)
        {
          basic_block bb = gimple_phi_arg_edge (phi, i)->src;
 
-         if ((bb == info.switch_bb
-              || (single_pred_p (bb) && single_pred (bb) == info.switch_bb))
-             && !is_gimple_ip_invariant (gimple_phi_arg_def (phi, i)))
+         if (bb == info.switch_bb
+             || (single_pred_p (bb) && single_pred (bb) == info.switch_bb))
            {
-             info.reason = "   Non-invariant value from a case\n";
-             return false; /* Non-invariant argument.  */
+             tree reloc, val;
+
+             val = gimple_phi_arg_def (phi, i);
+             if (!is_gimple_ip_invariant (val))
+               {
+                 info.reason = "   Non-invariant value from a case\n";
+                 return false; /* Non-invariant argument.  */
+               }
+             reloc = initializer_constant_valid_p (val, TREE_TYPE (val));
+             if ((flag_pic && reloc != null_pointer_node)
+                 || (!flag_pic && reloc == NULL_TREE))
+               {
+                 if (reloc)
+                   info.reason
+                     = "   Value from a case would need runtime relocations\n";
+                 else
+                   info.reason
+                     = "   Value from a case is not a valid initializer\n";
+                 return false;
+               }
            }
        }
     }