From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 4EFFC3858D35 for ; Fri, 9 Jun 2023 18:08:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4EFFC3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 82107AB6; Fri, 9 Jun 2023 11:08:59 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 875143F6C4; Fri, 9 Jun 2023 11:08:13 -0700 (PDT) From: Richard Sandiford To: Kyrylo Tkachov via Gcc-patches Mail-Followup-To: Kyrylo Tkachov via Gcc-patches ,Kyrylo Tkachov , richard.sandiford@arm.com Cc: Kyrylo Tkachov Subject: Re: [PATCH] simplify-rtx: Implement constant folding of SS_TRUNCATE, US_TRUNCATE References: Date: Fri, 09 Jun 2023 19:08:12 +0100 In-Reply-To: (Kyrylo Tkachov via Gcc-patches's message of "Thu, 8 Jun 2023 14:56:37 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-27.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,KAM_SHORT,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: Kyrylo Tkachov via Gcc-patches writes: > Hi all, > > This patch implements RTL constant-folding for the SS_TRUNCATE and US_TRUNCATE codes. > The semantics are a clamping operation on the argument with the min and max of the narrow mode, > followed by a truncation. The signedness of the clamp and the min/max extrema is derived from > the signedness of the saturating operation. > > We have a number of instructions in aarch64 that use SS_TRUNCATE and US_TRUNCATE to represent > their operations and we have pretty thorough runtime tests in gcc.target/aarch64/advsimd-intrinsics/vqmovn*.c. > With this patch the instructions are folded away at optimisation levels and the correctness checks still > pass. > > Bootstrapped and tested on aarch64-none-linux-gnu and aarch64_be-none-elf. > Ok for trunk? > > Thanks, > Kyrill > > gcc/ChangeLog: > > * simplify-rtx.cc (simplify_const_unary_operation): > Handle US_TRUNCATE, SS_TRUNCATE. > > diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc > index 276be67aa67247dd46361ab9badc46ab089d6df0..5983a06e5a8ca89c717e8648be410024147b16e6 100644 > --- a/gcc/simplify-rtx.cc > +++ b/gcc/simplify-rtx.cc > @@ -2131,6 +2131,22 @@ simplify_const_unary_operation (enum rtx_code code, machine_mode mode, > result = wide_int::from (op0, width, UNSIGNED); > break; > > + case US_TRUNCATE: > + case SS_TRUNCATE: > + { > + signop sgn = code == US_TRUNCATE ? UNSIGNED : SIGNED; > + wide_int nmax > + = wide_int::from (wi::max_value (width, sgn), > + GET_MODE_PRECISION (imode), sgn); > + wide_int nmin > + = wide_int::from (wi::min_value (width, sgn), > + GET_MODE_PRECISION (imode), sgn); > + result > + = wide_int::from (op0, GET_MODE_PRECISION (imode), sgn); > + result = wi::min (wi::max (result, nmin, sgn), nmax, sgn); FWIW, it looks like this could be: result = wi::min (wi::max (op0, nmin, sgn), nmax, sgn); without the first assignment to result. That feels more natural IMO, since no conversion is being done on op0. Thanks, Richard > + result = wide_int::from (result, width, sgn); > + break; > + } > case SIGN_EXTEND: > result = wide_int::from (op0, width, SIGNED); > break;