* 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
+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,
+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
--- /dev/null
+/* 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" } } */
{
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;
+ }
}
}
}