From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id CD5AA3858D3C for ; Fri, 10 Mar 2023 11:38:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD5AA3858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id D804D20653; Fri, 10 Mar 2023 11:38:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1678448321; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yVZW0bIEDx+wwwvDxDuBw+ugvDmDmlGThhH6S60V2FQ=; b=BjU+GVXyY9xiA5XWuDG/HSwtRQ8IpJ4eaErobCJBDIHg4GCQUITB0o8gO7egGZPYopFkkh kuwH2KqzEFQefeqZQ66ZCOiNGyclk+hlz06gJjTiAz8XUa8CPeYZ0vBB8dubR98NGZbECF aTsphEEk5pAe12QN2sgHqGgUJHNwgdA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1678448321; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yVZW0bIEDx+wwwvDxDuBw+ugvDmDmlGThhH6S60V2FQ=; b=o5tw5W2c5O3UZ6ftFEJVTOxaBfBzWyjFUyhJ4xWn3+7j/CuQGzdP6fx4vyvjZs5AGJaxLx h2z/5jzScfVr3aCA== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id C8BF72C141; Fri, 10 Mar 2023 11:38:41 +0000 (UTC) Date: Fri, 10 Mar 2023 11:38:41 +0000 (UTC) From: Richard Biener To: Jakub Jelinek cc: Aldy Hernandez , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] range-op-float: Extend lhs by 0.5ulp rather than 1ulp if not -frounding-math [PR109008] In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,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 List-Id: On Fri, 10 Mar 2023, Jakub Jelinek wrote: > Hi! > > This patch, incremental to the just posted one, improves the reverse > operation ranges significantly by widening just by 0.5ulp in each > direction rather than 1ulp. Again, REAL_VALUE_TYPE has both wider > exponent range and wider mantissa precision (160 bits) than any > supported type, this patch uses the latter property. > > The patch doesn't do it if -frounding-math, because then the rounding > can be +-1ulp in each direction depending on the rounding mode which > we don't know, or for IBM double double because that type is just weird > and we can't trust in sane properties. > > I've performed testing of these 2 patches on 300000 random tests as with > yesterday's patch, exact numbers are in the PR, but I see very significant > improvement in the precision of the ranges while keeping it conservatively > correct. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? The flow is a little bit obfuscated, but OK. Thanks, Richard. > 2023-03-10 Jakub Jelinek > > PR tree-optimization/109008 > * range-op-float.cc (float_widen_lhs_range): If not > -frounding-math and not IBM double double format, extend lhs > range just by 0.5ulp rather than 1ulp in each direction. > > --- gcc/range-op-float.cc.jj 2023-03-09 12:13:57.189790814 +0100 > +++ gcc/range-op-float.cc 2023-03-09 13:12:05.248873234 +0100 > @@ -2205,8 +2205,8 @@ zero_to_inf_range (REAL_VALUE_TYPE &lb, > [1., 1.] = op1 + [1., 1.]. op1's range is not [0., 0.], but > [-0x1.0p-54, 0x1.0p-53] (when not -frounding-math), any value for > which adding 1. to it results in 1. after rounding to nearest. > - So, for op1_range/op2_range extend the lhs range by 1ulp in each > - direction. See PR109008 for more details. */ > + So, for op1_range/op2_range extend the lhs range by 1ulp (or 0.5ulp) > + in each direction. See PR109008 for more details. */ > > static frange > float_widen_lhs_range (tree type, const frange &lhs) > @@ -2230,6 +2230,14 @@ float_widen_lhs_range (tree type, const > lb = dconstm1; > SET_REAL_EXP (&lb, FLOAT_MODE_FORMAT (TYPE_MODE (type))->emax + 1); > } > + if (!flag_rounding_math && !MODE_COMPOSITE_P (TYPE_MODE (type))) > + { > + /* If not -frounding-math nor IBM double double, actually widen > + just by 0.5ulp rather than 1ulp. */ > + REAL_VALUE_TYPE tem; > + real_arithmetic (&tem, PLUS_EXPR, &lhs.lower_bound (), &lb); > + real_arithmetic (&lb, RDIV_EXPR, &tem, &dconst2); > + } > } > if (real_isfinite (&ub)) > { > @@ -2240,6 +2248,14 @@ float_widen_lhs_range (tree type, const > ub = dconst1; > SET_REAL_EXP (&ub, FLOAT_MODE_FORMAT (TYPE_MODE (type))->emax + 1); > } > + if (!flag_rounding_math && !MODE_COMPOSITE_P (TYPE_MODE (type))) > + { > + /* If not -frounding-math nor IBM double double, actually widen > + just by 0.5ulp rather than 1ulp. */ > + REAL_VALUE_TYPE tem; > + real_arithmetic (&tem, PLUS_EXPR, &lhs.upper_bound (), &ub); > + real_arithmetic (&ub, RDIV_EXPR, &tem, &dconst2); > + } > } > /* Temporarily disable -ffinite-math-only, so that frange::set doesn't > reduce the range back to real_min_representable (type) as lower bound > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)