From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 176353858D38; Wed, 6 Dec 2023 08:56:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 176353858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701852996; bh=IiliQPo28HgezmJif5krdjk/4Y3mWb7P92QeNtgv/q8=; h=From:To:Subject:Date:From; b=SlvCgelEl3L2gBmvdkautsU8IqZze6uctjiSkSDY8e5E3VF3/ZHma63yY8RNrj4So 8GT5WXN/C1f8ldEPvsKtoilnOTtgXKwg+KfFddkg+Wzb0xLrI/+JBqB9YVukjW000d EACsCPQIxXfFYGi5GcCRVveIL/B62zc0tX4XdPFg= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-6209] lower-bitint: Fix arithmetics followed by extension by many bits [PR112809] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 895a70f012b8c1b8e80ecc584c1d7ded014bc2bc X-Git-Newrev: 0ca64f846edce3c7b7f26bcc5978118e560e65b1 Message-Id: <20231206085636.176353858D38@sourceware.org> Date: Wed, 6 Dec 2023 08:56:36 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0ca64f846edce3c7b7f26bcc5978118e560e65b1 commit r14-6209-g0ca64f846edce3c7b7f26bcc5978118e560e65b1 Author: Jakub Jelinek Date: Wed Dec 6 09:55:30 2023 +0100 lower-bitint: Fix arithmetics followed by extension by many bits [PR112809] A zero or sign extension from result of some upwards_2limb operation is implemented in lower_mergeable_stmt as an extra loop which fills in the extra bits with 0s or 1s. If the delta of extended vs. unextended bit count is small, the code doesn't use a loop and emits up to a couple of stores to constant indexes, but if the delta is large, it uses cnt = (bo_bit != 0) + 1 + (rem != 0); statements. bo_bit is non-zero for bit-field loads and is done in that case as straight line, the unconditional 1 in there is for a loop which handles most of the limbs in the delta and finally (rem != 0) is for the case when the extended precision is not a multiple of limb_prec and is again done in straight line code (after the loop). The testcase ICEs because the decision what idx to use was incorrect for kind == bitint_prec_huge (i.e. when the precision delta is very large) and rem == 0 (i.e. the extended precision is multiple of limb_prec). In that case cnt is either 1 (if bo_bit == 0) or 2, and idx should be either first size_int (start) and then result of create_loop (for bo_bit != 0) or just result of create_loop, but by mistake the last case was size_int (end), which means when precision is multiple of limb_prec storing above the precision (which ICEs; but also not emitting the loop which is needed). 2023-12-06 Jakub Jelinek PR tree-optimization/112809 * gimple-lower-bitint.cc (bitint_large_huge::lower_mergeable_stmt): For separate_ext in kind == bitint_prec_huge mode if rem == 0, create for i == cnt - 1 the loop rather than using size_int (end). * gcc.dg/bitint-48.c: New test. Diff: --- gcc/gimple-lower-bitint.cc | 2 +- gcc/testsuite/gcc.dg/bitint-48.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc index 575883a072d..d2026f6c905 100644 --- a/gcc/gimple-lower-bitint.cc +++ b/gcc/gimple-lower-bitint.cc @@ -2624,7 +2624,7 @@ bitint_large_huge::lower_mergeable_stmt (gimple *stmt, tree_code &cmp_code, { if (kind == bitint_prec_large || (i == 0 && bo_bit != 0)) idx = size_int (start + i); - else if (i == cnt - 1) + else if (i == cnt - 1 && (rem != 0)) idx = size_int (end); else if (i == (bo_bit != 0)) idx = create_loop (size_int (start + i), &idx_next); diff --git a/gcc/testsuite/gcc.dg/bitint-48.c b/gcc/testsuite/gcc.dg/bitint-48.c new file mode 100644 index 00000000000..8701ebb9b6e --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-48.c @@ -0,0 +1,23 @@ +/* PR tree-optimization/112809 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2" } */ + +#if __BITINT_MAXWIDTH__ >= 512 +_BitInt (512) a; +_BitInt (256) b; +_BitInt (256) c; + +int +foo (void) +{ + return a == (b | c); +} + +void +bar (void) +{ + a /= b - 2; +} +#else +int i; +#endif