From patchwork Mon Oct 30 10:41:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 159684 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp2112528vqb; Mon, 30 Oct 2023 03:44:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHN0wbKAFxnf5GSmLXf1vKXaqMFFVZEWZX1Vs32VCXDna4z8gnoNtYCAY20oaLvrEx+S14w X-Received: by 2002:a0c:e188:0:b0:66d:298f:fae with SMTP id p8-20020a0ce188000000b0066d298f0faemr7399644qvl.49.1698662652646; Mon, 30 Oct 2023 03:44:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698662652; cv=pass; d=google.com; s=arc-20160816; b=eW08YQcpj7QCuHKxhkHqTo0lDDJt8w/mcPfKK+rGwdDeauQdP6Q7qqW9zhmXiPWTU4 i530JKlfBPTjXzuKC2WrocGxFDs6awgMa/C/7USYF1iy8ST3x3zXLWktyfUAAxAATsDV wHJYKhO+AZ+TBsANw3MRvlJIdarxDvxXSxm324v2R9Ig8R88eLAkmvv1J7wcVf/LIvLk 8w+ueVaak+4L0l58dz2YOE9AfP29gQtOoXoAr1PXnX4CcDSZBmJ6DSKTF0HVgYZlniy6 /2uOXu7vjvakvz3KokD5dYZTO7OknSShFfrbsNzYR1J5nj6a9pLI868/M6ozTQpouTIw DdKA== 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=/uoMhTNcIpXSaq9oP1CTKMw1jz0rQyXGicLdecCuIww=; fh=ChXOctppJn0KECDRINafwUY5xHRufGHaa0Ju9pddrcQ=; b=TwLqG+20Fw2bp7koQuP+DbOFFnLGDx/yNJLTRl/B7gjJ5/6j1eGRdghJNhQOASjc9g VjGuwbaHKiwx/w9nX6aW8tFp9U/JEdxtxrsItZFT7RvUOv0pLWaWBmRoxVrjuhfhFaXm 4DNHWCvRNYdBGlOPy9BORT2XYHNvm4DsJoN+uHUcGQUdR2YDgd5vTNCBUqOuu4PXAfnH 30KrmrOOb15OMBQqDPO82hTaeH+bENI97+UsNpl7m/NHj3yDOe5arFPmMJEnDPn5DtS6 d79Gvtx0BPhpEwz+b7pcVt1NMNFdd8HRJ9wVqLXovJxABjupc3XZE6skEVKywEtDHBhX ilCw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="HATRLX/g"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id bt5-20020ad455c5000000b0066d1b4ce85bsi5468858qvb.532.2023.10.30.03.44.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 03:44:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="HATRLX/g"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6BEA13858434 for ; Mon, 30 Oct 2023 10:44:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by sourceware.org (Postfix) with ESMTPS id C2C6A3858D20 for ; Mon, 30 Oct 2023 10:43:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C2C6A3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C2C6A3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=134.134.136.24 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698662630; cv=none; b=M/JuoTv7UvMz5em7jxV6eYE3/k4pCUNEPM8fTPb/0jBwFJf5d4QBaTSJkPVeSVdTBa1IAlBO+jvvY/Lc0zNCZugPVqlTnk8/7mxmz25korN/ZKDCYRh29nyQyn/fHdq3Bs1WiAWXXPagYSN7nf5IlOrkpeHx05fjGEKX91uGc4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698662630; c=relaxed/simple; bh=szQCWeA2C6xvNBd8Hvh9j0plBCfiMwj/l7fx+790zEc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=voMDUgMbopQAWXj9y76JxoTvmjL+q1rYIURrYbKbgvDAvWykEwS9JWxVdcg2MgsrGnikZ/Q00N/CbQV2453VDcFejLz+W+Ha0HfPVZLdrXGGAdoB8WXGVMEYHBfsKj3FoZt41VExdpa7dAZQPvc6nSbMa4Oa+pIp6Q3iL/q3ejI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698662628; x=1730198628; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=szQCWeA2C6xvNBd8Hvh9j0plBCfiMwj/l7fx+790zEc=; b=HATRLX/gaRcy+HPTewQJDgBm9NrPl9GVZnse/b6bEGoqbuepnYkjDrP6 bvnNCxIgss0VVIp2oy+pxk+fTGUjdeynOpKoTQlj6mcDFVBxMuounGzie 8CNs8mihlihiBdvN2/zwDG8Rl/ya8gPhTzN0Rz1Vw19/9l5883h2y2WrW St0fF8v8aAs5eNcc8ZYFgYYMmBU3KdvurF0S4ONGaFOVy6joBNWSNjXcs xx2DhkI1Hr7zfWmNMErpVj22vhwtyV1UWE1G8x+tPZv44W0Utnhm3bV3L f0e1caDQ0pDEMP9VbF1xVki9ce7oxATxZhN3hVqjcHba5K20VeIYiG0lg A==; X-IronPort-AV: E=McAfee;i="6600,9927,10878"; a="390906551" X-IronPort-AV: E=Sophos;i="6.03,263,1694761200"; d="scan'208";a="390906551" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2023 03:43:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10878"; a="933742051" X-IronPort-AV: E=Sophos;i="6.03,263,1694761200"; d="scan'208";a="933742051" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by orsmga005.jf.intel.com with ESMTP; 30 Oct 2023 03:43:46 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 785B71005673; Mon, 30 Oct 2023 18:43:45 +0800 (CST) From: liuhongt To: gcc-patches@gcc.gnu.org Cc: crazylht@gmail.com, hjl.tools@gmail.com Subject: [PATCH] Handle bitop with INTEGER_CST in analyze_and_compute_bitop_with_inv_effect. Date: Mon, 30 Oct 2023 18:41:45 +0800 Message-Id: <20231030104145.169132-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: 1781176889862382800 X-GMAIL-MSGID: 1781176889862382800 analyze_and_compute_bitop_with_inv_effect assumes the first operand is loop invariant which is not the case when it's INTEGER_CST. Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,} Ok for trunk? gcc/ChangeLog: PR tree-optimization/105735 PR tree-optimization/111972 * tree-scalar-evolution.cc (analyze_and_compute_bitop_with_inv_effect): Handle bitop with INTEGER_CST. gcc/testsuite/ChangeLog: * gcc.target/i386/pr105735-3.c: New test. --- gcc/testsuite/gcc.target/i386/pr105735-3.c | 87 ++++++++++++++++++++++ gcc/tree-scalar-evolution.cc | 3 + 2 files changed, 90 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/pr105735-3.c diff --git a/gcc/testsuite/gcc.target/i386/pr105735-3.c b/gcc/testsuite/gcc.target/i386/pr105735-3.c new file mode 100644 index 00000000000..9e268a1a997 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr105735-3.c @@ -0,0 +1,87 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-sccp-details" } */ +/* { dg-final { scan-tree-dump-times {final value replacement} 8 "sccp" } } */ + +unsigned int +__attribute__((noipa)) +foo (unsigned int tmp) +{ + for (int bit = 0; bit < 64; bit++) + tmp &= 11304; + return tmp; +} + +unsigned int +__attribute__((noipa)) +foo1 (unsigned int tmp) +{ + for (int bit = 63; bit >= 0; bit -=3) + tmp &= 11304; + return tmp; +} + +unsigned int +__attribute__((noipa)) +foo2 (unsigned int tmp) +{ + for (int bit = 0; bit < 64; bit++) + tmp |= 11304; + return tmp; +} + +unsigned int +__attribute__((noipa)) +foo3 (unsigned int tmp) +{ + for (int bit = 63; bit >= 0; bit -=3) + tmp |= 11304; + return tmp; +} + +unsigned int +__attribute__((noipa)) +foo4 (unsigned int tmp) +{ + for (int bit = 0; bit < 64; bit++) + tmp ^= 11304; + return tmp; +} + +unsigned int +__attribute__((noipa)) +foo5 (unsigned int tmp) +{ + for (int bit = 0; bit < 63; bit++) + tmp ^= 11304; + return tmp; +} + +unsigned int +__attribute__((noipa)) +f (unsigned int tmp, int bit) +{ + unsigned int res = tmp; + for (int i = 0; i < bit; i++) + res &= 11304; + return res; +} + +unsigned int +__attribute__((noipa)) +f1 (unsigned int tmp, int bit) +{ + unsigned int res = tmp; + for (int i = 0; i < bit; i++) + res |= 11304; + return res; +} + +unsigned int +__attribute__((noipa)) +f2 (unsigned int tmp, int bit) +{ + unsigned int res = tmp; + for (int i = 0; i < bit; i++) + res ^= 11304; + return res; +} diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc index 95a15fe0988..33c7711f7e3 100644 --- a/gcc/tree-scalar-evolution.cc +++ b/gcc/tree-scalar-evolution.cc @@ -3681,6 +3681,9 @@ analyze_and_compute_bitop_with_inv_effect (class loop* loop, tree phidef, match_op[0] = gimple_assign_rhs1 (def); match_op[1] = gimple_assign_rhs2 (def); + if (TREE_CODE (match_op[1]) == INTEGER_CST) + std::swap (match_op[0], match_op[1]); + if (TREE_CODE (match_op[1]) != SSA_NAME || !expr_invariant_in_loop_p (loop, match_op[0]) || !(header_phi = dyn_cast (SSA_NAME_DEF_STMT (match_op[1])))