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

--- Comment #8 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:8394d27cfea0adf784e414068b5c0da32ff8efdf

commit r16-8757-g8394d27cfea0adf784e414068b5c0da32ff8efdf
Author: Jakub Jelinek <[email protected]>
Date:   Mon Apr 20 09:08:49 2026 +0200

    bitintlower: Padding bit fixes, part 2 [PR123635]

    So, I've tried the (extremely slow) cfarm95 RISCV box and found that my
    earlier PR123635 patch actually broke stuff.
    First thing I found is that __riscv__ macro I was using in bitintext.h
    doesn't exist and fixed that.
    I wrote two new tests (88/89, one for a problem I'll talk about later and
    one to cover shifts) and fixed one nit in 86/87.  All the testing
    has been done on this modified tests and using
    make -j8 -k check-gcc RUNTESTFLAGS="dg.exp='*bitint* pr112673.c
builtin-stdc-bit-*.c pr112566-2.c pr112511.c pr116588.c pr116003.c pr113693.c
pr113602.c flex-array-counted-by-7.c' dg-torture.exp='*bitint* pr116480-2.c
pr114312.c pr114121.c' dfp.exp=*bitint*
vect.exp='vect-early-break_99-pr113287.c' tree-ssa.exp=pr113735.c"
    On pre-r16-8678 source, the FAILs were
    FAIL: gcc.dg/torture/bitint-82.c   -O0  execution test
    FAIL: gcc.dg/torture/bitint-82.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-83.c   -O0  execution test
    FAIL: gcc.dg/torture/bitint-83.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-86.c   -O0  execution test
    FAIL: gcc.dg/torture/bitint-86.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-87.c   -O0  execution test
    FAIL: gcc.dg/torture/bitint-87.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-88.c   -O0  execution test
    FAIL: gcc.dg/torture/bitint-88.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-89.c   -O0  execution test
    FAIL: gcc.dg/torture/bitint-89.c   -O2  execution test
    i.e. all the bitintext.h tests for padding bits (except bitint-84.c),
    plus gcc.dg/bitint-39.c gcc.dg/torture/bitint-37.c tests timing out
    (but those timed out due to extremely slow CPU all the time, and are
    really large and not padding related, so let's ignore that).
    Now, with r16-8678 (i.e. vanilla trunk), the FAILs are
    FAIL: gcc.dg/torture/bitint-42.c   -O0  execution test
    FAIL: gcc.dg/torture/bitint-42.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-62.c   -O0  execution test
    FAIL: gcc.dg/torture/bitint-62.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-66.c   -O0  execution test
    FAIL: gcc.dg/torture/bitint-68.c   -O0  execution test
    FAIL: gcc.dg/torture/bitint-68.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-79.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-80.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-81.c   -O0  execution test
    FAIL: gcc.dg/torture/bitint-81.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-83.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-87.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-88.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-89.c   -O2  execution test
    So, I broke some tests (42, 62, 66, 68, 79, 80, 81) and
    fixed a few too (82, 86 and at -O0 only 83, 87, 88, 89).

    I've debugged the regressions I've caused and the problem is on large/huge
    _BitInt bit-field stores, we can't clear any padding bits in those cases,
    bit-fields never have paddings (C FE rejects oversized bit-fields and the
    padding is used for further fields or is merely structure padding rather
    than padding of the bit-field).
    The following patch fixes more than that.  There is another problem
    (bitint-88.c tries to test that), when we merge some operation (e.g.
    addition) of some narrower large/huge _BitInt with sign extension from
    it into a wider unsigned _BitInt (e.g. signed _BitInt(513) addition
    sign extended into unsigned _BitInt(1025)), the earlier solution for
    the extra padding limb doesn't work properly, we do want to sign
    extend the bit 512 into bits 513-1024, but the padding bits above
    that need to be cleared.  For the limb containing bit 1024 we do it
    right, it is sign extension but outside of loop, so should cast the
    all zeros or all ones value to unsigned long : 1 and back, but
    the limb containing bit 1088 needs to be just zeroed.
    And the patch also adds the bitint_ext_full handling to RSHIFT_EXPR
    and LSHIFT_EXPR code.
    With this, the FAILs on riscv64-linux are
    FAIL: gcc.dg/torture/bitint-87.c   -O2  execution test
    FAIL: gcc.dg/torture/bitint-89.c   -O2  execution test
    which means I need to debug further the multiplication/division/modulo/
    casts from float and there is some remaining problem with the shifts.
    Plus something not covered yet, the overflow builtins/ubsan (all of +-*).

    In any case, because this patch doesn't regress on riscv64-linux any
    actual non-padding tests and even these two aren't regressions, I'd
    like to commit this patch separately and fix stuff incrementally,
    to unbreak the bit-field stores.

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

            PR middle-end/123635
            * gimple-lower-bitint.cc (bitint_precision_kind): Assert the
current
            assumptions, that bitint_ext_full for abi_limb_prec > limb_prec is
            supported only when abi_limb_prec is limb_Prec * 2 and it is not
            big endian in that case.
            (bitint_large_huge::lower_mergeable_stmt): Don't set separate_ext
            fir bitint_ext_full for bit-field stores.  Guard the condition
            on an extra limb of padding bits to be extended rather than
including
            earlier extensions in that too.  If already sign extending before
            and type is unsigned, set zero_ms_limb instead and later handle it.
            (bitint_large_huge::lower_shift_stmt): Handle bitint_ext_full.

            * gcc.dg/bitintext.h: Use __riscv macro instead of __riscv__.
            * gcc.dg/torture/bitint-86.c: Remove bogus sync_char_short
            effective target.
            * gcc.dg/torture/bitint-87.c: Likewise.
            * gcc.dg/torture/bitint-88.c: New test.
            * gcc.dg/torture/bitint-89.c: New test.

    Reviewed-by: Jeffrey Law <[email protected]>

Reply via email to