This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, 4.2] atomic builtins: copy alignment info from tree to rtl
- From: Adrian Straetling <straetling at de dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: uweigand at de dot ibm dot com, krebbel1 at de dot ibm dot com
- Date: Tue, 6 Dec 2005 21:56:59 +0100
- Subject: [patch, 4.2] atomic builtins: copy alignment info from tree to rtl
Hi,
implementing the remaining atomic builtins for s390(x) I found it
limiting that the back end did not receive alignment information.
To emulate compare_and_swap[hq]i with compare_and_swapsi the knowledge
of the memory alignment is essential as compare_and_swapsi needs to be
32bit-aligned.
If the compiler knows the alignment at compile time
__attribute((aligned (4)))__
it could produce more efficient code not having to compute the
alignment at runtime.
The alignment in these cases gets lost in several expand_builtin_* functions
that create a memory_rtx from scratch (to avoid aliasing info) and do
not copy the alignment info to it.
Here is a patch that does so.
Bootstrapped and regtested on s390(x) showing no regressions (with and
without an additional s390 patch to exploit the alignement info).
Testing on i686 only showed regressions which frequently popped up
in unrelated test runs as well (pass39-frag.c, FileHandleGcTest).
Ok for 4.2?
2005-12-06 Adrian Straetling <straetling@de.ibm.com>
* gcc/builtins.c: (expand_builtin_sync_operation,
expand_builtin_compare_and_swap,expand_builtin_lock_test_and_set,
expand_builtin_lock_release): Copy alignment to memory rtx.
Index: gcc/builtins.c
===================================================================
--- gcc/builtins.c.orig 2005-11-22 13:45:07.000000000 +0100
+++ gcc/builtins.c 2005-11-22 17:00:13.480637006 +0100
@@ -5418,9 +5418,10 @@ expand_builtin_sync_operation (enum mach
rtx target, bool ignore)
{
rtx addr, val, mem;
+ tree loc = TREE_VALUE (arglist);
/* Expand the operands. */
- addr = expand_expr (TREE_VALUE (arglist), NULL, Pmode, EXPAND_SUM);
+ addr = expand_expr (loc, NULL, Pmode, EXPAND_SUM);
arglist = TREE_CHAIN (arglist);
val = expand_expr (TREE_VALUE (arglist), NULL, mode, EXPAND_NORMAL);
@@ -5429,6 +5430,7 @@ expand_builtin_sync_operation (enum mach
memory, so that we kill all other live memories. Otherwise we don't
satisfy the full barrier semantics of the intrinsic. */
mem = validize_mem (gen_rtx_MEM (mode, addr));
+ set_mem_align (mem, get_pointer_alignment (loc, BIGGEST_ALIGNMENT));
MEM_VOLATILE_P (mem) = 1;
if (ignore)
@@ -5447,9 +5449,10 @@ expand_builtin_compare_and_swap (enum ma
bool is_bool, rtx target)
{
rtx addr, old_val, new_val, mem;
+ tree loc = TREE_VALUE (arglist);
/* Expand the operands. */
- addr = expand_expr (TREE_VALUE (arglist), NULL, Pmode, EXPAND_SUM);
+ addr = expand_expr (loc, NULL, Pmode, EXPAND_SUM);
arglist = TREE_CHAIN (arglist);
old_val = expand_expr (TREE_VALUE (arglist), NULL, mode, EXPAND_NORMAL);
@@ -5461,6 +5464,7 @@ expand_builtin_compare_and_swap (enum ma
memory, so that we kill all other live memories. Otherwise we don't
satisfy the full barrier semantics of the intrinsic. */
mem = validize_mem (gen_rtx_MEM (mode, addr));
+ set_mem_align (mem, get_pointer_alignment (loc, BIGGEST_ALIGNMENT));
MEM_VOLATILE_P (mem) = 1;
if (is_bool)
@@ -5480,9 +5484,10 @@ expand_builtin_lock_test_and_set (enum m
rtx target)
{
rtx addr, val, mem;
+ tree loc = TREE_VALUE (arglist);
/* Expand the operands. */
- addr = expand_expr (TREE_VALUE (arglist), NULL, Pmode, EXPAND_NORMAL);
+ addr = expand_expr (loc, NULL, Pmode, EXPAND_NORMAL);
arglist = TREE_CHAIN (arglist);
val = expand_expr (TREE_VALUE (arglist), NULL, mode, EXPAND_NORMAL);
@@ -5491,6 +5496,7 @@ expand_builtin_lock_test_and_set (enum m
memory, so that we kill all other live memories. Otherwise we don't
satisfy the barrier semantics of the intrinsic. */
mem = validize_mem (gen_rtx_MEM (mode, addr));
+ set_mem_align (mem, get_pointer_alignment (loc, BIGGEST_ALIGNMENT));
MEM_VOLATILE_P (mem) = 1;
return expand_sync_lock_test_and_set (mem, val, target);
@@ -5528,14 +5534,16 @@ expand_builtin_lock_release (enum machin
enum insn_code icode;
rtx addr, mem, insn;
rtx val = const0_rtx;
+ tree loc = TREE_VALUE (arglist);
/* Expand the operands. */
- addr = expand_expr (TREE_VALUE (arglist), NULL, Pmode, EXPAND_NORMAL);
+ addr = expand_expr (loc, NULL, Pmode, EXPAND_NORMAL);
/* Note that we explicitly do not want any alias information for this
memory, so that we kill all other live memories. Otherwise we don't
satisfy the barrier semantics of the intrinsic. */
mem = validize_mem (gen_rtx_MEM (mode, addr));
+ set_mem_align (mem, get_pointer_alignment (loc, BIGGEST_ALIGNMENT));
MEM_VOLATILE_P (mem) = 1;
/* If there is an explicit operation in the md file, use it. */