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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <[email protected]>:

https://gcc.gnu.org/g:4abe2b137f26173c489f4acb96f662ea542a0519

commit r17-6489-g4abe2b137f26173c489f4acb96f662ea542a0519
Author: Jakub Jelinek <[email protected]>
Date:   Fri Nov 20 10:17:30 2026 +0100

    bitintlower: Handle COMPLEX_CST lowering [PR128869]

    The following testcase is miscompiled during bitintlowering.
    We have
      # y_3 = PHI <y_7(3), 5(2), 0(4)>
      <L6>:
      _8 = .SUB_OVERFLOW
(0x8000000000000000000000000000000000000000000000000000000000000000, y_3);
      _1 = IMAGPART_EXPR <_8>;
      _2 = (bool) _1;
      _9 = (int) _2;
      return _9;
    and the switch before this uses large/huge _BitInt, so we early in the
    pass lower the switch and do cleanup_tree_cfg.  In this case it removes
    some edges and y_3 is simplified into 0 and we end up with
      s_5 = (_BitInt(257)) c_4(D);
      _8 = __complex__ (0, 1);
      _1 = IMAGPART_EXPR <_8>;
      _2 = (bool) _1;
      _9 = (int) _2;
      return _9;
    as the content of the whole function.  Now, bitintlower doesn't handle
    COMPLEX_CST because it was never actually needed, it would be always
    propagated into the REALPART_EXPR and IMAGPART_EXPR uses thereof (note,
    we don't support _Complex _BitInt, only the uses of COMPLEX_TYPE of
    BITINT_TYPE in return values of .{ADD,SUB,MUL}_OVERFLOW and .CLMUL_WIDEN).
    But in this case such cleanup doesn't happen and for lower_stmt we actually
    even didn't call that at all (that one would ICE on unknown stmts), but
    we only handled BITINT_TYPE_P as SSA uses or sets and had special case
    for GIMPLE_CALL lhs.
    This patch fixes this by handling also COMPLEX_CST (by the same routine
    as COMPLEX_EXPR, only very small change is needed to find out the two
    halves) and tweaks the bitint kind discovery so that for all SSA_NAMEs
    it looks also for COMPLEX_TYPEs.

    2026-11-20  Jakub Jelinek  <[email protected]>

            PR tree-optimization/128869
            * gimple-lower-bitint.cc
(bitint_large_huge::lower_complexexpr_stmt):
            Also handle COMPLEX_CST.
            (bitint_large_huge::lower_stmt): Likewise.
            (gimple_lower_bitint): Handle COMPLEX_TYPE of BITINT_TYPE_P as
well.

            * gcc.dg/bitint-150.c: New test.

    Reviewed-by: Richard Biener <[email protected]>

Reply via email to