From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id B614A3858438; Fri, 23 Feb 2024 10:39:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B614A3858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708684749; bh=wKKWq+wwyAMk15psbfMpVMgZzobkqn3+jVxqvrWKbHQ=; h=From:To:Subject:Date:From; b=g/n0VSLCOBJm4HnJHx9hNdwSrd8QzekaCuACmK1FsWd0iiIxp0kpVF4wXjHrGWxHl 5yYq/YVI+cvw/iso4X1V1H3+ASXa/2NIoPLZfsEJEfenKmrLzKWTv9W5tetLuTKEyJ M/4wZeSg5ZlvdLXseKTLiWBN+mDmzRWHFbVT+WJ8= 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-9151] expr: Fix REDUCE_BIT_FIELD in multiplication expansion [PR114054] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: be1f2bc4522f772184a4d16d8f3fec75baed89cf X-Git-Newrev: 22121546e0315d25ee419d2389022e3974750885 Message-Id: <20240223103909.B614A3858438@sourceware.org> Date: Fri, 23 Feb 2024 10:39:09 +0000 (GMT) List-Id: https://gcc.gnu.org/g:22121546e0315d25ee419d2389022e3974750885 commit r14-9151-g22121546e0315d25ee419d2389022e3974750885 Author: Jakub Jelinek Date: Fri Feb 23 11:38:18 2024 +0100 expr: Fix REDUCE_BIT_FIELD in multiplication expansion [PR114054] The following testcase ICEs, because the REDUCE_BIT_FIELD macro uses the target variable implicitly: #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \ ? reduce_to_bit_field_precision ((expr), \ target, \ type) \ : (expr)) and so when the code below reuses the target variable, documented to be The value may be stored in TARGET if TARGET is nonzero. TARGET is just a suggestion; callers must assume that the rtx returned may not be the same as TARGET. for something unrelated (the value that should be returned), this misbehaves (in the testcase target is set to a CONST_INT, which has VOIDmode and reduce_to_bit_field_precision assert checking doesn't like that). Needed to say that If TARGET is CONST0_RTX, it means that the value will be ignored. but in expand_expr_real_2 does at the start: ignore = (target == const0_rtx || ((CONVERT_EXPR_CODE_P (code) || code == COND_EXPR || code == VIEW_CONVERT_EXPR) && TREE_CODE (type) == VOID_TYPE)); /* We should be called only if we need the result. */ gcc_assert (!ignore); - so such target is mainly meant for calls and the like in other routines. Certainly doesn't expect that target changes from not being ignored initially to ignore later on and other CONST_INT results as well as anything which is not an object into which anything can be stored. So, the following patch fixes that by using a more appripriate temporary for the result, which other code is using. 2024-02-23 Jakub Jelinek PR rtl-optimization/114054 * expr.cc (expand_expr_real_2) : Use temp variable instead of target parameter for result. * gcc.dg/bitint-92.c: New test. Diff: --- gcc/expr.cc | 12 ++++++------ gcc/testsuite/gcc.dg/bitint-92.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/gcc/expr.cc b/gcc/expr.cc index e238811110e4..8d34d024c9c1 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -10259,12 +10259,12 @@ expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode, &algorithm, &variant, cost) : cost < mul_cost (speed, mode)) { - target = bit0_p ? expand_and (mode, negate_rtx (mode, op0), - op1, target) - : expand_and (mode, op0, - negate_rtx (mode, op1), - target); - return REDUCE_BIT_FIELD (target); + temp = bit0_p ? expand_and (mode, negate_rtx (mode, op0), + op1, target) + : expand_and (mode, op0, + negate_rtx (mode, op1), + target); + return REDUCE_BIT_FIELD (temp); } } } diff --git a/gcc/testsuite/gcc.dg/bitint-92.c b/gcc/testsuite/gcc.dg/bitint-92.c new file mode 100644 index 000000000000..c567d63f007e --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-92.c @@ -0,0 +1,17 @@ +/* PR rtl-optimization/114054 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-Og -fwhole-program -fno-tree-ccp -fprofile-use -fno-tree-copy-prop -w" } */ + +int x; + +void +foo (int i, unsigned u) +{ + x = __builtin_mul_overflow_p ((unsigned _BitInt(1)) u, i, (_BitInt(33)) 0); +} + +int +main () +{ + foo (11, 0); +}