From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 569D3384F6F2 for ; Fri, 18 Nov 2022 10:37:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 569D3384F6F2 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668767866; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZkPbWh5PRYGcQkePkTurmkCFBH3uh9Z5oxCVb/+xFos=; b=f3nMC+6v/Beaq2pXAqFNcqHBoRhJ10deEFRrFFF3ZIbHWkEc+NR+GtNaI7j7cOMAgFNatm oJnedbDv8GcIe2m+ZNrfq33XkQSbMV2b1iaBPNcYJxi+aP6ztxK7MLHh3qU/5uS/rIUXXp VWhTWhEOpOntsBLIO8MjD7T2H2a6sk4= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-267-Ye12lDGKPtiP5Ztkv0z1fQ-1; Fri, 18 Nov 2022 05:37:45 -0500 X-MC-Unique: Ye12lDGKPtiP5Ztkv0z1fQ-1 Received: by mail-wr1-f71.google.com with SMTP id q2-20020adfab02000000b00241b8f7efc5so1254881wrc.19 for ; Fri, 18 Nov 2022 02:37:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZkPbWh5PRYGcQkePkTurmkCFBH3uh9Z5oxCVb/+xFos=; b=36mCtJsrf94yEydDbINpS8a8ulouhtxBlxLlv6fmD9e1WF/ySGQdDSLiMg5szpc7NA lzihKr2uY9lV1/Mr/vQ3G04Fax7PSZ1vzmguSjWwL498//efW8M/wjoxH/ofEAO7RFS8 U77BSuFjfjczEwKayu/8asDWvDthQJF+Lw6Nz7fA/Yaqjh2fSrFsTV4RK2lT7o9029sv AKxApjH1fq6v47MLlkbiUOdsO/rnJG2JLCjyTOr6JD7J/9pYltz/caV5z25ZIBYPaT3u We9qoYM6x2eosWtX4INswt0/4kRklW6SrT0I9B4JXdjqQOVChiiRVFRi33URglUg6MUi wIig== X-Gm-Message-State: ANoB5pm3OZ3dNByVwX94u3mRgY3PveOGOpksqoqSRaD2G1Odv7gbBX41 jy8NJ8WLVYIPIQHesvwGd0r0naoluor/R1NC8wMfmj7ELDLPXFqTR7+FsQWaQus/Bx5ztRq4rao uS+z5IEg4GUFu/WnwFQ== X-Received: by 2002:adf:f552:0:b0:236:6578:48ad with SMTP id j18-20020adff552000000b00236657848admr3928921wrp.405.1668767864231; Fri, 18 Nov 2022 02:37:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf52/BO9BdW3QrCi6d0nJOKnRsC5dxWMRcw+LEpkqSAJyenamV1wafyHdSBU6VrOQpSSaz01Ww== X-Received: by 2002:adf:f552:0:b0:236:6578:48ad with SMTP id j18-20020adff552000000b00236657848admr3928908wrp.405.1668767863909; Fri, 18 Nov 2022 02:37:43 -0800 (PST) Received: from [192.168.1.2] ([139.47.33.22]) by smtp.gmail.com with ESMTPSA id f19-20020a05600c4e9300b003cfd4a50d5asm9454380wmq.34.2022.11.18.02.37.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Nov 2022 02:37:43 -0800 (PST) Message-ID: Date: Fri, 18 Nov 2022 11:37:42 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH] [range-ops] Implement sqrt. To: Richard Biener , Jakub Jelinek Cc: Joseph Myers , GCC patches , Andrew MacLeod References: <20221113200553.440728-1-aldyh@redhat.com> <6150f7fd-5a57-c138-f65e-8dc3bf13d11a@codesourcery.com> <4441fc8a-e9e1-6fdd-20d1-473d10122426@codesourcery.com> From: Aldy Hernandez In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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 List-Id: On 11/18/22 09:39, Richard Biener wrote: > On Thu, Nov 17, 2022 at 8:38 PM Jakub Jelinek via Gcc-patches > wrote: >> >> On Thu, Nov 17, 2022 at 06:59:45PM +0000, Joseph Myers wrote: >>> On Thu, 17 Nov 2022, Aldy Hernandez via Gcc-patches wrote: >>> >>>> So... is the optimization wrong? Are we not allowed to substitute >>>> that NAN if we know it's gonna happen? Should we also allow F F F F F >>>> in the test? Or something else? >>> >>> This seems like the usual ambiguity about what transformations >>> -ftrapping-math (on by default) is meant to prevent. >>> >>> Generally it's understood to prevent transformations that add *or remove* >>> exceptions, so folding a case that raises "invalid" to a NaN (with >>> "invalid" no longer raised) is invalid with -ftrapping-math. But that >>> doesn't tend to be applied if the operation raising the exceptions has a >>> result that is otherwise unused - in such a case the operation may still >>> be removed completely (the exception isn't properly treated as a side >>> effect to avoid dead code elimination; cf. Marc Glisse's -ffenv-access >>> patches from August 2020). And it may often also not be applied to >>> "inexact". >> >> The problem is that the above model I'm afraid is largely incompatible with >> the optimizations ranger provides. >> A strict model where no operations that could raise exceptions are discarded >> is easy, we let frange optimize as much as it wants and just tell DCE not to >> eliminate operations that can raise exceptions. >> But in the model where some exceptions can be discarded if results are unused >> but not others where they are used, there is no way to distinguish between >> the result of the operation really isn't needed and ranger figured out a >> result (or usable range of something) and therefore the result of the >> operation isn't needed. >> Making frange more limited with -ftrapping-math, making it punt for >> operations that could raise an exception would be quite drastic >> pessimization. Perhaps for -ftrapping-math we could say no frange value is >> singleton and so at least for most of operations we actually wouldn't >> optimize out the whole computation when we know the result? Still, we could >> also just have >> r = long_computation (x, y, z); >> if (r > 42.0) >> and if frange figures out that r must be [256.0, 1024.0] and never NAN, we'd >> still happily optimize away the comparison. > > Yes, I don't think singling out the singleton case will help. There is also simplify_using_ranges::fold_cond() which is used by VRP and DOM to fold conditionals. So twiddling frange::singleton_p will have no effect here since FP conditionals results are integers (f > 3.0 is true or false). And now that we're on this subject... We are very careful in frange (range-op-floats.o) to avoid returning true/false in relational which may have a NAN. This keeps us from folding conditionals that may result in a trapping NAN. For example, if we see [if (x_5 unord_lt 10.0)...] and we know x_5 is [-INF, -8.0] +-NAN, this conditional is always true, but we return VARYING to avoid folding a NAN producing conditional. I wonder whether we're being too conservative? An alternative woudld be: z_8 = x_5 unord_lt 10.0 goto true_side; But if DCE is going to clean that up anyhow without regards to exceptions, then maybe we can fold these conditionals altogether? If not in this release, then in the next one. ISTM that range-ops should always tell the truth of what it knows, instead of being conservative wrt exceptions. It should be up to the clients (VRP or simplify_using_ranges::fold_cond) to use the information correctly. > Practically strictly > preserving IEEE exceptions is only important for a very small audience, and > for that even INEXACT will matter (but we still have -ftrapping-math > by default). > For that audience likely all constant / range propagation is futile and thus the > easiest thing might be to simply cut that off completely? > > I'd say what ranger does is reasonable with -ftrapping-math given the current > practice of handling this option. There's no point in trying to preserve the > (by accident) "better" handling without ranger. Instead as Joseph says somebody > would need to sit down, split -ftrapping-math, adjust the default and thorougly > document things (also with -fnon-call-exceptions which magically makes > IEEE flag raising operations possibly throw exceptions). As there's currently > no code motion barriers for FP code with respect to exception flag inspection > any dead code we preserve is likely going to be unhelpful. > > So for now simply amend the documentation as to what -ftrapping-math > currently means with respect to range/constant propagation? So something like "Even in the presence of -ftrapping-math, VRP may fold operations that may cause exceptions For example, an addition that is guaranteed to produce a NAN, may be replaced with a NAN, thus eliding the addition. This may cause any exception that may have been generated by the addition to not appear in the final program." ?? Aldy