From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id E3C493858434; Wed, 18 Oct 2023 22:35:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E3C493858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697668514; bh=1O9gmuO5U6Olwwf/SRPRnogObsZDqCAxP7ZDL3h4KxQ=; h=From:To:Subject:Date:From; b=MU2ZH2DZg20A2j0f38QfeaENAdHI6St+gqeH2ICfawoGlD7H2DVj6aXrSgw1vE/YH d4W8/VXkXCknMnfknkgTr8W7GiKrnF92QFnsI8kBb7q5065EQX7uhBnvLb07D0Spis 1VtEopLjK5nHCqNkJWxWvxL3RdPMQ4pFVhGTII1c= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4729] Fix expansion of `(a & 2) != 1` X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 879c91fcccf93681bd7e13290bfbb384cadcd268 X-Git-Newrev: b20dbddcc41120144e700c4e3ef1ec396b1c56ab Message-Id: <20231018223514.E3C493858434@sourceware.org> Date: Wed, 18 Oct 2023 22:35:14 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b20dbddcc41120144e700c4e3ef1ec396b1c56ab commit r14-4729-gb20dbddcc41120144e700c4e3ef1ec396b1c56ab Author: Andrew Pinski Date: Wed Oct 18 10:26:07 2023 -0700 Fix expansion of `(a & 2) != 1` I had a thinko in r14-1600-ge60593f3881c72a96a3fa4844d73e8a2cd14f670 where we would remove the `& CST` part if we ended up not calling expand_single_bit_test. This fixes the problem by introducing a new variable that will be used for calling expand_single_bit_test. As afar as I know this can only show up when disabling optimization passes as this above form would have been optimized away. Committed as obvious after a bootstrap/test on x86_64-linux-gnu. PR middle-end/111863 gcc/ChangeLog: * expr.cc (do_store_flag): Don't over write arg0 when stripping off `& POW2`. gcc/testsuite/ChangeLog: * gcc.c-torture/execute/pr111863-1.c: New test. Diff: --- gcc/expr.cc | 9 +++++---- gcc/testsuite/gcc.c-torture/execute/pr111863-1.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/gcc/expr.cc b/gcc/expr.cc index 8aed3fc6cbe9..763bd82c59f2 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -13206,14 +13206,15 @@ do_store_flag (sepops ops, rtx target, machine_mode mode) || integer_pow2p (arg1)) && (TYPE_PRECISION (ops->type) != 1 || TYPE_UNSIGNED (ops->type))) { - wide_int nz = tree_nonzero_bits (arg0); - gimple *srcstmt = get_def_for_expr (arg0, BIT_AND_EXPR); + tree narg0 = arg0; + wide_int nz = tree_nonzero_bits (narg0); + gimple *srcstmt = get_def_for_expr (narg0, BIT_AND_EXPR); /* If the defining statement was (x & POW2), then use that instead of the non-zero bits. */ if (srcstmt && integer_pow2p (gimple_assign_rhs2 (srcstmt))) { nz = wi::to_wide (gimple_assign_rhs2 (srcstmt)); - arg0 = gimple_assign_rhs1 (srcstmt); + narg0 = gimple_assign_rhs1 (srcstmt); } if (wi::popcount (nz) == 1 @@ -13227,7 +13228,7 @@ do_store_flag (sepops ops, rtx target, machine_mode mode) type = lang_hooks.types.type_for_mode (mode, unsignedp); return expand_single_bit_test (loc, tcode, - arg0, + narg0, bitnum, type, target, mode); } } diff --git a/gcc/testsuite/gcc.c-torture/execute/pr111863-1.c b/gcc/testsuite/gcc.c-torture/execute/pr111863-1.c new file mode 100644 index 000000000000..4e27fe631b21 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr111863-1.c @@ -0,0 +1,16 @@ +/* { dg-options " -fno-tree-ccp -fno-tree-dominator-opts -fno-tree-vrp" } */ + +__attribute__((noipa)) +int f(int a) +{ + a &= 2; + return a != 1; +} +int main(void) +{ + int t = f(1); + if (!t) + __builtin_abort(); + __builtin_printf("%d\n",t); + return 0; +}