(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
sh/
pr53987-1.c
       1  /* Check that no unnecessary sign/zero extensions are being emitted.  */
       2  /* { dg-do compile }  */
       3  /* { dg-options "-O2" }  */
       4  /* { dg-final { scan-assembler-times "extu.b" 2 } }  */
       5  /* { dg-final { scan-assembler-not "extu.w" } }  */
       6  /* { dg-final { scan-assembler-not "exts.b" } }  */
       7  /* { dg-final { scan-assembler-not "exts.w" } }  */
       8  /* { dg-final { scan-assembler-not "movu" } }  */
       9  /* { dg-final { scan-assembler-not "tst\t#255" } }  */
      10  
      11  int
      12  test_00 (unsigned char* x, char* xx, int y, int z)
      13  {
      14    /* If x[0] / b is treated as a non-extended QImode subreg the zero
      15       test will be a QImode subreg test, which is supposed to ignore
      16       bits[31:8].  However, since the QImode memory load always sign
      17       extends, it's also OK to test all the bits.  Thus we don't want
      18       to see a tst #255 here.  */
      19    int b = x[0];
      20    xx[0] = b;
      21    return b ? y : z;
      22  }
      23  
      24  int
      25  test_01 (unsigned char a, unsigned char b, int c, int d)
      26  {
      27    /* 2x extu.b  */
      28    if (a == b)
      29      return c;
      30    return d;
      31  }
      32  
      33  int
      34  test_02 (unsigned char* a, unsigned char* b, int c, int d)
      35  {
      36    /* 2x mov.b  */
      37    if (*a != 0 && *b == 0)
      38      return c;
      39    return d;
      40  }
      41  
      42  int
      43  test_03 (unsigned char* a)
      44  {
      45    /* 1x mov.b  */
      46    return *a == 0;
      47  }
      48  
      49  int
      50  test_04 (unsigned short* a)
      51  {
      52    /* 1x mov.w  */
      53    return *a == 0;
      54  }
      55  
      56  unsigned char test_05_var;
      57  int
      58  test_05 (int a, int b, int c, int d)
      59  {
      60    /* Must not see sign/zero extension here.  */
      61    test_05_var = (a == b) | (b == c);
      62    if (test_05_var)
      63      return d;
      64  
      65    return 0;
      66  }