2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / gcc / testsuite / gcc.dg / optimize-bswaphi-1.c
blob3e51f043cae62f744ca99c893fa158392454da26
1 /* { dg-do compile } */
2 /* { dg-require-effective-target bswap16 } */
3 /* { dg-require-effective-target stdint_types } */
4 /* { dg-options "-O2 -fdump-tree-bswap" } */
5 /* { dg-additional-options "-march=z900" { target s390-*-* } } */
7 #include <stdint.h>
9 unsigned char data[2];
11 struct uint16_st {
12 unsigned char u0, u1;
15 uint32_t read_le16_1 (void)
17 return data[0] | (data[1] << 8);
20 uint32_t read_le16_2 (struct uint16_st data)
22 return data.u0 | (data.u1 << 8);
25 uint32_t read_le16_3 (unsigned char *data)
27 return *data | (*(data + 1) << 8);
30 uint32_t read_be16_1 (void)
32 return data[1] | (data[0] << 8);
35 uint32_t read_be16_2 (struct uint16_st data)
37 return data.u1 | (data.u0 << 8);
40 uint32_t read_be16_3 (unsigned char *data)
42 return *(data + 1) | (*data << 8);
45 /* { dg-final { scan-tree-dump-times "16 bit load in target endianness found at" 3 "bswap" } } */
46 /* { dg-final { scan-tree-dump-times "16 bit bswap implementation found at" 3 "bswap" { xfail alpha*-*-* arm*-*-* } } } */
47 /* { dg-final { cleanup-tree-dump "bswap" } } */