Skip to content

Commit 29998cc

Browse files
committed
range-op: Fix up ABSU_EXPR handling [PR113756]
ABSU_EXPR unary expr is special because it has a signed integer argument and unsigned integer result (of the same precision). The following testcase is miscompiled since ABSU_EXPR handling has been added to range-op because it uses widest_int::from with the result sign (i.e. UNSIGNED) rather than the operand sign (i.e. SIGNED), so e.g. for the 32-bit int argument mask ends up 0xffffffc1 or something similar and even when it has most significant bit in the precision set, in widest_int (tree-ssa-ccp.cc really should stop using widest_int, but that is I think stage1 task) it doesn't appear to be negative and so bit_value_unop ABSU_EXPR doesn't set the resulting mask/value from oring of the argument and its negation. Fixed thusly, not doing that for GIMPLE_BINARY_RHS because I don't know about a binary op that would need something similar. 2024-02-06 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/113756 * range-op.cc (update_known_bitmask): For GIMPLE_UNARY_RHS, use TYPE_SIGN (lh.type ()) instead of sign for widest_int::from of lh_bits value and mask. * gcc.dg/pr113756.c: New test.
1 parent 6e308d5 commit 29998cc

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

gcc/range-op.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,10 @@ update_known_bitmask (irange &r, tree_code code,
435435
bit_value_unop (code, sign, prec, &widest_value, &widest_mask,
436436
TYPE_SIGN (lh.type ()),
437437
TYPE_PRECISION (lh.type ()),
438-
widest_int::from (lh_bits.value (), sign),
439-
widest_int::from (lh_bits.mask (), sign));
438+
widest_int::from (lh_bits.value (),
439+
TYPE_SIGN (lh.type ())),
440+
widest_int::from (lh_bits.mask (),
441+
TYPE_SIGN (lh.type ())));
440442
break;
441443
case GIMPLE_BINARY_RHS:
442444
bit_value_binop (code, sign, prec, &widest_value, &widest_mask,

gcc/testsuite/gcc.dg/pr113756.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* PR tree-optimization/113756 */
2+
/* { dg-do run { target int32plus } } */
3+
/* { dg-options "-O2" } */
4+
5+
int d, e, i, k, l = -8;
6+
signed char h, j;
7+
8+
int
9+
bar (int n, int o, int p3)
10+
{
11+
int a = o - p3, b = n - p3, c = a + b, f = -b, g = c < 0 ? -c : c;
12+
return a <= f && a <= g ? o : p3;
13+
}
14+
15+
void
16+
foo (int *n, unsigned short o)
17+
{
18+
unsigned p = 8896;
19+
for (; e >= 0; e--)
20+
p = 5377;
21+
for (; h <= 0; h++)
22+
for (; j <= 0; j++)
23+
{
24+
*n = 1611581749;
25+
i = bar (34, p - 5294, *n - 1611581687);
26+
k = i + p + 65535 + o + *n - 1611718251;
27+
if (k != 0)
28+
__builtin_abort ();
29+
}
30+
}
31+
32+
int
33+
main ()
34+
{
35+
foo (&l, l);
36+
}

0 commit comments

Comments
 (0)