summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2014-02-12 13:36:08 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2014-02-12 13:36:08 +0000
commit712bf3a3fbd037195c546f7aeed66cc95920790a (patch)
tree2170229d022391e2e5097c4abd86cc05f7ff07dc
parent7eba00287fcbda411d8eeb9cef34151bffb859f8 (diff)
downloadgcc-712bf3a3fbd037195c546f7aeed66cc95920790a.tar.gz
2014-02-12 Richard Biener <rguenther@suse.de>
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
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/gimple-low.c38
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr60092.c21
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/alias-31.c2
5 files changed, 61 insertions, 14 deletions
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 <rguenther@suse.de>
+
+ 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 <senthil_kumar.selvaraj@atmel.com>
* 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 <rguenther@suse.de>
+
+ 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 <ebotcazou@adacore.com>
* 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);