On Fri, Nov 12, 2021 at 07:29:03AM -0800, H.J. Lu wrote: > Check optab before transforming equivalent, but slighly different cases > to their canonical forms in optimize_atomic_bit_test_and and require > TARGET_HIMODE_MATH in HImode atomic bit expanders. > > gcc/ > > PR target/103205 > * tree-ssa-ccp.c (optimize_atomic_bit_test_and): Check optab > before transforming equivalent, but slighly different cases to > their canonical forms. > * config/i386/sync.md (atomic_bit_test_and_set<mode>): Require > TARGET_HIMODE_MATH for HImode. > (atomic_bit_test_and_complement<mode>): Likewise. > (atomic_bit_test_and_reset<mode>): Likewise. > > gcc/testsuite/ > > PR target/103205 > * gcc.target/i386/pr103205-1a.c: New test. > * gcc.target/i386/pr103205-1b.c: Likewise. > * gcc.target/i386/pr103205-2a.c: Likewise. > * gcc.target/i386/pr103205-2b.c: Likewise. > * gcc.target/i386/pr103205-3.c: Likewise. > * gcc.target/i386/pr103205-4.c: Likewise.
Why? When one uses 16-bit atomics, no matter what he does there will be some HImode math (at least the atomic instruction). And the rest can be dealt with. I have following patch queued for testing for this... 2021-11-12 Jakub Jelinek <ja...@redhat.com> PR target/103205 * config/i386/sync.md (atomic_bit_test_and_set<mode>, atomic_bit_test_and_complement<mode>, atomic_bit_test_and_reset<mode>): Use OPTAB_WIDEN instead of OPTAB_DIRECT. * gcc.target/i386/pr103205.c: New test. --- gcc/config/i386/sync.md.jj 2021-10-04 19:53:01.025005548 +0200 +++ gcc/config/i386/sync.md 2021-11-12 15:27:47.387273428 +0100 @@ -726,7 +726,7 @@ (define_expand "atomic_bit_test_and_set< rtx result = convert_modes (<MODE>mode, QImode, tem, 1); if (operands[4] == const0_rtx) result = expand_simple_binop (<MODE>mode, ASHIFT, result, - operands[2], operands[0], 0, OPTAB_DIRECT); + operands[2], operands[0], 0, OPTAB_WIDEN); if (result != operands[0]) emit_move_insn (operands[0], result); DONE; @@ -763,7 +763,7 @@ (define_expand "atomic_bit_test_and_comp rtx result = convert_modes (<MODE>mode, QImode, tem, 1); if (operands[4] == const0_rtx) result = expand_simple_binop (<MODE>mode, ASHIFT, result, - operands[2], operands[0], 0, OPTAB_DIRECT); + operands[2], operands[0], 0, OPTAB_WIDEN); if (result != operands[0]) emit_move_insn (operands[0], result); DONE; @@ -801,7 +801,7 @@ (define_expand "atomic_bit_test_and_rese rtx result = convert_modes (<MODE>mode, QImode, tem, 1); if (operands[4] == const0_rtx) result = expand_simple_binop (<MODE>mode, ASHIFT, result, - operands[2], operands[0], 0, OPTAB_DIRECT); + operands[2], operands[0], 0, OPTAB_WIDEN); if (result != operands[0]) emit_move_insn (operands[0], result); DONE; --- gcc/testsuite/gcc.target/i386/pr103205.c.jj 2021-11-12 15:47:21.218380790 +0100 +++ gcc/testsuite/gcc.target/i386/pr103205.c 2021-11-12 15:46:39.546980182 +0100 @@ -0,0 +1,11 @@ +/* PR target/103205 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mtune-ctrl=^himode_math" } */ + +unsigned short a; + +unsigned short +foo (void) +{ + return __sync_fetch_and_and (&a, ~1) & 1; +} Jakub