]> git.ipfire.org Git - thirdparty/gcc.git/commit
lower-bitint: Fix _BitInt .{ADD,SUB}_OVERFLOW lowering [PR112750]
authorJakub Jelinek <jakub@redhat.com>
Fri, 1 Dec 2023 08:25:45 +0000 (09:25 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 1 Dec 2023 08:25:45 +0000 (09:25 +0100)
commit364332658ef790d09d250db39c5b13e27c3543f1
treec427cc35ebdf323d602b005acb571038169b793b
parent875c7771097d12f81f658f5f01ef52ec5b57f678
lower-bitint: Fix _BitInt .{ADD,SUB}_OVERFLOW lowering [PR112750]

The .{ADD,SUB}_OVERFLOW lowering is implemented by performing normal
addition/subtraction (perhaps extended to even more bits than normally by
continuing with extended values of operands after running of normal bits)
and in addition to that trying to compute if certain sets of bits are either
all zero or all sign extensions of the least significant bit.

That code is in a lot of cases guarded just by a single condition (which
can be idx > startlimb, idx >= startlimb or idx == startlimb) or by
2 conditions - if (idx >= startlimb) { if (idx == startlimb) ... else ... }
Now, if_then_if_then_else when the second argument is NULL works just as
if_then and sets m_gsi to be within the initially empty then block and that is
where we emit code for constant tidx startlimb + (cmp_code == GT_EXPR).
But in the 2 conditions case, m_gsi is set to the initially empty else
block, so using EQ_EXPR for the condition was incorrect (and strangely
nothing in the testsuite caught that), because the code for extracting the
lowest set of bits (i.e. when tidx is startlimb) is then done when idx
is not startlimb rather than when it is.
The following patch fixes that.

Note, when developing the lowering, I was using gcov to make sure all code
is covered by the testsuite with minimum exceptions, so no idea how this
slipped out.

2023-12-01  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/112750
* gimple-lower-bitint.cc (bitint_large_huge::lower_addsub_overflow):
Use NE_EXPR rather than EQ_EXPR for g2 if !single_comparison and
adjust probabilities.

* gcc.dg/bitint-41.c: Use -std=c23 rather than -std=c2x.
* gcc.dg/torture/bitint-43.c: Likewise.
* gcc.dg/torture/bitint-44.c: Likewise.
* gcc.dg/torture/bitint-45.c: New test.
gcc/gimple-lower-bitint.cc
gcc/testsuite/gcc.dg/bitint-41.c
gcc/testsuite/gcc.dg/torture/bitint-43.c
gcc/testsuite/gcc.dg/torture/bitint-44.c
gcc/testsuite/gcc.dg/torture/bitint-45.c [new file with mode: 0644]