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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2026-11-25
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Drea Pinski <pinskia at gcc dot gnu.org> ---
```
  _1 = (unsigned _BitInt(3)) g_14(D);
  _2 = (unsigned _BitInt(3)) i_15(D);
  _3 = _1 + _2;
  _4 = (_BitInt(3)) _3;
  acc_16 = (long int) _4;
  if (i_15(D) != 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 4>; [50.00%]

  <bb 3> [local count: 536870912]:

  <bb 4> [local count: 1073741824]:
  # _9 = PHI <0(3), _3(2)>
  c_19 = VIEW_CONVERT_EXPR<_BitInt(8)>(_9);
  _5 = VIEW_CONVERT_EXPR<_BitInt(3)>(c_19);
```

This looks ok to me.  Even though it is a bit odd.  The problem I suspect is
the VCE here.

Which gets expanded to:
```
;; c_19 = VIEW_CONVERT_EXPR<_BitInt(8)>(_9);

(insn 22 21 0 (set (reg:QI 112 [ cD.2995 ])
        (reg:QI 102 [ _3 ])) "/app/example.cpp":6:18 -1
     (nil))

;; _5 = VIEW_CONVERT_EXPR<_BitInt(3)>(c_19);

(insn 23 22 0 (set (reg:QI 104 [ _5 ])
        (reg:QI 112 [ cD.2995 ])) "/app/example.cpp":9:17 -1
     (nil))
```

So the question is about the padding bits in the register do they need to be
sign/zero extended? 


What SRA did seems reasonible even:
```
  _4 = (_BitInt(3)) _3;
  _29 = VIEW_CONVERT_EXPR<_BitInt(8)>(_4);
  b_32 = _29;
  _5 = VIEW_CONVERT_EXPR<_BitInt(3)>(b_32);
...

  # c_30 = PHI <c_33(3), c_34(4)>
  a_35 = c_30;
  _6 = VIEW_CONVERT_EXPR<_BitInt(3)>(a_35);
```


```

Applying pattern match.pd:6347, gimple-match-5.cc:9453
gimple_simplified to _18 = VIEW_CONVERT_EXPR<_BitInt(8)>(_3);
```
Is in forwprop.

The pattern which seems to be causing the issue:
```
/* Strip inner integral conversions that do not change precision or size, or
   zero-extend while keeping the same size (for bool-to-char).
   However, keep this conversion if the result is an extended _BitInt,
   since it may rely on this conversion to extend properly.  */

(simplify
  (view_convert (convert@0 @1))
  (with {
    bool extended_bitint = false;
    if (BITINT_TYPE_P (TREE_TYPE (@0)))
      {
        struct bitint_info info;
        extended_bitint
          = targetm.c.bitint_type_info (TYPE_PRECISION (TREE_TYPE (@0)),
                                                        &info);
        extended_bitint = extended_bitint && info.extended;
      }
   }
  (if ((INTEGRAL_TYPE_P (TREE_TYPE (@0)) || POINTER_TYPE_P (TREE_TYPE (@0)))
       && (INTEGRAL_TYPE_P (TREE_TYPE (@1)) || POINTER_TYPE_P (TREE_TYPE (@1)))
       && !extended_bitint
       && TYPE_SIZE (TREE_TYPE (@0)) == TYPE_SIZE (TREE_TYPE (@1))
       && (TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1))
           || (TYPE_PRECISION (TREE_TYPE (@0)) > TYPE_PRECISION (TREE_TYPE
(@1))
               && TYPE_UNSIGNED (TREE_TYPE (@1)))))
   (view_convert @1))))
```

Which does something special already for some BITINT types
(r16-3039-ged1ee231172112) but maybe it should do it always.

Reply via email to