From c66475078ce85978489b9da5a19ebf21697f2b0d Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 6 Oct 2006 18:54:43 +0200 Subject: [PATCH] re PR target/28924 (x86 sync builtins fail for char and short memory operands) PR target/28924 * builtins.c (expand_builtin_sync_operation, expand_builtin_compare_and_swap, expand_builtin_lock_test_and_set): Use convert_to_mode to handle promoted arguments. * gcc.c-torture/compile/20061005-1.c: New test. From-SVN: r117508 --- gcc/ChangeLog | 7 ++++++ gcc/builtins.c | 8 +++++++ gcc/testsuite/ChangeLog | 5 ++++ .../gcc.c-torture/compile/20061005-1.c | 23 +++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 gcc/testsuite/gcc.c-torture/compile/20061005-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7625c494df0..17765ab88f7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2006-10-06 Jakub Jelinek + + PR target/28924 + * builtins.c (expand_builtin_sync_operation, + expand_builtin_compare_and_swap, expand_builtin_lock_test_and_set): + Use convert_to_mode to handle promoted arguments. + 2006-10-06 J"orn Rennecke * print-tree.c (print_node_brief, print_node): Print sign of Inf. diff --git a/gcc/builtins.c b/gcc/builtins.c index 2c81983f3d3..29974622ea1 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -5494,6 +5494,8 @@ expand_builtin_sync_operation (enum machine_mode mode, tree arglist, arglist = TREE_CHAIN (arglist); val = expand_expr (TREE_VALUE (arglist), NULL, mode, EXPAND_NORMAL); + /* If VAL is promoted to a wider mode, convert it back to MODE. */ + val = convert_to_mode (mode, val, 1); if (ignore) return expand_sync_operation (mem, val, code); @@ -5517,9 +5519,13 @@ expand_builtin_compare_and_swap (enum machine_mode mode, tree arglist, arglist = TREE_CHAIN (arglist); old_val = expand_expr (TREE_VALUE (arglist), NULL, mode, EXPAND_NORMAL); + /* If OLD_VAL is promoted to a wider mode, convert it back to MODE. */ + old_val = convert_to_mode (mode, old_val, 1); arglist = TREE_CHAIN (arglist); new_val = expand_expr (TREE_VALUE (arglist), NULL, mode, EXPAND_NORMAL); + /* If NEW_VAL is promoted to a wider mode, convert it back to MODE. */ + new_val = convert_to_mode (mode, new_val, 1); if (is_bool) return expand_bool_compare_and_swap (mem, old_val, new_val, target); @@ -5544,6 +5550,8 @@ expand_builtin_lock_test_and_set (enum machine_mode mode, tree arglist, arglist = TREE_CHAIN (arglist); val = expand_expr (TREE_VALUE (arglist), NULL, mode, EXPAND_NORMAL); + /* If VAL is promoted to a wider mode, convert it back to MODE. */ + val = convert_to_mode (mode, val, 1); return expand_sync_lock_test_and_set (mem, val, target); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 43988d7250e..9e16cecd218 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-10-06 Jakub Jelinek + + PR target/28924 + * gcc.c-torture/compile/20061005-1.c: New test. + 2006-10-06 Olivier Hainque * gcc.dg/typename-vla-1.c: New case. diff --git a/gcc/testsuite/gcc.c-torture/compile/20061005-1.c b/gcc/testsuite/gcc.c-torture/compile/20061005-1.c new file mode 100644 index 00000000000..a433509aec4 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/20061005-1.c @@ -0,0 +1,23 @@ +/* PR target/28924 */ + +char c; + +void +testc (void) +{ + (void) __sync_fetch_and_add (&c, -1); +} + +short s; + +void +tests (void) +{ + (void) __sync_fetch_and_add (&s, -1); +} + +void +testc2 (void) +{ + (void) __sync_val_compare_and_swap (&c, -1, -3); +} -- 2.30.2