From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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]))) -- 2.31.1