(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
aarch64/
negs.c
       1  /* { dg-do run } */
       2  /* { dg-options "-O2 --save-temps" } */
       3  
       4  extern void abort (void);
       5  int z;
       6  
       7  int
       8  negs_si_test1 (int a, int b, int c)
       9  {
      10    int d = -b;
      11  
      12    /* { dg-final { scan-assembler "negs\tw\[0-9\]+, w\[0-9\]+" } } */
      13    if (d < 0)
      14      return a + c;
      15  
      16    z = d;
      17      return b + c + d;
      18  }
      19  
      20  int
      21  negs_si_test3 (int a, int b, int c)
      22  {
      23    int d = -(b) << 3;
      24  
      25    /* { dg-final { scan-assembler "negs\tw\[0-9\]+, w\[0-9\]+, lsl 3" } } */
      26    if (d == 0)
      27      return a + c;
      28  
      29    z = d;
      30      return b + c + d;
      31  }
      32  
      33  typedef long long s64;
      34  s64 zz;
      35  
      36  s64
      37  negs_di_test1 (s64 a, s64 b, s64 c)
      38  {
      39    s64 d = -b;
      40  
      41    /* { dg-final { scan-assembler "negs\tx\[0-9\]+, x\[0-9\]+" } } */
      42    if (d < 0)
      43      return a + c;
      44  
      45    zz = d;
      46      return b + c + d;
      47  }
      48  
      49  s64
      50  negs_di_test3 (s64 a, s64 b, s64 c)
      51  {
      52    s64 d = -(b) << 3;
      53  
      54    /* { dg-final { scan-assembler "negs\tx\[0-9\]+, x\[0-9\]+, lsl 3" } } */
      55    if (d == 0)
      56      return a + c;
      57  
      58    zz = d;
      59      return b + c + d;
      60  }
      61  
      62  int main ()
      63  {
      64    int x;
      65    s64 y;
      66  
      67    x = negs_si_test1 (2, 12, 5);
      68    if (x != 7)
      69      abort ();
      70  
      71    x = negs_si_test1 (1, 2, 32);
      72    if (x != 33)
      73      abort ();
      74  
      75    x = negs_si_test3 (13, 14, 5);
      76    if (x != -93)
      77      abort ();
      78  
      79    x = negs_si_test3 (15, 21, 2);
      80    if (x != -145)
      81      abort ();
      82  
      83    y = negs_di_test1 (0x20202020ll,
      84  		     0x65161611ll,
      85  		     0x42434243ll);
      86    if (y != 0x62636263ll)
      87      abort ();
      88  
      89    y = negs_di_test1 (0x1010101010101ll,
      90  		     0x123456789abcdll,
      91  		     0x5555555555555ll);
      92    if (y != 0x6565656565656ll)
      93      abort ();
      94  
      95    y = negs_di_test3 (0x62523781ll,
      96  		     0x64234978ll,
      97  		     0x12345123ll);
      98    if (y != 0xfffffffd553d4edbll)
      99      abort ();
     100  
     101    y = negs_di_test3 (0x763526268ll,
     102  		     0x101010101ll,
     103  		     0x222222222ll);
     104    if (y != 0xfffffffb1b1b1b1bll)
     105      abort ();
     106  
     107    return 0;
     108  }