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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-01-24
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

Either fold or convert is causing the issue.

Reduced testcase:
```
unsigned _BitInt(1)
foo(unsigned _BitInt(16) ub16)
{
  unsigned _BitInt(1)  t  = (ub16 << 2);
    // being reduced to just (unsigned _BitInt(1) ) ub16 which is wrong
  return t;
}
unsigned _BitInt(1)
foo1(unsigned _BitInt(16) ub16)
{
  unsigned _BitInt(16) t = (ub16 << 2);
  return t;
}

int
main(void)
{
  unsigned _BitInt(16) ub16 = 0xfef1;
  if (foo(ub16) != foo1(ub16))
    __builtin_abort();
  return 0;
}
```

Note match does the correct thing:
```
/* Narrow a lshift by constant.  */
(simplify
 (convert (lshift:s@0 @1 INTEGER_CST@2))
 (if (INTEGRAL_TYPE_P (type)
      && INTEGRAL_TYPE_P (TREE_TYPE (@0))
      && !integer_zerop (@2)
      && TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (@0)))
  (if (TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (@0))
       || wi::ltu_p (wi::to_wide (@2), TYPE_PRECISION (type)))
   (lshift (convert @1) @2)
   (if (wi::ltu_p (wi::to_wide (@2), TYPE_PRECISION (TREE_TYPE (@0))))
    { build_zero_cst (type); }))))

```

Reply via email to