From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id 3FFC73858412 for ; Fri, 15 Oct 2021 07:48:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3FFC73858412 Received: by mail-ed1-x529.google.com with SMTP id d3so34502958edp.3 for ; Fri, 15 Oct 2021 00:48:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=YrARGFjxlj8cDdRJSrMc9O/NVRDFyUUutsVdxA0rwKM=; b=Eazxrod6azicAAH2v1p5wPKpvPRGPc7wYZ+jxW1yHphBeDq7RLMty2cdpTIJDpj7Mi k8MQmAJVzbeoyHG2XeRbWeSXIQNxgEeAqTs5bdvsVWPc3X+5Th/wRYbb0oSEOhU2xEVu E6hSdmaVuXyse9PzfhT+DMwFj/aHjnWpYEwnOBZe1OwarcH8To4OjT1GuZBP4OkcN4iC fI8I9bddWEzY3w3WospB2A9TY4t3dW1Rz44UQvbVI1NssRcr4zcv0jNlV25x6Z/G2cSE vzlaqiZHrKDphaR1mgUTuzGa8MR9uTh/ZSXgRPAEnhcTlUn9lvgE6MY74jre5gfILzSf szqQ== X-Gm-Message-State: AOAM532Hmc23BeHPhGPzJakzcUjni+vGB1r0xWW84qD+NRj2VFPlh+Hx PPHivF5usO754TsgplyzJlzZ68nevGYDyAxpDfE= X-Google-Smtp-Source: ABdhPJx+LLwu0u3xG6dah5/xEY6ke4QQixI4DS9GkMK64A2YdnbUapdX9xZxYc8HEcBJDYKphAja9PWDUlzDGHAqL+o= X-Received: by 2002:a50:e0c3:: with SMTP id j3mr15447683edl.97.1634284080081; Fri, 15 Oct 2021 00:48:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Fri, 15 Oct 2021 09:47:49 +0200 Message-ID: Subject: Re: FW: [PING] Re: [Patch][GCC][middle-end] - Generate FRINTZ for (double)(int) under -ffast-math on aarch64 To: Jirui Wu Cc: "gcc-patches@gcc.gnu.org" , Richard Sandiford , "ian@airs.com" , Richard Biener Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Oct 2021 07:48:03 -0000 On Fri, Sep 24, 2021 at 2:59 PM Jirui Wu via Gcc-patches wrote: > > Hi, > > Ping: https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577846.html > > The patch is attached as text for ease of use. Is there anything that nee= ds to change? > > Ok for master? If OK, can it be committed for me, I have no commit rights= . I'm still not sure about the correctness. I suppose the flag_fp_int_builtin_inexact && !flag_trapping_math is supposed to guard against spurious inexact exceptions, shouldn't that be !flag_fp_int_builtin_inexact || !flag_trapping_math instead? The comment looks a bit redundant and we prefer sth like /* (double)(int)x -> trunc (x) if the type of x matches the expressions FP type. */ Thanks, Richard. > Jirui Wu > > -----Original Message----- > From: Jirui Wu > Sent: Friday, September 10, 2021 10:14 AM > To: Richard Biener > Cc: Richard Biener ; Andrew Pinski ; Richard Sandiford ; ian@airs.com; gcc= -patches@gcc.gnu.org; Joseph S. Myers > Subject: [PING] Re: [Patch][GCC][middle-end] - Generate FRINTZ for (doubl= e)(int) under -ffast-math on aarch64 > > Hi, > > Ping: https://gcc.gnu.org/pipermail/gcc-patches/2021-August/577846.html > > Ok for master? If OK, can it be committed for me, I have no commit rights= . > > Jirui Wu > -----Original Message----- > From: Jirui Wu > Sent: Friday, September 3, 2021 12:39 PM > To: 'Richard Biener' > Cc: Richard Biener ; Andrew Pinski ; Richard Sandiford ; ian@airs.com; gcc= -patches@gcc.gnu.org; Joseph S. Myers > Subject: RE: [Patch][GCC][middle-end] - Generate FRINTZ for (double)(int)= under -ffast-math on aarch64 > > Ping > > -----Original Message----- > From: Jirui Wu > Sent: Friday, August 20, 2021 4:28 PM > To: Richard Biener > Cc: Richard Biener ; Andrew Pinski ; Richard Sandiford ; ian@airs.com; gcc= -patches@gcc.gnu.org; Joseph S. Myers > Subject: RE: [Patch][GCC][middle-end] - Generate FRINTZ for (double)(int)= under -ffast-math on aarch64 > > > -----Original Message----- > > From: Richard Biener > > Sent: Friday, August 20, 2021 8:15 AM > > To: Jirui Wu > > Cc: Richard Biener ; Andrew Pinski > > ; Richard Sandiford ; > > ian@airs.com; gcc-patches@gcc.gnu.org; Joseph S. Myers > > > > Subject: RE: [Patch][GCC][middle-end] - Generate FRINTZ for > > (double)(int) under -ffast-math on aarch64 > > > > On Thu, 19 Aug 2021, Jirui Wu wrote: > > > > > Hi all, > > > > > > This patch generates FRINTZ instruction to optimize type casts. > > > > > > The changes in this patch covers: > > > * Generate FRINTZ for (double)(int) casts. > > > * Add new test cases. > > > > > > The intermediate type is not checked according to the C99 spec. > > > Overflow of the integral part when casting floats to integers causes > > undefined behavior. > > > As a result, optimization to trunc() is not invalid. > > > I've confirmed that Boolean type does not match the matching conditio= n. > > > > > > Regtested on aarch64-none-linux-gnu and no issues. > > > > > > Ok for master? If OK can it be committed for me, I have no commit rig= hts. > > > > +/* Detected a fix_trunc cast inside a float type cast, > > + use IFN_TRUNC to optimize. */ > > +#if GIMPLE > > +(simplify > > + (float (fix_trunc @0)) > > + (if (direct_internal_fn_supported_p (IFN_TRUNC, type, > > + OPTIMIZE_FOR_BOTH) > > + && flag_unsafe_math_optimizations > > + && type =3D=3D TREE_TYPE (@0)) > > > > types_match (type, TREE_TYPE (@0)) > > > > please. Please perform cheap tests first (the flag test). > > > > + (IFN_TRUNC @0))) > > +#endif > > > > why only for GIMPLE? I'm not sure flag_unsafe_math_optimizations is a > > good test here. If you say we can use undefined behavior of any > > overflow of the fix_trunc operation what do we guard here? > > If it's Inf/NaN input then flag_finite_math_only would be more > > appropriate, if it's behavior for -0. (I suppose trunc (-0.0) =3D=3D -0= .0 > > and thus "wrong") then a && !HONOR_SIGNED_ZEROS (type) is missing > > instead. If it's setting of FENV state and possibly trapping on > > overflow (but it's undefined?!) then flag_trapping_math covers the > > latter but we don't have any flag for eliding FENV state affecting > > transforms, so there the kitchen-sink flag_unsafe_math_optimizations mi= ght apply. > > > > So - which is it? > > > This change is only for GIMPLE because we can't test for the optab suppor= t without being in GIMPLE. direct_internal_fn_supported_p is defined only f= or GIMPLE. > > IFN_TRUNC's documentation mentions nothing for zero, NaNs/inf inputs. > So I think the correct guard is just flag_fp_int_builtin_inexact. > !flag_trapping_math because the operation can only still raise inexacts. > > The new pattern is moved next to the place you mentioned. > > Ok for master? If OK can it be committed for me, I have no commit rights. > > Thanks, > Jirui > > Note there's also the pattern > > > > /* Handle cases of two conversions in a row. */ (for ocvt (convert > > float > > fix_trunc) (for icvt (convert float) > > (simplify > > (ocvt (icvt@1 @0)) > > (with > > { > > ... > > > > which is related so please put the new pattern next to that (the set > > of conversions handled there does not include (float (fix_trunc @0))) > > > > Thanks, > > Richard. > > > > > Thanks, > > > Jirui > > > > > > gcc/ChangeLog: > > > > > > * match.pd: Generate IFN_TRUNC. > > > > > > gcc/testsuite/ChangeLog: > > > > > > * gcc.target/aarch64/merge_trunc1.c: New test. > > > > > > > -----Original Message----- > > > > From: Richard Biener > > > > Sent: Tuesday, August 17, 2021 9:13 AM > > > > To: Andrew Pinski > > > > Cc: Jirui Wu ; Richard Sandiford > > > > ; ian@airs.com; > > > > gcc-patches@gcc.gnu.org; rguenther@suse.de > > > > Subject: Re: [Patch][GCC][middle-end] - Generate FRINTZ for > > > > (double)(int) under -ffast-math on aarch64 > > > > > > > > On Mon, Aug 16, 2021 at 8:48 PM Andrew Pinski via Gcc-patches > > > > wrote: > > > > > > > > > > On Mon, Aug 16, 2021 at 9:15 AM Jirui Wu via Gcc-patches > > > > > wrote: > > > > > > > > > > > > Hi all, > > > > > > > > > > > > This patch generates FRINTZ instruction to optimize type casts. > > > > > > > > > > > > The changes in this patch covers: > > > > > > * Opimization of a FIX_TRUNC_EXPR cast inside a FLOAT_EXPR > > > > > > using > > > > IFN_TRUNC. > > > > > > * Change of corresponding test cases. > > > > > > > > > > > > Regtested on aarch64-none-linux-gnu and no issues. > > > > > > > > > > > > Ok for master? If OK can it be committed for me, I have no > > > > > > commit > > rights. > > > > > > > > > > Is there a reason why you are doing the transformation manually > > > > > inside forwprop rather than handling it inside match.pd? > > > > > Also can't this only be done for -ffast-math case? > > > > > > > > You definitely have to look at the intermediate type - that could > > > > be a uint8_t or even a boolean type. So unless the intermediate > > > > type can represent all float values optimizing to trunc() is invali= d. > > > > Also if you emit IFN_TRUNC you have to make sure there's target > > > > support - we don't emit calls to a library > > > > trunc() from an internal function call (and we wouldn't want to > > > > optimize it that way). > > > > > > > > Richard. > > > > > > > > > > > > > > Thanks, > > > > > Andrew Pinski > > > > > > > > > > > > > > > > > Thanks, > > > > > > Jirui > > > > > > > > > > > > gcc/ChangeLog: > > > > > > > > > > > > * tree-ssa-forwprop.c (pass_forwprop::execute): > > > > > > Optimize with > > frintz. > > > > > > > > > > > > > > > > > > gcc/testsuite/ChangeLog: > > > > > > > > > > > > * gcc.target/aarch64/fix_trunc1.c: Update to new expect= ation. > > > > > > > -- > > Richard Biener > > SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 > > Nuernberg, Germany; GF: Felix Imend=C3=B6rffer; HRB 36809 (AG Nuernberg= )