Debian Codegraph @

gcc/testsuite/gcc.dg/field-merge-1.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-O -save-temps -fdump-tree-optimized" } */
3
4 /* Check that field loads compared with constants are merged, even if
5 tested out of order, and when fields straddle across alignment
6 boundaries. */
7
8 struct TL {
9 unsigned char p;
10 unsigned int a;
11 unsigned char q;
12 unsigned int b;
13 unsigned char r;
14 unsigned int c;
15 unsigned char s;
16 } __attribute__ ((packed, aligned (4), scalar_storage_order ("little-endian")));
17
18 struct TB {
19 unsigned char p;
20 unsigned int a;
21 unsigned char q;
22 unsigned int b;
23 unsigned char r;
24 unsigned int c;
25 unsigned char s;
26 } __attribute__ ((packed, aligned (4), scalar_storage_order ("big-endian")));
27
28 #define vc (unsigned char)0xaa
29 #define vi (unsigned int)0x12345678
30
31 struct TL vL = { vc, vi, vc, vi, vc, vi, vc };
32 struct TB vB = { vc, vi, vc, vi, vc, vi, vc };
33
34 void f (void) {
35 /* Which words of | vL | vB | */
36 /* are accessed by |0123|0123| */
37 if (0 /* the tests? | | | */
38 || vL.p != vc /* |* | | */
39 || vB.p != vc /* | |* | */
40 || vL.s != vc /* | *| | */
41 || vB.q != vc /* | | * | */
42 || vL.a != vi /* |^* | | */
43 || vB.b != vi /* | | ^* | */
44 || vL.c != vi /* | *^| | */
45 || vB.c != vi /* | | ^*| */
46 || vL.b != vi /* | ^^ | | */
47 || vL.q != vc /* | ^ | | */
48 || vB.a != vi /* | |^^ | */
49 || vB.r != vc /* | | ^ | */
50 || vB.s != vc /* | | ^| */
51 || vL.r != vc /* | ^ | | */
52 )
53 __builtin_abort ();
54 }
55
56 int main () {
57 f ();
58 return 0;
59 }
60
61 /* { dg-final { scan-tree-dump-times "BIT_FIELD_REF" 8 "optimized" { target { ! { avr-*-* pru-*-* } } } } } */
62 /* { dg-final { scan-assembler-not "cmpb" { target { i*86-*-* || x86_64-*-* } } } } */
63 /* { dg-final { scan-assembler-times "cmpl" 8 { target { i*86-*-* || x86_64-*-* } } } } */
64 /* { dg-final { scan-assembler-times "cmpw" 8 { target { powerpc*-*-* || rs6000-*-* } } } } */