aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2008-10-15 08:43:19 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2008-10-15 08:43:19 +0200
commitf6e6e9904cd32cc78873a33f0a3839812b0d0f57 (patch)
tree29214d79594ce43e6efb4c36998eb8577cdb8070 /gcc
parente3bc2fa7e63a75f1a31057aa9c77451f1263488a (diff)
downloadgcc-f6e6e9904cd32cc78873a33f0a3839812b0d0f57.zip
gcc-f6e6e9904cd32cc78873a33f0a3839812b0d0f57.tar.gz
gcc-f6e6e9904cd32cc78873a33f0a3839812b0d0f57.tar.bz2
re PR tree-optimization/36881 (Creating runtime relocations for code which does not need it)
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. * gcc.dg/tree-ssa/pr36881.c: New test. From-SVN: r141129
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr36881.c23
-rw-r--r--gcc/tree-switch-conversion.c27
4 files changed, 57 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 84625a1..2009584 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 12090cc..731785c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..742dd9d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr36881.c
@@ -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" } } */
diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c
index e975745..798cf16 100644
--- a/gcc/tree-switch-conversion.c
+++ b/gcc/tree-switch-conversion.c
@@ -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;
+ }
}
}
}