1 /* Only test on some 64-bit targets which do have bswap{si,di}2 patterns and
2 are either big or little endian (not pdp endian). */
3 /* { dg-do run { target { lp64 && { i?86-*-* x86_64-*-* powerpc*-*-* aarch64*-*-* } } } } */
4 /* { dg-require-effective-target store_merge } */
5 /* { dg-options "-O2 -fno-tree-vectorize -fdump-tree-store-merging" } */
7 __attribute__((noipa
)) void
8 f1 (unsigned char *p
, unsigned long long q
)
20 __attribute__((noipa
)) void
21 f2 (unsigned char *p
, unsigned long long q
)
33 __attribute__((noipa
)) void
34 f3 (unsigned char *__restrict p
, unsigned char *__restrict q
)
36 unsigned char q3
= q
[3];
37 unsigned char q2
= q
[2];
38 unsigned char q1
= q
[1];
39 unsigned char q0
= q
[0];
46 __attribute__((noipa
)) void
47 f4 (unsigned char *__restrict p
, unsigned char *__restrict q
)
55 struct S
{ unsigned char a
, b
; unsigned short c
; };
57 __attribute__((noipa
)) void
58 f5 (struct S
*__restrict p
, struct S
*__restrict q
)
60 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
61 unsigned char pa
= q
->c
>> 8;
62 unsigned char pb
= q
->c
;
63 unsigned short pc
= (q
->a
<< 8) | q
->b
;
64 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
65 unsigned char pa
= q
->c
;
66 unsigned char pb
= q
->c
>> 8;
67 unsigned short pc
= q
->a
| (q
->b
<< 8);
74 __attribute__((noipa
)) void
75 f6 (struct S
*__restrict p
, struct S
*__restrict q
)
77 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
80 p
->c
= (q
->a
<< 8) | q
->b
;
81 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
84 p
->c
= q
->a
| (q
->b
<< 8);
88 struct T
{ unsigned long long a
: 8, b
: 8, c
: 8, d
: 8, e
: 8, f
: 8, g
: 8, h
: 8; };
90 __attribute__((noipa
)) void
91 f7 (struct T
*__restrict p
, struct T
*__restrict q
)
103 struct S b
= { 0x11, 0x12,
104 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
106 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
110 struct T e
= { 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28 };
118 f1 (a
, 0x0102030405060708ULL
);
119 for (i
= 0; i
< 8; ++i
)
122 f2 (a
, 0x0102030405060708ULL
);
123 for (i
= 0; i
< 8; ++i
)
127 for (i
= 0; i
< 8; ++i
)
128 if (a
[i
] != (i
< 4 ? 8 - i
: 1 + i
))
130 f2 (a
, 0x090a0b0c0d0e0f10ULL
);
132 for (i
= 0; i
< 8; ++i
)
133 if (a
[i
] != (i
< 4 ? 9 + i
: 16 - i
))
136 if (c
.a
!= 0x14 || c
.b
!= 0x13
137 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
139 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
145 if (d
.a
!= 0x11 || d
.b
!= 0x12 || d
.c
!= b
.c
)
149 if (f
.a
!= 0x28 || f
.b
!= 0x27 || f
.c
!= 0x26 || f
.d
!= 0x25
150 || f
.e
!= 0x24 || f
.f
!= 0x23 || f
.g
!= 0x22 || f
.h
!= 0x21)
155 /* { dg-final { scan-tree-dump-times "Merging successful" 7 "store-merging" } } */
156 /* { dg-final { scan-tree-dump-times "__builtin_bswap64" 2 "store-merging" } } */
157 /* { dg-final { scan-tree-dump-times "__builtin_bswap32" 4 "store-merging" } } */