From patchwork Tue Nov 7 06:05:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 162276 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp41101vqo; Mon, 6 Nov 2023 22:08:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZAGVA4le3pWMpcZ59p+aen80pB4M9iFUZL0g5ZtwWvtqgtLtmm6AUbNxIM2+2m0Hk7/lx X-Received: by 2002:a05:6214:2dc5:b0:675:a120:7a2d with SMTP id nc5-20020a0562142dc500b00675a1207a2dmr3379545qvb.2.1699337289845; Mon, 06 Nov 2023 22:08:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699337289; cv=pass; d=google.com; s=arc-20160816; b=QYHR0xAonr72+KHSPvaYVskOAsy4uJCFIfKtUZeOFlf7R6c7F3Wc9qj+AucI/1BIik PHF/UkJX0PN1tOEIp1QMNxdU/b0WTfJiIYd+D51XJz3Zs/ed/r5r4pwljgQnOP94olCM v6Pl5IYhEFCukoMEOZY5MMWg6dldWlLZ3JhsfzVnCfP8eovIyVZ6c7S0gVcJo7zW6KNo R5gpDTlYEWz+1Ix59wCIkddbVQcMQw+y6Oga3X5OcgnbZiMDsRMmNjjvEzvXlTZuwc2P K/o5f2vDvfnvAFd5izdohjquTGX1Dy9gATqPFEnV5SFUpNu++Pf4B8JpDC0e1MtHY7YS iTog== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=90X1DE7vJ4YvCzPIq8Nz2Qv0xyl1tjZzlOhS1/U8Wy8=; fh=ChXOctppJn0KECDRINafwUY5xHRufGHaa0Ju9pddrcQ=; b=t1/ZBVwGwgLDCsZZhBR4vH1l1Tmj+F1ZF5asoDDXPQFMdXkwUWBfvNKMVzp7agVdJ1 q5AG3yw3RJYtsv20QXs/djWCMDXPqcBAZCuAAPrmYISCCO1io1uxvAaAQxC3gZC1zH1y 1sdGc+kjvVI9QrVZkvhPSJCaiTgB0MC1qEPmsJw9F+qdKp5YUTa/hhhTODGP2DIAEVof n6BofRbIVEvlG9itcFHiszcCzFrTybti3FO9zn9tTedBnIkHN1hpxGGGqWc78B61rJS0 j87rh8cADO/c//oze3ucmQXuHeVZcVVbRrQwsO22RUiu1Z828gt+cqNfZ4806scOeWiH wR4Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BVp+AEao; 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=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e18-20020a0cf752000000b0065af2518773si6699349qvo.89.2023.11.06.22.08.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 22:08:09 -0800 (PST) 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=@intel.com header.s=Intel header.b=BVp+AEao; 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=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9ADEE3858D1E for ; Tue, 7 Nov 2023 06:08:09 +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 9C7D53858D1E for ; Tue, 7 Nov 2023 06:07:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C7D53858D1E 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 9C7D53858D1E 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=1699337266; cv=none; b=GyWL3+OiuTT44rRKFA65rxiMV1/1kAL49ge3jNHeIowr3u3dV1ciByQwk06MiGY54neFg4BxhDQADKT3hIMTlERfBlY0h6ivARmDfL4MB8Tbz5prpZS4kPP76/Hor+vS0HHil3SE/ZefycI8vqZsBsoetTPIRdFC5SXD0NpIS/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699337266; c=relaxed/simple; bh=EiO0Jw/NK5rwUaFiynhMZWQeA9TONioRXPZNonPKY1U=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Bb1FRVi3GeOS5NUzjgqkaR0Vuvv3j76jxvDkOD1PIWublpGj75pvY2XR00g2ld3lQPcHlleY/0bc01g/z/Q0Z7V0zKimraDldIPQQvWjtXerK4LIHYVpPJiRUNrTc7WvueujXBESZJIuW77kuk0wFUYVQzySUigCwWsxQOzONlg= 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=1699337262; x=1730873262; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EiO0Jw/NK5rwUaFiynhMZWQeA9TONioRXPZNonPKY1U=; b=BVp+AEaozw4WUew+zFTaj67K3MSBEFt3rk0Ne5TldY9TTjTBkbZ/wZqA fw9qoWcP+ooC52Owr9ZjsJ27eSahEOvJJ7hxoNqUAKmeQUkcliBquFOY8 kFuOI7gkLlUe3ugaj8lEz1YJKepIgAcOYDnMySC+NT1FAy4BF5vDYtRdZ m6ddxhHkYVdKNeOCHzDR/3cqcqFoMmQyFg+uCVMrMM8MreT9Lm08KdfQv e/JtsbJwkKy3nhXOigum/uzO5ALLYrTTt1YXEBhazr6+oDBv/wgRuBk7U 3KQVmg0iR7ydD6/mweTkBHWQk5TvqnA//pA+9v74jYm+a9oa1/hSieB/Q A==; X-IronPort-AV: E=McAfee;i="6600,9927,10886"; a="392311338" X-IronPort-AV: E=Sophos;i="6.03,282,1694761200"; d="scan'208";a="392311338" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2023 22:07:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10886"; a="1009775812" X-IronPort-AV: E=Sophos;i="6.03,282,1694761200"; d="scan'208";a="1009775812" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmsmga006.fm.intel.com with ESMTP; 06 Nov 2023 22:07:39 -0800 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 42A391005669; Tue, 7 Nov 2023 14:07:39 +0800 (CST) From: liuhongt To: gcc-patches@gcc.gnu.org Cc: crazylht@gmail.com, hjl.tools@gmail.com Subject: [V2 PATCH] Handle bitop with INTEGER_CST in analyze_and_compute_bitop_with_inv_effect. Date: Tue, 7 Nov 2023 14:05:39 +0800 Message-Id: <20231107060539.443303-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231030104145.169132-1-hongtao.liu@intel.com> References: <20231030104145.169132-1-hongtao.liu@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 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, T_SCC_BODY_TEXT_LINE 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: 1781884298409844157 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 regtseted 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 70b17c5bca1..f61277c32df 100644 --- a/gcc/tree-scalar-evolution.cc +++ b/gcc/tree-scalar-evolution.cc @@ -3689,6 +3689,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 (expr_invariant_in_loop_p (loop, match_op[1])) + 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])))