https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116137

            Bug ID: 116137
           Summary: missing VRP with absu and known not to include INF
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
            Blocks: 85316
  Target Milestone: ---

Take:
```
int
f1 (signed char x, signed char y)
{
  if (x == 0x80 || y == 0x80) return 0;
  x= __builtin_abs(x);
  y= __builtin_abs(y);
  return (x < 0) ^ (y < 0);
}
```

This should just optimize to `return 0`.
>From the VRP dump we have:
Folding statement: _1 = ABSU_EXPR <x_5(D)>;
Global Exported: _1 = [irange] unsigned char [0, 128]
Not folded
Folding statement: _2 = ABSU_EXPR <y_7(D)>;
Global Exported: _2 = [irange] unsigned char [0, 128]
Not folded
Folding statement: _11 = _1 ^ _2;
Not folded

But there is no range on _11 even though it is obvious it is just [0,128]
still.

If we manually tried to create the range like:
```
int
f2_ (unsigned char x, unsigned char y)
{
  if (x >= 128 || y >= 128) return 0;
 unsigned char t = x ^ y;
 signed char t1 = t;
  return t1 < 0;
}
```
This works and we get:
Folding statement: t_10 = x_8(D) ^ y_9(D);
Global Exported: t_10 = [irange] unsigned char [0, 127] MASK 0x7f VALUE 0x0
Not folded

And if we look at the ranges for that bb we get:
2->4  (F) x_8(D) :      [irange] unsigned char [0, 127] MASK 0x7f VALUE 0x0
2->4  (F) y_9(D) :      [irange] unsigned char [0, 127] MASK 0x7f VALUE 0x0


Notice how there is a MASK/VALUE here but in the ABSU case there is not. I
suspect that is what is causing the problem.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases

Reply via email to