Enhance optimize_atomic_bit_test_and to handle truncation.
authorliuhongt <hongtao.liu@intel.com>
Tue, 16 Nov 2021 05:36:36 +0000 (13:36 +0800)
committerliuhongt <hongtao.liu@intel.com>
Wed, 24 Nov 2021 01:00:58 +0000 (09:00 +0800)
commit7df89377a7ae3906255e38a79be8e5d962c3a0df
tree64cd9f5620610f80dd1df5275f0e2bed5242ba7d
parente1d4359264585acc8210ba60abb6dfb15bf1fa57
Enhance optimize_atomic_bit_test_and to handle truncation.

r12-5102-gfb161782545224f5 improves integer bit test on
__atomic_fetch_[or|and]_* returns only for nop_convert, .i.e.

transfrom

  mask_5 = 1 << bit_4(D);
  mask.0_1 = (unsigned int) mask_5;
  _2 = __atomic_fetch_or_4 (a_7(D), mask.0_1, 0);
  t1_9 = (int) _2;
  t2_10 = mask_5 & t1_9;

to

  mask_5 = 1 << n_4(D);
  mask.1_1 = (unsigned int) mask_5;
  _11 = .ATOMIC_BIT_TEST_AND_SET (&pscc_a_1_4, n_4(D), 0);
  _8 = (int) _11;

And this patch extend the original patch to handle truncation.
.i.e.

transform

  long int mask;
  mask_8 = 1 << n_7(D);
  mask.0_1 = (long unsigned int) mask_8;
  _2 = __sync_fetch_and_or_8 (&pscc_a_2_3, mask.0_1);
  _3 = (unsigned int) _2;
  _4 = (unsigned int) mask_8;
  _5 = _3 & _4;
  _6 = (int) _5;

to

  long int mask;
  mask_8 = 1 << n_7(D);
  mask.0_1 = (long unsigned int) mask_8;
  _14 = .ATOMIC_BIT_TEST_AND_SET (&pscc_a_2_3, n_7(D), 0);
  _5 = (unsigned int) _14;
  _6 = (int) _5;

2021-11-17  Hongtao Liu  <hongtao.liu@intel.com>
    H.J. Lu  <hongjiu.lu@intel.com>

gcc/ChangeLog:

PR tree-optimization/103194
* match.pd (gimple_nop_atomic_bit_test_and_p): Extended to
match truncation.
* tree-ssa-ccp.c (gimple_nop_convert): Declare.
(optimize_atomic_bit_test_and): Enhance
optimize_atomic_bit_test_and to handle truncation.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr103194-2.c: New test.
* gcc.target/i386/pr103194-3.c: New test.
* gcc.target/i386/pr103194-4.c: New test.
* gcc.target/i386/pr103194-5.c: New test.
* gcc.target/i386/pr103194.c: New test.
gcc/match.pd
gcc/testsuite/gcc.target/i386/pr103194-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr103194-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr103194-4.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr103194-5.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr103194.c [new file with mode: 0644]
gcc/tree-ssa-ccp.c