From 23462d4d8fb5b5e40d6a62dd285301228f13a37b Mon Sep 17 00:00:00 2001 From: Uros Bizjak Date: Mon, 17 Nov 2008 12:19:06 +0100 Subject: re PR middle-end/37908 (atomic NAND op generate wrong code; __sync_nand_and_fetch, __sync_fetch_and_nand) PR middle-end/37908 * optabs.c (expand_sync_operation): Properly handle NAND case by calculating ~(t1 & val) instead of (~t1 & val). * builtins.c (expand_builtin_sync_operation): Warn for changed semantics in NAND builtins. * c.opt (Wsync-nand): New warning option. Describe -Wsync-nand. * doc/invoke.texi (Warning options): Add Wsync-nand. * doc/extend.texi (Atomic Builtins) [__sync_fetch_and_nand]: Correct __sync_fetch_and_nand builtin operation in the example. Add a note about changed semantics in GCC 4.4. [__sync_nand_and_fetch]: Correct __sync_nand_and_fetch builtin operation in the example. Add a note about changed semantics in GCC 4.4. testsuite/ChangeLog: PR middle-end/37908 * gcc.dg/pr37908.c: New test. * gcc.dg/ia64-sync-1.c: Correct __sync_fetch_and_nand and __sync_nand_and_fetch results. Add dg-message to look for the warning about changed semantics of NAND builtin. (init_si, init_di): Change init value for __sync_fetch_and_nand to -1. (test_si, test_di): Change expected result of __sync_nand_and_fetch to ~7. * gcc.dg/ia64-sync-2.c: Correct __sync_fetch_and_nand and __sync_nand_and_fetch results. Add dg-message to look for the warning about changed semantics of NAND builtin. (init_noret_si, init_noret_di): Change init value for __sync_fetch_and_nand to -1. (init_noret_si, init_noret_di): Change expected result of __sync_nand_and_fetch to ~7. * gcc.dg/sync-2.c: Correct __sync_fetch_and_nand and __sync_nand_and_fetch results. Add dg-message to look for the warning about changed semantics of NAND builtin. (init_qi, init_qi): Change init value for __sync_fetch_and_nand to -1. (init_hi, init_hi): Change expected result of __sync_nand_and_fetch to ~7. * gcc.dg/sync-3.c: Copy from sync-2.c instead of including the c source file. * gcc.c-torture/compile/sync-1.c: Add dg-message to look for the warning about changed semantics of NAND builtin. * gcc.c-torture/compile/sync-2.c: Ditto. * gcc.c-torture/compile/sync-3.c: Ditto. From-SVN: r141942 --- gcc/optabs.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'gcc/optabs.c') diff --git a/gcc/optabs.c b/gcc/optabs.c index 1273103..ed59f5e 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -7182,12 +7182,13 @@ expand_sync_operation (rtx mem, rtx val, enum rtx_code code) t1 = t0; if (code == NOT) { - t1 = expand_simple_unop (mode, NOT, t1, NULL_RTX, true); - code = AND; + t1 = expand_simple_binop (mode, AND, t1, val, NULL_RTX, + true, OPTAB_LIB_WIDEN); + t1 = expand_simple_unop (mode, code, t1, NULL_RTX, true); } - t1 = expand_simple_binop (mode, code, t1, val, NULL_RTX, - true, OPTAB_LIB_WIDEN); - + else + t1 = expand_simple_binop (mode, code, t1, val, NULL_RTX, + true, OPTAB_LIB_WIDEN); insn = get_insns (); end_sequence (); @@ -7315,9 +7316,17 @@ expand_sync_fetch_operation (rtx mem, rtx val, enum rtx_code code, } if (code == NOT) - target = expand_simple_unop (mode, NOT, target, NULL_RTX, true); - target = expand_simple_binop (mode, code, target, val, NULL_RTX, - true, OPTAB_LIB_WIDEN); + { + target = expand_simple_binop (mode, AND, target, val, + NULL_RTX, true, + OPTAB_LIB_WIDEN); + target = expand_simple_unop (mode, code, target, + NULL_RTX, true); + } + else + target = expand_simple_binop (mode, code, target, val, + NULL_RTX, true, + OPTAB_LIB_WIDEN); } return target; @@ -7340,11 +7349,13 @@ expand_sync_fetch_operation (rtx mem, rtx val, enum rtx_code code, t1 = t0; if (code == NOT) { - t1 = expand_simple_unop (mode, NOT, t1, NULL_RTX, true); - code = AND; + t1 = expand_simple_binop (mode, AND, t1, val, NULL_RTX, + true, OPTAB_LIB_WIDEN); + t1 = expand_simple_unop (mode, code, t1, NULL_RTX, true); } - t1 = expand_simple_binop (mode, code, t1, val, NULL_RTX, - true, OPTAB_LIB_WIDEN); + else + t1 = expand_simple_binop (mode, code, t1, val, NULL_RTX, + true, OPTAB_LIB_WIDEN); if (after) emit_move_insn (target, t1); -- cgit v1.1