From patchwork Tue Aug 6 12:59:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1969503 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=D+R25c/C; 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 4WdYLl6XXdz1yXs for ; Tue, 6 Aug 2024 23:00:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 360763858424 for ; Tue, 6 Aug 2024 13:00:11 +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.12]) by sourceware.org (Postfix) with ESMTPS id 651873858C56 for ; Tue, 6 Aug 2024 12:59:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 651873858C56 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 651873858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.12 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722949190; cv=none; b=xiUaWJC1V8WRMgNsvpGgSIpCf2W/FiXvdLVQ8RCOt+P4JQMpa/MT3vJ1wO4yOSO62h8Z7VMh4b84NTaI79SScKk31+14tVYr1K42apkcsBGNHhFvrZPMOxUZ4pblqyto1fphSCn8h0CQk32W2cdMemkGjAMDBU6Su74See9r+E8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722949190; c=relaxed/simple; bh=tdLXj8FtAmkHAN+rl4Dyv93USvTM8+9W/NZpMpHpGaY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=mOjscXmS+j7lHv8x4nTQKasqY8kmQRlAsGeQ2fqTw2JSqZeFtF3hZF5xXYVPIK6yZAnun9h4Yhk9I1ke/vw2qKqLc4P0HiCX31JPi33dlTTjnEsxYOg24lOTxhAUfKVjueHbLsknd7vY0cIIquAyLfpUh8PPv6javlaW0W1Cmvo= 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=1722949188; x=1754485188; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=tdLXj8FtAmkHAN+rl4Dyv93USvTM8+9W/NZpMpHpGaY=; b=D+R25c/CSv38bDsCqhPvJZbXy8RuY/1JJiyTEGCFJBI/hDTqVj8anBJu DjTXFKmaERXuQ24JfVfjCiZBPeW0kleQMX5ETmtXelSpyaq2ayFe1wRvj Yx+mGwXftwJifwmsmzEki20IdW+XGlDS8JRdmUyH2YyKlcKx+frs6ftsV K7DqIYiGkRXjWAwbJGfn1+4LIpdAYb/7Hpw9dDx2TdM6m7a2aPgUsWJID TeF/EBVUMk4Bl+7xxF1CEXtunXOkuFUuHRseLpt/EibEWSWuljqFio2kc T/lgU5JG9a4K2gGbB5DiqTq36SY9bqbAnJ8AXTGhlc60UpP2JpvrGbvYR g==; X-CSE-ConnectionGUID: JYgdftPISmu/Oz8pg2dHWg== X-CSE-MsgGUID: V6tHDp0mRcyDiGTTynq8RA== X-IronPort-AV: E=McAfee;i="6700,10204,11156"; a="24828871" X-IronPort-AV: E=Sophos;i="6.09,267,1716274800"; d="scan'208";a="24828871" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Aug 2024 05:59:47 -0700 X-CSE-ConnectionGUID: jzMJiPA2TjCK4WH5DxYMPA== X-CSE-MsgGUID: IehKklDmQvy/BtUolF5+Wg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,267,1716274800"; d="scan'208";a="87433759" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by fmviesa001.fm.intel.com with ESMTP; 06 Aug 2024 05:59:45 -0700 Received: from panli.sh.intel.com (panli.sh.intel.com [10.239.154.73]) by shvmail02.sh.intel.com (Postfix) with ESMTP id B8D6810054E3; Tue, 6 Aug 2024 20:59:44 +0800 (CST) From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com, juzhe.zhong@rivai.ai, kito.cheng@gmail.com, jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, Pan Li Subject: [PATCH v2] Vect: Make sure the lhs type of .SAT_TRUNC has its mode precision [PR116202] Date: Tue, 6 Aug 2024 20:59:37 +0800 Message-ID: <20240806125937.779220-1-pan2.li@intel.com> X-Mailer: git-send-email 2.43.0 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, KAM_SHORT, 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 vect pattern recog is valid when the lhs type has its mode precision. For example as below, QImode with 1 bit precision like _Bool is invalid here. g_12 = (long unsigned int) _2; _13 = MIN_EXPR ; _3 = (_Bool) _13; The above pattern cannot be recog as .SAT_TRUNC (g_12) because the dest only has 1 bit precision with QImode mode. Aka the type doesn't have the mode precision. The below tests are passed for this patch. 1. The rv64gcv fully regression tests. 2. The x86 bootstrap tests. 3. The x86 fully regression tests. PR target/116202 gcc/ChangeLog: * tree-vect-patterns.cc (vect_recog_sat_trunc_pattern): Add the type_has_mode_precision_p check for the lhs type. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/pr116202-run-1.c: New test. Signed-off-by: Pan Li --- .../riscv/rvv/base/pr116202-run-1.c | 24 +++++++++++++++++++ gcc/tree-vect-patterns.cc | 5 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/pr116202-run-1.c diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr116202-run-1.c b/gcc/testsuite/gcc.target/riscv/rvv/base/pr116202-run-1.c new file mode 100644 index 00000000000..d150f20b5d9 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr116202-run-1.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-options "-O3 -march=rv64gcv_zvl256b -fdump-rtl-expand-details" } */ + +int b[24]; +_Bool c[24]; + +int main() { + for (int f = 0; f < 4; ++f) + b[f] = 6; + + for (int f = 0; f < 24; f += 4) + c[f] = ({ + int g = ({ + unsigned long g = -b[f]; + 1 < g ? 1 : g; + }); + g; + }); + + if (c[0] != 1) + __builtin_abort (); +} + +/* { dg-final { scan-rtl-dump-not ".SAT_TRUNC " "expand" } } */ diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc index 4674a16d15f..74f80587b0e 100644 --- a/gcc/tree-vect-patterns.cc +++ b/gcc/tree-vect-patterns.cc @@ -4695,11 +4695,12 @@ vect_recog_sat_trunc_pattern (vec_info *vinfo, stmt_vec_info stmt_vinfo, tree ops[1]; tree lhs = gimple_assign_lhs (last_stmt); + tree otype = TREE_TYPE (lhs); - if (gimple_unsigned_integer_sat_trunc (lhs, ops, NULL)) + if (gimple_unsigned_integer_sat_trunc (lhs, ops, NULL) + && type_has_mode_precision_p (otype)) { tree itype = TREE_TYPE (ops[0]); - tree otype = TREE_TYPE (lhs); tree v_itype = get_vectype_for_scalar_type (vinfo, itype); tree v_otype = get_vectype_for_scalar_type (vinfo, otype); internal_fn fn = IFN_SAT_TRUNC;