(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
aarch64/
max_plus_1.c
       1  /* { dg-do run } */
       2  /* { dg-options "-O2 --save-temps" } */
       3  /* { dg-final { check-function-bodies "**" "" "" } } */
       4  
       5  /*
       6  ** f1:
       7  **	adds	(w[0-9]+), w0, #4
       8  **	csel	w0, \1, wzr, g[te]
       9  **	ret
      10  */
      11  /*
      12  ** f2:
      13  **	adds	(w[0-9]+), w0, #4
      14  **	csel	w0, \1, wzr, g[te]
      15  **	ret
      16  */
      17  /*
      18  ** f3:
      19  **	adds	(w[0-9]+), w0, #5
      20  **	csinc	w0, \1, wzr, gt
      21  **	ret
      22  */
      23  /*
      24  ** f4:
      25  **	adds	(w[0-9]+), w0, #3
      26  **	csinv	w0, \1, wzr, ge
      27  **	ret
      28  */
      29  
      30  #ifndef TYPE
      31  #define TYPE int32_t
      32  #define TYPE_MIN INT32_MIN
      33  #define TYPE_MAX INT32_MAX
      34  #define VALUE -4
      35  #endif
      36  
      37  #include <stdint.h>
      38  
      39  TYPE __attribute__((noipa))
      40  f1 (TYPE x)
      41  {
      42    return (x > VALUE ? x - VALUE : 0);
      43  }
      44  
      45  TYPE __attribute__((noipa))
      46  f2 (TYPE x)
      47  {
      48    return (x > VALUE ? x : VALUE) - VALUE;
      49  }
      50  
      51  TYPE __attribute__((noipa))
      52  f3 (TYPE x)
      53  {
      54    return (x > VALUE ? x : VALUE) - (VALUE - 1);
      55  }
      56  
      57  TYPE __attribute__((noipa))
      58  f4 (TYPE x)
      59  {
      60    return (x > VALUE ? x : VALUE) - (VALUE + 1);
      61  }
      62  
      63  TYPE __attribute__((noipa))
      64  f5 (TYPE x)
      65  {
      66    return (x > VALUE ? x : VALUE) - (VALUE + 2);
      67  }
      68  
      69  TYPE __attribute__((noipa))
      70  f6 (TYPE x)
      71  {
      72    return (x > VALUE ? x : VALUE) - (VALUE - 2);
      73  }
      74  
      75  int
      76  main (void)
      77  {
      78    TYPE max_test = TYPE_MAX;
      79    if (TYPE_MIN < 0 && VALUE < 0)
      80      max_test += VALUE;
      81  
      82    if (f1 (TYPE_MIN) != 0)
      83      __builtin_abort ();
      84    if (f1 (VALUE - 1) != 0)
      85      __builtin_abort ();
      86    if (f1 (VALUE) != 0)
      87      __builtin_abort ();
      88    if (f1 (VALUE + 1) != 1)
      89      __builtin_abort ();
      90    if (f1 (max_test) != max_test - VALUE)
      91      __builtin_abort ();
      92  
      93    if (f2 (TYPE_MIN) != 0)
      94      __builtin_abort ();
      95    if (f2 (VALUE - 1) != 0)
      96      __builtin_abort ();
      97    if (f2 (VALUE) != 0)
      98      __builtin_abort ();
      99    if (f2 (VALUE + 1) != 1)
     100      __builtin_abort ();
     101    if (f2 (max_test) != max_test - VALUE)
     102      __builtin_abort ();
     103  
     104    if (f3 (TYPE_MIN) != 1)
     105      __builtin_abort ();
     106    if (f3 (VALUE - 1) != 1)
     107      __builtin_abort ();
     108    if (f3 (VALUE) != 1)
     109      __builtin_abort ();
     110    if (f3 (VALUE + 1) != 2)
     111      __builtin_abort ();
     112    if (f3 (max_test - 1) != max_test - VALUE)
     113      __builtin_abort ();
     114  
     115    if (f4 (TYPE_MIN) != -1)
     116      __builtin_abort ();
     117    if (f4 (VALUE - 1) != -1)
     118      __builtin_abort ();
     119    if (f4 (VALUE) != -1)
     120      __builtin_abort ();
     121    if (f4 (VALUE + 1) != 0)
     122      __builtin_abort ();
     123    if (f4 (max_test) != max_test - VALUE - 1)
     124      __builtin_abort ();
     125  
     126    if (f5 (TYPE_MIN) != -2)
     127      __builtin_abort ();
     128    if (f5 (VALUE - 1) != -2)
     129      __builtin_abort ();
     130    if (f5 (VALUE) != -2)
     131      __builtin_abort ();
     132    if (f5 (VALUE + 1) != -1)
     133      __builtin_abort ();
     134    if (f5 (max_test) != max_test - VALUE - 2)
     135      __builtin_abort ();
     136  
     137    if (f6 (TYPE_MIN) != 2)
     138      __builtin_abort ();
     139    if (f6 (VALUE - 1) != 2)
     140      __builtin_abort ();
     141    if (f6 (VALUE) != 2)
     142      __builtin_abort ();
     143    if (f6 (VALUE + 1) != 3)
     144      __builtin_abort ();
     145    if (VALUE <= max_test - 2 && f6 (max_test - 2) != max_test - VALUE)
     146      __builtin_abort ();
     147  
     148    return 0;
     149  }