From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by sourceware.org (Postfix) with ESMTPS id E0A4A3858D20 for ; Mon, 26 Jun 2023 01:31:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E0A4A3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687743070; x=1719279070; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ANIH3qyFXH7SOaf6PdShnSmtzTRbBRRAsT4ipDiZbq4=; b=YCbjiUpJakAxhVDlSdpJJRe16ECYzkvdnWQ68NwokxF8Ur/Mo3EBnozN 3YOIACHqxWEHqOqTUA4hiCB0kpWLKLGH1RUkPN+1wkAmf7arjTv4XJMOU U5wav9w4ypVqAopDLFNf/D+/wgLTK4jGBeiYJA+h6AUtRN0NSyWkAbKtW +RdUFQfRxXtqyMplgjX9K5qXhphWDI5mZV0a2j9/kdhXJi454p5uu+aWb 4HLWVbLQh4wrfWn8qfSJ9BwWKE4vjgDbXLdX+sLx2Z0gR5jHVSbZUcjVU 8B+HFLa0l01MpitzfJUelynE4zomtLanTIgqdjj6aX3DI4iwSG+il4e1I Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="391353084" X-IronPort-AV: E=Sophos;i="6.01,158,1684825200"; d="scan'208";a="391353084" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2023 18:31:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10752"; a="785969703" X-IronPort-AV: E=Sophos;i="6.01,158,1684825200"; d="scan'208";a="785969703" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmsmga004.fm.intel.com with ESMTP; 25 Jun 2023 18:31:05 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 349FA1005185; Mon, 26 Jun 2023 09:31:05 +0800 (CST) From: liuhongt To: gcc-patches@gcc.gnu.org Cc: richard.sandiford@arm.com, rguenther@suse.de Subject: [PATCH 2/3] Don't use intermiediate type for FIX_TRUNC_EXPR when ftrapping-math. Date: Mon, 26 Jun 2023 09:31:04 +0800 Message-Id: <20230626013105.18788-2-hongtao.liu@intel.com> X-Mailer: git-send-email 2.39.1.388.g2fc9e9ca3c In-Reply-To: <20230626013105.18788-1-hongtao.liu@intel.com> References: <20230626013105.18788-1-hongtao.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.0 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_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: > > Hmm, good question. GENERIC has a direct truncation to unsigned char > > for example, the C standard generally says if the integral part cannot > > be represented then the behavior is undefined. So I think we should be > > safe here (0x1.0p32 doesn't fit an int). > > We should be following Annex F (unspecified value plus "invalid" exception > for out-of-range floating-to-integer conversions rather than undefined > behavior). But we don't achieve that very well at present (see bug 93806 > comments 27-29 for examples of how such conversions produce wobbly > values). That would mean guarding this with !flag_trapping_math would be the appropriate thing to do. Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,} and aarch64-linux-gnu. Ok for trunk? gcc/ChangeLog: PR tree-optimization/110371 PR tree-optimization/110018 * tree-vect-stmts.cc (vectorizable_conversion): Don't use intermiediate type for FIX_TRUNC_EXPR when ftrapping-math. gcc/testsuite/ChangeLog: * gcc.target/i386/pr110018-1.c: Add -fno-trapping-math to dg-options. * gcc.target/i386/pr110018-2.c: Ditto. --- gcc/testsuite/gcc.target/i386/pr110018-1.c | 2 +- gcc/testsuite/gcc.target/i386/pr110018-2.c | 2 +- gcc/tree-vect-stmts.cc | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.target/i386/pr110018-1.c b/gcc/testsuite/gcc.target/i386/pr110018-1.c index b6a3be7b7a2..24eeca60f6f 100644 --- a/gcc/testsuite/gcc.target/i386/pr110018-1.c +++ b/gcc/testsuite/gcc.target/i386/pr110018-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-mavx512fp16 -mavx512vl -O2 -mavx512dq" } */ +/* { dg-options "-mavx512fp16 -mavx512vl -O2 -mavx512dq -fno-trapping-math" } */ /* { dg-final { scan-assembler-times {(?n)vcvttp[dsh]2[dqw]} 5 } } */ /* { dg-final { scan-assembler-times {(?n)vcvt[dqw]*2p[dsh]} 5 } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr110018-2.c b/gcc/testsuite/gcc.target/i386/pr110018-2.c index a663e074698..9a2d9e17894 100644 --- a/gcc/testsuite/gcc.target/i386/pr110018-2.c +++ b/gcc/testsuite/gcc.target/i386/pr110018-2.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-mavx512fp16 -mavx512vl -O2 -mavx512dq" } */ +/* { dg-options "-mavx512fp16 -mavx512vl -O2 -mavx512dq -fno-trapping-math" } */ /* { dg-final { scan-assembler-times {(?n)vcvttp[dsh]2[dqw]} 5 } } */ /* { dg-final { scan-assembler-times {(?n)vcvt[dqw]*2p[dsh]} 5 } } */ diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 1748555a625..bf61461939b 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -5263,7 +5263,8 @@ vectorizable_conversion (vec_info *vinfo, if ((code == FLOAT_EXPR && GET_MODE_SIZE (lhs_mode) > GET_MODE_SIZE (rhs_mode)) || (code == FIX_TRUNC_EXPR - && GET_MODE_SIZE (rhs_mode) > GET_MODE_SIZE (lhs_mode))) + && GET_MODE_SIZE (rhs_mode) > GET_MODE_SIZE (lhs_mode) + && !flag_trapping_math)) { bool float_expr_p = code == FLOAT_EXPR; scalar_mode imode = float_expr_p ? rhs_mode : lhs_mode; -- 2.39.1.388.g2fc9e9ca3c