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

            Bug ID: 111285
           Summary: vector ABSU is lowered incorrectly
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
            Blocks: 110009
  Target Milestone: ---

Take:
```
#define vector __attribute__((vector_size(1*sizeof(int))))
void unsigned_f1 (vector int *vp,  vector unsigned *x)
{
  vector int v = *vp;
  vector unsigned int d_6;
  vector int b_5;
  vector unsigned int v1_2;
  vector unsigned int _7;
  vector int _9;

  b_5 = v>>(sizeof(int)*8 - 1);
  _9 = b_5 | 1;
  d_6 = (vector unsigned int) _9;
  v1_2 = (vector unsigned int) v;
  _7 = v1_2 * d_6;
  *x = _7;
}


```
and this match.pd pattern:
```
/* x * ((x>>N)|1) -> abs(x) */
(simplify
 (mult:c @0 (nop_convert? (bit_ior:c (rshift @1 INTEGER_CST@2) integer_onep)))
 (if (!TYPE_UNSIGNED (TREE_TYPE (@1))
      && wi::to_wide (@2) == element_precision (type) - 1
      && bitwise_equal_p (@0, @1))
  (if (TYPE_UNSIGNED (type))
   (absu @1)
   (abs @1))))
```
With this we get right before vector lowering:
```
  v_3 = *vp_2(D);
  _7_4 = ABSU_EXPR <v_3>;
  # .MEM_6 = VDEF <.MEM_1(D)>
  *x_5(D) = _7_4;
```
Which is correct.
But then lowering comes along and gives:
```
  v_3 = *vp_2(D);
  _7 = VIEW_CONVERT_EXPR<unsigned intD.9>(v_3);
  _7_4 = {_7};
  # .MEM_6 = VDEF <.MEM_1(D)>
  *x_5(D) = _7_4;

```

This is because we used the lhs type rather than the rhs type ...


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110009
[Bug 110009] Another missing ABS detection

Reply via email to