1  /* { dg-do run } */
       2  /* { dg-options "-O2 --save-temps -fno-inline" } */
       3  
       4  extern void abort (void);
       5  
       6  int
       7  subs_si_test1 (int a, int b, int c)
       8  {
       9    int d = a - b;
      10  
      11    /* { dg-final { scan-assembler-not "subs\tw\[0-9\]+, w\[0-9\]+, w\[0-9\]+" } } */
      12    /* { dg-final { scan-assembler "sub\tw\[0-9\]+, w\[0-9\]+, w\[0-9\]+" } } */
      13    if (d <= 0)
      14      return a + c;
      15    else
      16      return b + d + c;
      17  }
      18  
      19  int
      20  subs_si_test2 (int a, int b, int c)
      21  {
      22    int d = a - 0xfff;
      23  
      24    /* { dg-final { scan-assembler-not "subs\tw\[0-9\]+, w\[0-9\]+, #4095" } } */
      25    /* { dg-final { scan-assembler "sub\tw\[0-9\]+, w\[0-9\]+, #4095" } } */
      26    if (d <= 0)
      27      return a + c;
      28    else
      29      return b + d + c;
      30  }
      31  
      32  int
      33  subs_si_test3 (int a, int b, int c)
      34  {
      35    int d = a - (b << 3);
      36  
      37    /* { dg-final { scan-assembler-not "subs\tw\[0-9\]+, w\[0-9\]+, w\[0-9\]+, lsl 3" } } */
      38    /* { dg-final { scan-assembler "sub\tw\[0-9\]+, w\[0-9\]+, w\[0-9\]+, lsl 3" } } */
      39    if (d <= 0)
      40      return a + c;
      41    else
      42      return b + d + c;
      43  }
      44  
      45  typedef long long s64;
      46  
      47  s64
      48  subs_di_test1 (s64 a, s64 b, s64 c)
      49  {
      50    s64 d = a - b;
      51  
      52    /* { dg-final { scan-assembler-not "subs\tx\[0-9\]+, x\[0-9\]+, x\[0-9\]+" } } */
      53    /* { dg-final { scan-assembler "sub\tx\[0-9\]+, x\[0-9\]+, x\[0-9\]+" } } */
      54    if (d <= 0)
      55      return a + c;
      56    else
      57      return b + d + c;
      58  }
      59  
      60  s64
      61  subs_di_test2 (s64 a, s64 b, s64 c)
      62  {
      63    s64 d = a - 0x1000ll;
      64  
      65    /* { dg-final { scan-assembler-not "subs\tx\[0-9\]+, x\[0-9\]+, #4096" } } */
      66    /* { dg-final { scan-assembler "sub\tx\[0-9\]+, x\[0-9\]+, #4096" } } */
      67    if (d <= 0)
      68      return a + c;
      69    else
      70      return b + d + c;
      71  }
      72  
      73  s64
      74  subs_di_test3 (s64 a, s64 b, s64 c)
      75  {
      76    s64 d = a - (b << 3);
      77  
      78    /* { dg-final { scan-assembler-not "subs\tx\[0-9\]+, x\[0-9\]+, x\[0-9\]+, lsl 3" } } */
      79    /* { dg-final { scan-assembler "sub\tx\[0-9\]+, x\[0-9\]+, x\[0-9\]+, lsl 3" } } */
      80    if (d <= 0)
      81      return a + c;
      82    else
      83      return b + d + c;
      84  }
      85  
      86  int main ()
      87  {
      88    int x;
      89    s64 y;
      90  
      91    x = subs_si_test1 (29, 4, 5);
      92    if (x != 34)
      93      abort ();
      94  
      95    x = subs_si_test1 (5, 2, 20);
      96    if (x != 25)
      97      abort ();
      98  
      99    x = subs_si_test2 (29, 4, 5);
     100    if (x != 34)
     101      abort ();
     102  
     103    x = subs_si_test2 (1024, 2, 20);
     104    if (x != 1044)
     105      abort ();
     106  
     107    x = subs_si_test3 (35, 4, 5);
     108    if (x != 12)
     109      abort ();
     110  
     111    x = subs_si_test3 (5, 2, 20);
     112    if (x != 25)
     113      abort ();
     114  
     115    y = subs_di_test1 (0x130000029ll,
     116  		     0x320000004ll,
     117  		     0x505050505ll);
     118  
     119    if (y != 0x63505052e)
     120      abort ();
     121  
     122    y = subs_di_test1 (0x5000500050005ll,
     123  		     0x2111211121112ll,
     124  		     0x0000000002020ll);
     125    if (y != 0x5000500052025)
     126      abort ();
     127  
     128    y = subs_di_test2 (0x130000029ll,
     129  		     0x320000004ll,
     130  		     0x505050505ll);
     131    if (y != 0x95504f532)
     132      abort ();
     133  
     134    y = subs_di_test2 (0x540004100ll,
     135  		     0x320000004ll,
     136  		     0x805050205ll);
     137    if (y != 0x1065053309)
     138      abort ();
     139  
     140    y = subs_di_test3 (0x130000029ll,
     141  		     0x064000008ll,
     142  		     0x505050505ll);
     143    if (y != 0x63505052e)
     144      abort ();
     145  
     146    y = subs_di_test3 (0x130002900ll,
     147  		     0x088000008ll,
     148  		     0x505050505ll);
     149    if (y != 0x635052e05)
     150      abort ();
     151  
     152    return 0;
     153  }
     154