From patchwork Wed Jul 17 09:48:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1961496 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=aTxg9++D; 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 4WPB3b5VB4z1xqc for ; Wed, 17 Jul 2024 19:49:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB6F7384A457 for ; Wed, 17 Jul 2024 09:49:13 +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.15]) by sourceware.org (Postfix) with ESMTPS id 0F5903860769 for ; Wed, 17 Jul 2024 09:48:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F5903860769 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 0F5903860769 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721209728; cv=none; b=QuZx0h7U4TxzJnWhkacH+9BK2uhPTGJ/37p0tcgvCMm+ix2YPX8LqTfNnOYW3LfhX4ACPxnEe1bK76tgZTWFeWSb3+Fpm2E5Bu+RdbKxQPgIZ5vzu+MMi6QwIwM+AaGgkJV/uPooMDQIqo49nllBbnvdE7cnEnQGhrv/o8puwGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721209728; c=relaxed/simple; bh=xpHmOg6/nx9wtLDwCyWptpyJ8b1SDc9UZIC0BeMczIw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=BFRc2wDdxW3GNG/efq21egNzyEMkO/K+53SPsBsEUz44tFiR0MIHM1cVL0WKzNO7sGA3ioS/Hu+4uVMQzt12lZD+zi0VLSSs3G2oLEgzjvhyWaZ1bTh7m82Ib8Ytjtp/FFZdMnAA/7R2igBv2+M/xRtpXiaLxJXg4ZZ9t/VvQYE= 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=1721209718; x=1752745718; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=xpHmOg6/nx9wtLDwCyWptpyJ8b1SDc9UZIC0BeMczIw=; b=aTxg9++DWvaVL5n/+Pru//H/xddxBErgG883FkUY/tl/CJY9G09lurpY E79Q1rYNMoSHn607H1B1DqwPZC34GGMDbuLuyOU6aXbH8HJ8S383q5RA0 TvRg79VcAVqCcwlNEh/KzLvb5YmcNRMekBRg/fc0S9cxVi29qthF2nk4c yR0T1Ig02jSHoTJesJOFIkRr7APs2WASx8/6b2KJ8EKBK4SrPInv/Bywy us7laCPDM+TXJt0FMjg8oj5wQyTTxQkkGBhte12DsbM2qUWC61h+DWnpB dHvvby/eIu5Sw6bphvaD5inY5n9rxCaz4VeqpSQHOrOm1qsBwt2enga79 A==; X-CSE-ConnectionGUID: jnzZzZ/zS+GBFmoFBKntqA== X-CSE-MsgGUID: vChccRKFRFq2oMf8mnbdiA== X-IronPort-AV: E=McAfee;i="6700,10204,11135"; a="18839088" X-IronPort-AV: E=Sophos;i="6.09,214,1716274800"; d="scan'208";a="18839088" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2024 02:48:37 -0700 X-CSE-ConnectionGUID: E1ATbf4aSBKGroxgkrXapw== X-CSE-MsgGUID: YBDnsVhyS4KAtGmz/HQN/Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,214,1716274800"; d="scan'208";a="50274915" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by fmviesa009.fm.intel.com with ESMTP; 17 Jul 2024 02:48:34 -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 1B5CE10054C5; Wed, 17 Jul 2024 17:48:33 +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, hongtao.liu@intel.com, Pan Li Subject: [PATCH v1] Match: Bugfix .SAT_TRUNC honor types has no mode precision [PR115961] Date: Wed, 17 Jul 2024 17:48:26 +0800 Message-Id: <20240717094826.394649-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 .SAT_TRUNC matching doesn't check the type has mode precision. Thus when 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 type_has_mode_precision_p for the .SAT_TRUNC matching to get rid of this. 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: * match.pd: Add type_has_mode_precision_p check for .SAT_TRUNC. 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/match.pd | 4 +-- .../g++.target/i386/pr115961-run-1.C | 34 +++++++++++++++++++ .../riscv/rvv/base/pr115961-run-1.C | 34 +++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) 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/match.pd b/gcc/match.pd index 24a0bbead3e..8121ec09f53 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3240,7 +3240,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_ior:c (negate (convert (gt @0 INTEGER_CST@1))) (convert @0)) (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) - && TYPE_UNSIGNED (TREE_TYPE (@0))) + && TYPE_UNSIGNED (TREE_TYPE (@0)) && type_has_mode_precision_p (type)) (with { unsigned itype_precision = TYPE_PRECISION (TREE_TYPE (@0)); @@ -3255,7 +3255,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (match (unsigned_integer_sat_trunc @0) (convert (min @0 INTEGER_CST@1)) (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) - && TYPE_UNSIGNED (TREE_TYPE (@0))) + && TYPE_UNSIGNED (TREE_TYPE (@0)) && type_has_mode_precision_p (type)) (with { unsigned itype_precision = TYPE_PRECISION (TREE_TYPE (@0)); 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" } } */