(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
i386/
pr102566-1a.c
       1  /* { dg-do compile } */
       2  /* { dg-options "-O2" } */
       3  
       4  void bar (void);
       5  
       6  __attribute__((noinline, noclone)) int
       7  f1 (int *a, int bit)
       8  {
       9    int mask = 1 << bit;
      10    return (__sync_fetch_and_or (a, mask) & mask) != 0;
      11  }
      12  
      13  __attribute__((noinline, noclone)) int
      14  f2 (int *a, int bit)
      15  {
      16    int mask = 1 << bit;
      17    int t1 = __atomic_fetch_or (a, mask, __ATOMIC_RELAXED);
      18    int t2 = t1 & mask;
      19    return t2 != 0;
      20  }
      21  
      22  __attribute__((noinline, noclone)) long int
      23  f3 (long int *a, int bit)
      24  {
      25    long int mask = 1l << bit;
      26    return (__atomic_fetch_or (a, mask, __ATOMIC_SEQ_CST) & mask) == 0;
      27  }
      28  
      29  __attribute__((noinline, noclone)) int
      30  f4 (int *a)
      31  {
      32    int mask = 1 << 7;
      33    return (__sync_fetch_and_or (a, mask) & mask) != 0;
      34  }
      35  
      36  __attribute__((noinline, noclone)) int
      37  f5 (int *a)
      38  {
      39    int mask = 1 << 13;
      40    return (__atomic_fetch_or (a, mask, __ATOMIC_RELAXED) & mask) != 0;
      41  }
      42  
      43  __attribute__((noinline, noclone)) int
      44  f6 (int *a)
      45  {
      46    int mask = 1 << 0;
      47    return (__atomic_fetch_or (a, mask, __ATOMIC_SEQ_CST) & mask) != 0;
      48  }
      49  
      50  __attribute__((noinline, noclone)) void
      51  f7 (int *a, int bit)
      52  {
      53    int mask = 1 << bit;
      54    if ((__sync_fetch_and_xor (a, mask) & mask) != 0)
      55      bar ();
      56  }
      57  
      58  __attribute__((noinline, noclone)) void
      59  f8 (int *a, int bit)
      60  {
      61    int mask = 1 << bit;
      62    if ((__atomic_fetch_xor (a, mask, __ATOMIC_RELAXED) & mask) == 0)
      63      bar ();
      64  }
      65  
      66  __attribute__((noinline, noclone)) int
      67  f9 (int *a, int bit)
      68  {
      69    int mask = 1 << bit;
      70    return (__atomic_fetch_xor (a, mask, __ATOMIC_SEQ_CST) & mask) != 0;
      71  }
      72  
      73  __attribute__((noinline, noclone)) int
      74  f10 (int *a)
      75  {
      76    int mask = 1 << 7;
      77    return (__sync_fetch_and_xor (a, mask) & mask) != 0;
      78  }
      79  
      80  __attribute__((noinline, noclone)) int
      81  f11 (int *a)
      82  {
      83    int mask = 1 << 13;
      84    return (__atomic_fetch_xor (a, mask, __ATOMIC_RELAXED) & mask) != 0;
      85  }
      86  
      87  __attribute__((noinline, noclone)) int
      88  f12 (int *a)
      89  {
      90    int mask = 1 << 0;
      91    return (__atomic_fetch_xor (a, mask, __ATOMIC_SEQ_CST) & mask) != 0;
      92  }
      93  
      94  __attribute__((noinline, noclone)) int
      95  f13 (int *a, int bit)
      96  {
      97    int mask = 1 << bit;
      98    return (__sync_fetch_and_and (a, ~mask) & mask) != 0;
      99  }
     100  
     101  __attribute__((noinline, noclone)) int
     102  f14 (int *a, int bit)
     103  {
     104    int mask = 1 << bit;
     105    return (__atomic_fetch_and (a, ~mask, __ATOMIC_RELAXED) & mask) != 0;
     106  }
     107  
     108  __attribute__((noinline, noclone)) int
     109  f15 (int *a, int bit)
     110  {
     111    int mask = 1 << bit;
     112    return (__atomic_fetch_and (a, ~mask, __ATOMIC_SEQ_CST) & mask) != 0;
     113  }
     114  
     115  __attribute__((noinline, noclone)) int
     116  f16 (int *a)
     117  {
     118    int mask = 1 << 7;
     119    return (__sync_fetch_and_and (a, ~mask) & mask) != 0;
     120  }
     121  
     122  __attribute__((noinline, noclone)) int
     123  f17 (int *a)
     124  {
     125    int mask = 1 << 13;
     126    return (__atomic_fetch_and (a, ~mask, __ATOMIC_RELAXED) & mask) != 0;
     127  }
     128  
     129  __attribute__((noinline, noclone)) int
     130  f18 (int *a)
     131  {
     132    int mask = 1 << 0;
     133    return (__atomic_fetch_and (a, ~mask, __ATOMIC_SEQ_CST) & mask) != 0;
     134  }
     135  
     136  __attribute__((noinline, noclone)) long int
     137  f19 (long int *a, int bit)
     138  {
     139    long int mask = 1l << bit;
     140    return (__atomic_xor_fetch (a, mask, __ATOMIC_SEQ_CST) & mask) != 0;
     141  }
     142  
     143  __attribute__((noinline, noclone)) long int
     144  f20 (long int *a)
     145  {
     146    long int mask = 1l << 7;
     147    return (__atomic_xor_fetch (a, mask, __ATOMIC_SEQ_CST) & mask) == 0;
     148  }
     149  
     150  __attribute__((noinline, noclone)) int
     151  f21 (int *a, int bit)
     152  {
     153    int mask = 1 << bit;
     154    return (__sync_fetch_and_or (a, mask) & mask);
     155  }
     156  
     157  __attribute__((noinline, noclone)) long int
     158  f22 (long int *a)
     159  {
     160    long int mask = 1l << 7;
     161    return (__atomic_xor_fetch (a, mask, __ATOMIC_SEQ_CST) & mask);
     162  }
     163  
     164  __attribute__((noinline, noclone)) long int
     165  f23 (long int *a)
     166  {
     167    long int mask = 1l << 7;
     168    return (__atomic_fetch_xor (a, mask, __ATOMIC_SEQ_CST) & mask);
     169  }
     170  
     171  __attribute__((noinline, noclone)) short int
     172  f24 (short int *a)
     173  {
     174    short int mask = 1 << 7;
     175    return (__sync_fetch_and_or (a, mask) & mask) != 0;
     176  }
     177  
     178  __attribute__((noinline, noclone)) short int
     179  f25 (short int *a)
     180  {
     181    short int mask = 1 << 7;
     182    return (__atomic_fetch_or (a, mask, __ATOMIC_SEQ_CST) & mask) != 0;
     183  }
     184  
     185  /* { dg-final { scan-assembler-times "lock;?\[ \t\]*bts" 9 } } */
     186  /* { dg-final { scan-assembler-times "lock;?\[ \t\]*btc" 10 } } */
     187  /* { dg-final { scan-assembler-times "lock;?\[ \t\]*btr" 6 } } */
     188  /* { dg-final { scan-assembler-not "cmpxchg" } } */