This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR60092 - lower posix_memalign to make align-info accessible
- From: Andreas Krebbel <krebbel at linux dot vnet dot ibm dot com>
- To: Richard Biener <rguenther at suse dot de>, gcc-patches at gcc dot gnu dot org
- Cc: Jakub Jelinek <jakub at redhat dot com>
- Date: Wed, 12 Feb 2014 09:57:29 +0100
- Subject: Re: [PATCH] PR60092 - lower posix_memalign to make align-info accessible
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot LSU dot 2 dot 11 dot 1402061519260 dot 29326 at zhemvz dot fhfr dot qr> <alpine dot LSU dot 2 dot 11 dot 1402061538320 dot 29326 at zhemvz dot fhfr dot qr> <alpine dot LSU dot 2 dot 11 dot 1402071032550 dot 29326 at zhemvz dot fhfr dot qr>
On 07/02/14 10:33, Richard Biener wrote:
> + 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);
> + 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));
> + 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)));
> + gsi_insert_after (gsi, stmt, GSI_NEW_STMT);
> + stmt = gimple_build_call (builtin_decl_implicit (BUILT_IN_ASSUME_ALIGNED),
> + 2, ptr, align);
> + gimple_call_set_lhs (stmt, ptr);
> + gsi_insert_after (gsi, stmt, GSI_NEW_STMT);
> + stmt = gimple_build_assign (fold_build2 (MEM_REF, ptr_type_node, pptr,
> + build_int_cst (ptr_type_node, 0)),
> + ptr);
> + gsi_insert_after (gsi, stmt, GSI_NEW_STMT);
> + }
Hi,
creating a new var for the output parameter throws away the value already in there. But this value
must not change when posix_memalign e.g. returns with ENOMEM. It breaks the glibc posix_memalign
testcase on s390 (somewhat reduced here):
typedef unsigned long size_t;
extern int posix_memalign(void **memptr, size_t alignment, size_t size);
extern void abort(void);
int
main (void)
{
void *p;
int ret;
p = 0;
ret = posix_memalign (&p, sizeof (void *), -1);
if (p != 0)
abort ();
return 0;
}
.c.170r.expand
main ()
{
void * D.1395;
void * D.1394;
int ret;
void * p;
int D.1393;
void * p.0;
void * _2;
void * _3;
void * p.0_4;
int _5;
;; basic block 2, loop depth 0
;; pred: ENTRY
p = 0B;
ret_1 = posix_memalign (&D.1395, 4, 4294967295);
_2 = D.1395;
_3 = __builtin_assume_aligned (_2, 4);
MEM[(void *)&p] = _3;
p.0_4 = p;
if (p.0_4 != 0B)
goto <bb 3>;
else
goto <bb 4>;
;; succ: 3
;; 4
;; basic block 3, loop depth 0
;; pred: 2
abort ();
;; succ:
;; basic block 4, loop depth 0
;; pred: 2
_5 = 0;
p ={v} {CLOBBER};
;; succ: 5
;; basic block 5, loop depth 0
;; pred: 4
<L3>:
return _5;
;; succ: EXIT
}