(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
powerpc/
pr87532.c
       1  /* { dg-do run } */
       2  /* { dg-require-effective-target vmx_hw } */
       3  /* { dg-options "-maltivec" } */
       4  
       5  /* This test should run the same on any target that supports altivec/dfp
       6     instructions.  Intentionally not specifying cpu in order to test
       7     all code generation paths.  */
       8  
       9  #include <stdlib.h>
      10  #include <stddef.h>
      11  #include <altivec.h>
      12  #include <stdio.h>
      13  
      14  static void
      15  check (unsigned char, unsigned char) __attribute__((__noinline__));
      16  
      17  static __attribute__((altivec(vector__))) unsigned char
      18  deoptimize (__attribute__((altivec(vector__))) unsigned char)
      19  __attribute__((__noinline__));
      20  
      21  static __attribute__((altivec(vector__))) unsigned char
      22  deoptimize (__attribute__((altivec(vector__))) unsigned char a)
      23  {
      24    __asm__ (" # %x0" : "+v" (a));
      25    return a;
      26  }
      27  
      28  // Toggle this attribute inline/noinline to see pass/fail.
      29  // fails with the noinline attribute applied.
      30  __attribute__ ((__noinline__))
      31  unsigned char
      32  get_auto_n (__attribute__((altivec(vector__))) unsigned char a, size_t n)
      33  {
      34    return (unsigned char) __builtin_vec_extract (a, n);
      35  }
      36  
      37  void
      38  do_auto (__attribute__((altivec(vector__))) unsigned char a)
      39  {
      40    size_t i;
      41    for (i = 1; i < 3 ; i++)
      42    {
      43      do
      44        {
      45  	printf ("get_auto_n (a, %d) produces 0x0%x\n",
      46  		i, (int) get_auto_n (a, i));
      47  
      48  	if ((int) get_auto_n (a,i) > 250) abort();
      49        } while (0);
      50    }
      51  }
      52  
      53  int
      54  main (void)
      55  {
      56    size_t i;
      57    __attribute__((altivec(vector__))) unsigned char x =
      58      { 3, 2, 3, 8, 5, 6, 7, 8, 240, 241, 242, 243, 244, 245, 246, 247 };
      59    __attribute__((altivec(vector__))) unsigned char a;
      60  
      61    printf (" first elements of x are: %d %d %d %d %d\n",
      62  	  x[0], x[1], x[2], x[3], x[4]);
      63  
      64    a = deoptimize (x);
      65  
      66    printf (" after deoptimization, first elements of a are: %d %d %d %d %d\n",
      67  	  a[0], a[1], a[2], a[3], a[4]);
      68  
      69    do_auto (a);
      70  
      71    return 0;
      72  }