2 /* { dg-options "-O2 -fdump-tree-optimized" } */
4 /* MUL_OVERFLOW should not be folded into unsigned multiplication,
5 because it sometimes overflows and sometimes does not. */
6 __attribute__((noinline
, noclone
)) long int
7 fn1 (long int x
, long int y
, int *ovf
)
11 y
= (y
& 65535) - (__LONG_MAX__
/ 65535 + 32768);
12 *ovf
= __builtin_mul_overflow (x
, y
, &res
);
16 /* MUL_OVERFLOW should not be folded into unsigned multiplication,
17 because it sometimes overflows and sometimes does not. */
18 __attribute__((noinline
, noclone
)) signed char
19 fn2 (long int x
, long int y
, int *ovf
)
22 x
= (x
& 63) + (__SCHAR_MAX__
/ 4);
24 *ovf
= __builtin_mul_overflow (x
, y
, &res
);
28 /* ADD_OVERFLOW should be folded into unsigned additrion,
29 because it sometimes overflows and sometimes does not. */
30 __attribute__((noinline
, noclone
)) unsigned char
31 fn3 (unsigned char x
, unsigned char y
, int *ovf
)
34 x
= (x
& 63) + ((unsigned char) ~0 - 65);
36 *ovf
= __builtin_add_overflow (x
, y
, &res
);
40 /* ADD_OVERFLOW should be folded into unsigned additrion,
41 because it sometimes overflows and sometimes does not. */
42 __attribute__((noinline
, noclone
)) unsigned char
43 fn4 (unsigned char x
, unsigned char y
, int *ovf
)
46 x
= (x
& 15) + ((unsigned char) ~0 - 16);
48 *ovf
= __builtin_add_overflow (x
, y
, &res
);
52 /* MUL_OVERFLOW should not be folded into unsigned multiplication,
53 because it sometimes overflows and sometimes does not. */
54 __attribute__((noinline
, noclone
)) long int
55 fn5 (long int x
, unsigned long int y
, int *ovf
)
58 y
= -65536UL + (y
& 65535);
59 *ovf
= __builtin_mul_overflow (x
, y
, &res
);
67 if (fn1 (0, 0, &ovf
) != 0
69 || fn1 (65535, 0, &ovf
) != (long int) ((__LONG_MAX__
/ 65535 + 32768UL) * -65535UL)
72 if (fn2 (0, 0, &ovf
) != (signed char) (__SCHAR_MAX__
/ 4 * 4U)
74 || fn2 (0, 1, &ovf
) != (signed char) (__SCHAR_MAX__
/ 4 * 5U)
77 if (fn3 (0, 0, &ovf
) != (unsigned char) ~0 - 65
79 || fn3 (63, 2, &ovf
) != (unsigned char) ~0
81 || fn3 (62, 3, &ovf
) != (unsigned char) ~0
83 || fn3 (63, 3, &ovf
) != 0
86 if (fn4 (0, 0, &ovf
) != (unsigned char) ~0
88 || fn4 (1, 0, &ovf
) != 0
90 || fn4 (0, 1, &ovf
) != 0
92 || fn4 (63, 3, &ovf
) != 17
95 if (fn5 (0, 0, &ovf
) != 0
97 || fn5 (1, 0, &ovf
) != -65536L
99 || fn5 (2, 32768, &ovf
) != -65536L
101 || fn5 (4, 32768 + 16384 + 8192, &ovf
) != -32768L
107 /* { dg-final { scan-tree-dump-times "ADD_OVERFLOW" 2 "optimized" } } */
108 /* { dg-final { scan-tree-dump-times "SUB_OVERFLOW" 0 "optimized" } } */
109 /* { dg-final { scan-tree-dump-times "MUL_OVERFLOW" 3 "optimized" } } */