S/390: Fix conditional returns on z196+
[official-gcc.git] / gcc / testsuite / gcc.target / s390 / insv-2.c
blob70af123c4ff8e455a38b51b8f8c2f3d502499f47
1 /* { dg-do compile } */
2 /* { dg-options "-O3 -march=zEC12 -mzarch" } */
4 unsigned long
5 foo1 (unsigned long a, unsigned long b)
7 return (a << 5) | (b & (((1UL << 5) - 1)));
10 /* This generates very different RTX than foo1. The output reg (r2)
11 matches the unshifted argument. So it actually is a
12 (set (zero_extract a 59 0) b) */
13 unsigned long
14 foo2 (unsigned long a, unsigned long b)
16 return (b << 5) | (a & (((1UL << 5) - 1)));
19 /* risbgn cannot be used when less bits are removed with the mask. */
21 unsigned long
22 foo1b (unsigned long a, unsigned long b)
24 return (a << 5) | (b & 1);
27 unsigned long
28 foo2b (unsigned long a, unsigned long b)
30 return (b << 5) | (a & 1);
33 /* risbgn cannot be used when the masked bits would end up in the
34 result since a real OR is required then. */
35 unsigned long
36 foo1c (unsigned long a, unsigned long b)
38 return (a << 5) | (b & 127);
41 unsigned long
42 foo2c (unsigned long a, unsigned long b)
44 return (b << 5) | (a & 127);
47 unsigned long
48 foo3 (unsigned long a, unsigned long b)
50 #ifdef __s390x__
51 return (a << 5) | (b >> 59);
52 #else
53 return (a << 5) | (b >> 27);
54 #endif
57 unsigned long
58 foo4 (unsigned long a, unsigned long b)
60 #ifdef __s390x__
61 return (b << 5) | (a >> 59);
62 #else
63 return (b << 5) | (a >> 27);
64 #endif
67 /* risbgn can be used also if there are some bits spared in the middle
68 of the two chunks. */
69 unsigned long
70 foo3b (unsigned long a, unsigned long b)
72 #ifdef __s390x__
73 return (a << 6) | (b >> 59);
74 #else
75 return (a << 6) | (b >> 27);
76 #endif
79 unsigned long
80 foo4b (unsigned long a, unsigned long b)
82 #ifdef __s390x__
83 return (b << 6) | (a >> 59);
84 #else
85 return (b << 6) | (a >> 27);
86 #endif
89 /* One bit of overlap so better don't use risbgn. */
91 unsigned long
92 foo3c (unsigned long a, unsigned long b)
94 #ifdef __s390x__
95 return (a << 4) | (b >> 59);
96 #else
97 return (a << 4) | (b >> 27);
98 #endif
101 unsigned long
102 foo4c (unsigned long a, unsigned long b)
104 #ifdef __s390x__
105 return (b << 4) | (a >> 59);
106 #else
107 return (b << 4) | (a >> 27);
108 #endif
111 /* The functions foo3, foo4, foo3b, foo4b no longer use risbgn but rosbg instead
112 which is slightly worse. Combine prefers to use the simpler two insn
113 combinations possible with rosbg instead of the more complicated three insn
114 combinations that result in risbgn. This problem has been introduced with
115 the commit
117 S/390: Add patterns for r<nox>sbg instructions.
119 (3rd of May, 2016). This should be fixed some time in the future, but for
120 now just adapt the expected result:
122 { dg-final { scan-assembler-times "risbgn" 6 { xfail { *-*-* } } } }
123 { dg-final { scan-assembler-times "risbgn" 2 } }