From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id B99133852C7F for ; Fri, 18 Nov 2022 08:39:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B99133852C7F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x22c.google.com with SMTP id l8so5887492ljh.13 for ; Fri, 18 Nov 2022 00:39:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=55RBFv03NQHXmEHrr2Ow9OxgYRRw+ene3Wfx4+oRdSg=; b=lvOghePp2RUFFThJZyurlSqo9/vVKn61axNmq9hhn2vEJm+qlB+ggz5TzNvZUB231q dO9e7mttfMcVqgd+6o6UYkTMbRQkrkdlQqqKve69Wdqe3mlCjxO360G1L0BWQsCf7nZU rnVPhv8fK0pwgKs3bhOmWcKjtnpAgCeAJkWlyUzi1bGrCyVbZ8i+xM5gIBnCLLS634va PEE34C2w5S6WyO1JxfgbRp6VR/hGEC2uMUshqBRED+ruXRQ8Djye3rnA40zn/Bv5QWWg kaLb+8Wdy4hQhhc43gs19ev+duRdYyo1t3X3SUDfD0e6UFTSIVXguiO3kIg8ClFmoRrM 14yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=55RBFv03NQHXmEHrr2Ow9OxgYRRw+ene3Wfx4+oRdSg=; b=oum7gH45CwTY470sES+hPVB5TvbA5PTVIr9smxvGLk5b6VXNjjK079vmxz7Gz/oVzG D8dWmydDNRMUtjg1dvzm/i9uGKPuhHIoS8xnTdjgFaskhC8s5eIZbCwmd67W3ijhkRfY 0EutnJCZYCTFHO75zxPIBOCMuOl/Yf2gOrDTPXjDDvGRXiJN8SdJHL7kvDYsAq3LAhDV MppbeBZT9x4A8Cd4nqJh4gF5cGIkFqY4Q1ByMV8ZHwTjNWpOfgjPs2wTus/tWF+yZvMl G4/U88S8rWIvoSHOTpR0j4TFSn+0ZemJc+lkgsbHGk5DesT13oA4okwPEVsQf5J8p0Dk rt2g== X-Gm-Message-State: ANoB5pnv/OgpdNgkATv9da/cjp0Uh6yPfZ9b2/Lm2ZhPRFOFzIOOI9tk m+yGteFOQ0+uvKJ3zhFPYdsv93jY/OFRFhMG5hM= X-Google-Smtp-Source: AA0mqf6LIGRccGDVDRMJ5ON5+8IG8xTYptWg0/tJaVnUlO5+jrJqwz+wxnxzXZRIdhPZCfgX6HO6omjuMQXk2eVroSA= X-Received: by 2002:a2e:8055:0:b0:26d:e656:d853 with SMTP id p21-20020a2e8055000000b0026de656d853mr2044681ljg.177.1668760788972; Fri, 18 Nov 2022 00:39:48 -0800 (PST) MIME-Version: 1.0 References: <20221113200553.440728-1-aldyh@redhat.com> <6150f7fd-5a57-c138-f65e-8dc3bf13d11a@codesourcery.com> <4441fc8a-e9e1-6fdd-20d1-473d10122426@codesourcery.com> In-Reply-To: From: Richard Biener Date: Fri, 18 Nov 2022 09:39:36 +0100 Message-ID: Subject: Re: [PATCH] [range-ops] Implement sqrt. To: Jakub Jelinek Cc: Joseph Myers , Aldy Hernandez , GCC patches , Andrew MacLeod Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,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 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. 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? Richard. > > Jakub >