From 712bf3a3fbd037195c546f7aeed66cc95920790a Mon Sep 17 00:00:00 2001 From: rguenth Date: Wed, 12 Feb 2014 13:36:08 +0000 Subject: [PATCH] 2014-02-12 Richard Biener PR middle-end/60092 * gimple-low.c (lower_builtin_posix_memalign): Lower conditional of posix_memalign being successful. (lower_stmt): Restrict lowering of posix_memalign to when -ftree-bit-ccp is enabled. * gcc.dg/torture/pr60092.c: New testcase. * gcc.dg/tree-ssa/alias-31.c: Disable SRA. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@207720 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 8 +++++++ gcc/gimple-low.c | 38 +++++++++++++++++++++----------- gcc/testsuite/ChangeLog | 6 +++++ gcc/testsuite/gcc.dg/torture/pr60092.c | 21 ++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/alias-31.c | 2 +- 5 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr60092.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4f22604e1c1..1f4ddb8e31a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2014-02-12 Richard Biener + + PR middle-end/60092 + * gimple-low.c (lower_builtin_posix_memalign): Lower conditional + of posix_memalign being successful. + (lower_stmt): Restrict lowering of posix_memalign to when + -ftree-bit-ccp is enabled. + 2014-02-12 Senthil Kumar Selvaraj * config/avr/avr-c.c (avr_resolve_overloaded_builtin): Pass vNULL for diff --git a/gcc/gimple-low.c b/gcc/gimple-low.c index 01e9e9cd28d..80fd786fdde 100644 --- a/gcc/gimple-low.c +++ b/gcc/gimple-low.c @@ -336,7 +336,8 @@ lower_stmt (gimple_stmt_iterator *gsi, struct lower_data *data) data->cannot_fallthru = false; return; } - else if (DECL_FUNCTION_CODE (decl) == BUILT_IN_POSIX_MEMALIGN) + else if (DECL_FUNCTION_CODE (decl) == BUILT_IN_POSIX_MEMALIGN + && flag_tree_bit_ccp) { lower_builtin_posix_memalign (gsi); return; @@ -781,37 +782,47 @@ lower_builtin_setjmp (gimple_stmt_iterator *gsi) } /* Lower calls to posix_memalign to - posix_memalign (ptr, align, size); - tem = *ptr; - tem = __builtin_assume_aligned (tem, align); - *ptr = tem; + res = posix_memalign (ptr, align, size); + if (res == 0) + *ptr = __builtin_assume_aligned (*ptr, align); or to void *tem; - posix_memalign (&tem, align, size); - ttem = tem; - ttem = __builtin_assume_aligned (ttem, align); - ptr = tem; + res = posix_memalign (&tem, align, size); + if (res == 0) + ptr = __builtin_assume_aligned (tem, align); in case the first argument was &ptr. That way we can get at the alignment of the heap pointer in CCP. */ static void lower_builtin_posix_memalign (gimple_stmt_iterator *gsi) { - gimple stmt = gsi_stmt (*gsi); - tree pptr = gimple_call_arg (stmt, 0); - tree align = gimple_call_arg (stmt, 1); + gimple stmt, call = gsi_stmt (*gsi); + tree pptr = gimple_call_arg (call, 0); + tree align = gimple_call_arg (call, 1); + tree res = gimple_call_lhs (call); tree ptr = create_tmp_reg (ptr_type_node, NULL); if (TREE_CODE (pptr) == ADDR_EXPR) { tree tem = create_tmp_var (ptr_type_node, NULL); TREE_ADDRESSABLE (tem) = 1; - gimple_call_set_arg (stmt, 0, build_fold_addr_expr (tem)); + gimple_call_set_arg (call, 0, build_fold_addr_expr (tem)); stmt = gimple_build_assign (ptr, tem); } else stmt = gimple_build_assign (ptr, fold_build2 (MEM_REF, ptr_type_node, pptr, build_int_cst (ptr_type_node, 0))); + if (res == NULL_TREE) + { + res = create_tmp_reg (integer_type_node, NULL); + gimple_call_set_lhs (call, res); + } + tree align_label = create_artificial_label (UNKNOWN_LOCATION); + tree noalign_label = create_artificial_label (UNKNOWN_LOCATION); + gimple cond = gimple_build_cond (EQ_EXPR, res, integer_zero_node, + align_label, noalign_label); + gsi_insert_after (gsi, cond, GSI_NEW_STMT); + gsi_insert_after (gsi, gimple_build_label (align_label), GSI_NEW_STMT); gsi_insert_after (gsi, stmt, GSI_NEW_STMT); stmt = gimple_build_call (builtin_decl_implicit (BUILT_IN_ASSUME_ALIGNED), 2, ptr, align); @@ -821,6 +832,7 @@ lower_builtin_posix_memalign (gimple_stmt_iterator *gsi) build_int_cst (ptr_type_node, 0)), ptr); gsi_insert_after (gsi, stmt, GSI_NEW_STMT); + gsi_insert_after (gsi, gimple_build_label (noalign_label), GSI_NEW_STMT); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5555d3edb7b..c87966d3fe7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2014-02-12 Richard Biener + + PR middle-end/60092 + * gcc.dg/torture/pr60092.c: New testcase. + * gcc.dg/tree-ssa/alias-31.c: Disable SRA. + 2014-02-12 Eric Botcazou * gcc.c-torture/execute/20140212-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/torture/pr60092.c b/gcc/testsuite/gcc.dg/torture/pr60092.c new file mode 100644 index 00000000000..f1ff80d8ac7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr60092.c @@ -0,0 +1,21 @@ +/* { dg-do run } */ +/* { dg-require-weak "" } */ + +typedef __SIZE_TYPE__ size_t; +extern int posix_memalign(void **memptr, size_t alignment, size_t size) __attribute__((weak)); +extern void abort(void); +int +main (void) +{ + void *p; + int ret; + + if (!posix_memalign) + return 0; + + p = (void *)&ret; + ret = posix_memalign (&p, sizeof (void *), -1); + if (p != (void *)&ret) + abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/alias-31.c b/gcc/testsuite/gcc.dg/tree-ssa/alias-31.c index f1aefbdc2ba..622df80a9c4 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/alias-31.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/alias-31.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-cddce1" } */ +/* { dg-options "-O2 -fno-tree-sra -fdump-tree-cddce1" } */ extern int posix_memalign(void **memptr, __SIZE_TYPE__ alignment, __SIZE_TYPE__ size); -- 2.11.4.GIT