From patchwork Wed Oct 18 22:34:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 155201 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp34210vqb; Wed, 18 Oct 2023 15:35:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3oOj9Lx2EuFRep2+cIiMzuXnqyvGYBJ+sWnCODAI5fAqpo3PlTgUBeUhchgqaVSiTdP+/ X-Received: by 2002:a05:622a:14e:b0:419:5bf1:f627 with SMTP id v14-20020a05622a014e00b004195bf1f627mr735849qtw.37.1697668504172; Wed, 18 Oct 2023 15:35:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697668504; cv=pass; d=google.com; s=arc-20160816; b=n2ViKdlbZTWm1ScHEJ32DbrYBDRQkBFB5DlSC5eu9+p53AGMdyGH8mLxhAk6o9MthK dK+2GRRDC9gm9QBj99ViGgEpdAc4AQhyVb2LKEvwug4dx67aPWrKjQg7Fqv/RUOo77/N GYmAM1eSqPKjzn1OXYOJGgRtlVRAdPmPG/6A6lFkA7q7myLZVboCe0JeE/x+5P7w4VWp F1lLQhCgIIb3L0UbUHGuhMdCaAKQO9OBj2qfuiH0Re6xRfWSll2wKg7a7imKK8ygpajw Ujwo4fw/vDifkcRyfCUdU5dCrwij9MX9ft+EPkr9jHXxf+ungqP5hVI5QYNvYskMg29B ZYNA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=bfO1f2UrK3+EoJsz0MlpKjUgfbZ5DK2Cd+32QpWA+Vk=; fh=6xfd3IYC8Zt5CA4TsXZHhPmGMhO9cjo3oiHaQc5bSUI=; b=tohLfXXrjZbjAmkUiRPdUfTPAb/493UtPC3XSNZ6XvNtkM8JxBRFSAHx+6rTA8bElf jUUYdgAxqkZO6TQ7DdsjS3O/DwZXBQjR92EljjgmvFYZXYfQNUVIMrW5c1l6+isPfhmb aYfQBnQ/bw0LFTBiTsVvGWtYKpQ+VQYmceKKNEWicjxCZwS6K6AC+1d4hU3mHGSlgRnW mV5YPWCDoUzz+QgrYYQP4w9+z/6GCBMKsNzm3bY6r9IsGcp2gkvA5sZfXUHQXdikkPLE XbPNc/NBT38FEOORYQnjZIWCsJEWwDVKvsAFp56cZyrfbfUcmT3u293ZkYxPAxRRi9D2 5xTg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=F21bu2x3; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id h14-20020ac85e0e000000b004181abf57fbsi685663qtx.3.2023.10.18.15.35.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 15:35:04 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=F21bu2x3; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E8AA43858430 for ; Wed, 18 Oct 2023 22:35:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) by sourceware.org (Postfix) with ESMTPS id BF6403858D1E for ; Wed, 18 Oct 2023 22:34:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF6403858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BF6403858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c31 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697668479; cv=none; b=OVd0AkTR61V1joMjEWxsD7t5+jnNEcqVqF4QWjQt40olyQku9gEo6E0CuY7Ex9W6MJUAxUol146+/cgYCkJS1xRtbXsvOh2Ja1vNBwGo81+zXn7A6zF0Ku2wR4IOjrghZpA8bL9zFfeuxRzpNpNjcQaRTe9EgcRI6AfXfi6nNms= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697668479; c=relaxed/simple; bh=Rk8tuqd/rEoSWGpiEOzU/ZH8bOkiLlbOnxXQg0hSULE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=E3JFyqAnnkCmScrcuNnGHwSPPDpwFb0zu/vbedWq4GRokBdhuv23a2a8Xz5yzoibXSUWdC8DG4ZJy8Y4Ej44/1NGHdzMZtR3kbagjZ2yde2iKwjEaEuTqKfs7pjxU9IL8rgJaeyRum3QDNotRjxd3JU2/7enODpghsUGJeWSIYY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-581fb6f53fcso569997eaf.2 for ; Wed, 18 Oct 2023 15:34:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697668476; x=1698273276; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=bfO1f2UrK3+EoJsz0MlpKjUgfbZ5DK2Cd+32QpWA+Vk=; b=F21bu2x3EimqX0js5LyfJUXLDAzgQNrnHWiwPMd84tpoUEyD8jbOdzpHqu6DsDwebb cyESBceKQAWe5hpEOMhDfs//Ap2jBsmrf2/W16f8d2VWseZm3tMT7xpbKLiU1SMHS8Xv MawS1DHQYNe99ED/wPrY17IcHvhzzlarClvqDAOo+mja2BYlIUjT1przYygtVfXWVVdm ga3y36n4BE78fDKncrPtqIyRK8531DLXyACEwAS5Ex4fOJTvxTKs+IH10d8T8qJXmSON aP1rDkQ04SwkwQ8dC7bqipzMIH9Gu5btG31Q3ZxoBw4mEbOsdNGFRxbvkFHOsN9xl12W HWkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697668476; x=1698273276; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bfO1f2UrK3+EoJsz0MlpKjUgfbZ5DK2Cd+32QpWA+Vk=; b=vrW6vRe4qAL+VLA0YIcIR61g8O5Vl7m6Ai6hb/KHzRF8kWe1UGzPIE2TcBW1bqbUYu Dh3pWgxfypp+UqO+6qavt1f+GMxbVDEty5GtDww1xUqxwoPLwYcnxjDD6TgjYkuCh9RK LOpZAi0wieaT1DZG1624Csa9iGqh8pZwyAC7kkMiD9amMXyXcY4l3IDmr2vB4Ii+bUfT V00pROqV09RND6DJ7mmSP8wsKbR1uEl3lx5Kz+RMSaxvqDxdGzI0peMdiseTBMaw+Utd y9aqTxg9JNsas3esBQMvtypNbaL9wAYMWumTJfRDGZVi6QrmmG8gvup3yM99Cz4Bx16J URwA== X-Gm-Message-State: AOJu0YwDF8akgxkzWZGdD5R+D9gBK9X3y3niQC6U04ICFgpa3OjfXUHN p5/MCdBXisZkzXsEjaa4O73L/nfAi4dr+Q== X-Received: by 2002:a05:6359:3110:b0:13f:411:c1a9 with SMTP id rh16-20020a056359311000b0013f0411c1a9mr325075rwb.17.1697668476513; Wed, 18 Oct 2023 15:34:36 -0700 (PDT) Received: from xeond2.wrightpinski.org ([98.97.114.173]) by smtp.gmail.com with ESMTPSA id x26-20020aa79ada000000b0069309cbc220sm3826131pfp.121.2023.10.18.15.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 15:34:35 -0700 (PDT) From: Andrew Pinski To: gcc-patches@gcc.gnu.org Cc: Andrew Pinski Subject: [COMMITTED] Fix expansion of `(a & 2) != 1` Date: Wed, 18 Oct 2023 15:34:32 -0700 Message-Id: <20231018223432.2519596-1-pinskia@gmail.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780134449495185639 X-GMAIL-MSGID: 1780134449495185639 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. --- gcc/expr.cc | 9 +++++---- gcc/testsuite/gcc.c-torture/execute/pr111863-1.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr111863-1.c diff --git a/gcc/expr.cc b/gcc/expr.cc index 8aed3fc6cbe..763bd82c59f 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 00000000000..4e27fe631b2 --- /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; +}