From patchwork Fri Jul 19 03:32:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1962279 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=UMGDnRLg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WQFck1HbSz1ySl for ; Fri, 19 Jul 2024 13:33:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E040385842C for ; Fri, 19 Jul 2024 03:33:08 +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 [192.198.163.7]) by sourceware.org (Postfix) with ESMTPS id CFD043858CDA for ; Fri, 19 Jul 2024 03:32:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CFD043858CDA 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 CFD043858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.7 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721359970; cv=none; b=xPksKaDXk0GBX7xX5iz9S8P7Dc+aMf+lqH30EoJXY/6Q7CnJSOVaAp7tQ77U4qKu7dUzej6ZYTxNi6e63L5mXUP3WdpiOBmKRO1KQHBCYFQ5trLkh3hyXGho8uSMDlXa3UG+TkabAR+PElS0yacfBpmgDoKsep/RiCp+CdtaT3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721359970; c=relaxed/simple; bh=Es0KIOIlx7rHtq/lQNCHQQlp66PZ826QxPCwU97qGQM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=qh+FY+0OGwzw90tth1f7qIdmA836A0EgJCGeKhszvUaoHgwuzyOuSCnCiZYt9XYFdH5fcxxgPV1PtL75dy/LGPENL3AjMWc73vWEBECQXoh33EJTKnj8JH1ZopZVYhFqlH3swTq3No8m/4m8ATt6oYINbHz73Z6RCqUVCG/9TbA= 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=1721359968; x=1752895968; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Es0KIOIlx7rHtq/lQNCHQQlp66PZ826QxPCwU97qGQM=; b=UMGDnRLgTbhX0aCkqeHwQh0cTDF4t9D69gYSwpbA7MI4Md/8Jd76RvUJ d6GURWye8g1XHL4vYWwAf4IKgYvbFOedhDNyl4RvRZ9eF6P8Le/NmVl9h 0zJO5Jzuf6rPoU2GcNDj0IApwZ8H25eyWbb3j4AYWkxzLIiHaYY/2caP3 1WsmHmhaQN338nIENe43ABiepaaMW0Btv06yBuiJt94T9ynEXN7GiVEMv qYCJg7tpengRtgw4k0wECnhsGWgVLJgv3zcv6oVYC6+YAzYRu5zJyEE2n 5/mM8/2z9M+/Zse1+MrkVkd/VzflU26dSzYwfr53aVyrIj5zRUThCiq2B w==; X-CSE-ConnectionGUID: mfUOy29uTZOGg6LSZoJy5A== X-CSE-MsgGUID: k52o7BjuQA6Dxhr4MMu3nQ== X-IronPort-AV: E=McAfee;i="6700,10204,11137"; a="44381657" X-IronPort-AV: E=Sophos;i="6.09,219,1716274800"; d="scan'208";a="44381657" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2024 20:32:47 -0700 X-CSE-ConnectionGUID: suuoRDUqSxGJiBmhg0mndQ== X-CSE-MsgGUID: Dfy/PLxoTKKwRb/ZMI6Ksg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,219,1716274800"; d="scan'208";a="55829758" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by orviesa005.jf.intel.com with ESMTP; 18 Jul 2024 20:32:44 -0700 Received: from pli-ubuntu.sh.intel.com (pli-ubuntu.sh.intel.com [10.239.159.47]) by shvmail02.sh.intel.com (Postfix) with ESMTP id 4689510071C5; Fri, 19 Jul 2024 11:32:43 +0800 (CST) From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, kito.cheng@gmail.com, richard.guenther@gmail.com, tamar.christina@arm.com, jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, richard.sandiford@arm.com, Pan Li Subject: [PATCH v1] Internal-fn: Only allow modes describe types for internal fn[PR115961] Date: Fri, 19 Jul 2024 11:32:41 +0800 Message-Id: <20240719033241.2255739-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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~incoming=patchwork.ozlabs.org@gcc.gnu.org From: Pan Li The direct_internal_fn_supported_p has no restrictions for the type modes. For example the bitfield like below will be recog as .SAT_TRUNC. struct e { unsigned pre : 12; unsigned a : 4; }; __attribute__((noipa)) void bug (e * v, unsigned def, unsigned use) { e & defE = *v; defE.a = min_u (use + 1, 0xf); } This patch would like to add checks for the direct_internal_fn_supported_p, and only allows the tree types describled by modes. The below test suites are passed for this patch: 1. The rv64gcv fully regression tests. 2. The x86 bootstrap tests. 3. The x86 fully regression tests. PR target/115961 gcc/ChangeLog: * internal-fn.cc (mode_describle_type_precision_p): Add new func impl to check if mode describle the tree type. (direct_internal_fn_supported_p): Add above check for the first and second tree type of tree pair. gcc/testsuite/ChangeLog: * g++.target/i386/pr115961-run-1.C: New test. * g++.target/riscv/rvv/base/pr115961-run-1.C: New test. Signed-off-by: Pan Li --- gcc/internal-fn.cc | 21 ++++++++++++ .../g++.target/i386/pr115961-run-1.C | 34 +++++++++++++++++++ .../riscv/rvv/base/pr115961-run-1.C | 34 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 gcc/testsuite/g++.target/i386/pr115961-run-1.C create mode 100644 gcc/testsuite/g++.target/riscv/rvv/base/pr115961-run-1.C diff --git a/gcc/internal-fn.cc b/gcc/internal-fn.cc index 95946bfd683..4dc69264a24 100644 --- a/gcc/internal-fn.cc +++ b/gcc/internal-fn.cc @@ -4164,6 +4164,23 @@ direct_internal_fn_optab (internal_fn fn) gcc_unreachable (); } +/* Return true if the mode describes the precision of tree type, or false. */ + +static bool +mode_describle_type_precision_p (const_tree type) +{ + if (VECTOR_TYPE_P (type)) + return VECTOR_MODE_P (TYPE_MODE (type)); + + if (INTEGRAL_TYPE_P (type)) + return type_has_mode_precision_p (type); + + if (SCALAR_FLOAT_TYPE_P (type) || COMPLEX_FLOAT_TYPE_P (type)) + return true; + + return false; +} + /* Return true if FN is supported for the types in TYPES when the optimization type is OPT_TYPE. The types are those associated with the "type0" and "type1" fields of FN's direct_internal_fn_info @@ -4173,6 +4190,10 @@ bool direct_internal_fn_supported_p (internal_fn fn, tree_pair types, optimization_type opt_type) { + if (!mode_describle_type_precision_p (types.first) + || !mode_describle_type_precision_p (types.second)) + return false; + switch (fn) { #define DEF_INTERNAL_FN(CODE, FLAGS, FNSPEC) \ diff --git a/gcc/testsuite/g++.target/i386/pr115961-run-1.C b/gcc/testsuite/g++.target/i386/pr115961-run-1.C new file mode 100644 index 00000000000..b8c8aef3b17 --- /dev/null +++ b/gcc/testsuite/g++.target/i386/pr115961-run-1.C @@ -0,0 +1,34 @@ +/* PR target/115961 */ +/* { dg-do run } */ +/* { dg-options "-O3 -fdump-rtl-expand-details" } */ + +struct e +{ + unsigned pre : 12; + unsigned a : 4; +}; + +static unsigned min_u (unsigned a, unsigned b) +{ + return (b < a) ? b : a; +} + +__attribute__((noipa)) +void bug (e * v, unsigned def, unsigned use) { + e & defE = *v; + defE.a = min_u (use + 1, 0xf); +} + +__attribute__((noipa, optimize(0))) +int main(void) +{ + e v = { 0xded, 3 }; + + bug(&v, 32, 33); + + if (v.a != 0xf) + __builtin_abort (); + + return 0; +} +/* { dg-final { scan-rtl-dump-not ".SAT_TRUNC " "expand" } } */ diff --git a/gcc/testsuite/g++.target/riscv/rvv/base/pr115961-run-1.C b/gcc/testsuite/g++.target/riscv/rvv/base/pr115961-run-1.C new file mode 100644 index 00000000000..b8c8aef3b17 --- /dev/null +++ b/gcc/testsuite/g++.target/riscv/rvv/base/pr115961-run-1.C @@ -0,0 +1,34 @@ +/* PR target/115961 */ +/* { dg-do run } */ +/* { dg-options "-O3 -fdump-rtl-expand-details" } */ + +struct e +{ + unsigned pre : 12; + unsigned a : 4; +}; + +static unsigned min_u (unsigned a, unsigned b) +{ + return (b < a) ? b : a; +} + +__attribute__((noipa)) +void bug (e * v, unsigned def, unsigned use) { + e & defE = *v; + defE.a = min_u (use + 1, 0xf); +} + +__attribute__((noipa, optimize(0))) +int main(void) +{ + e v = { 0xded, 3 }; + + bug(&v, 32, 33); + + if (v.a != 0xf) + __builtin_abort (); + + return 0; +} +/* { dg-final { scan-rtl-dump-not ".SAT_TRUNC " "expand" } } */