From patchwork Mon Oct 18 10:05:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 46335 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B91E03858422 for ; Mon, 18 Oct 2021 10:07:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B91E03858422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634551664; bh=0T3jZ36tkqiw9XWAOsgVbKSuh0PMybYQ6duBtwAuOx8=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=KTTVV7UP3GWO6OSaBnzibaXu6f0kQVf23E227tDUxFgoeHFnFCu63q5PiDA+4WXqS 5W/ejbx7nRmbZtQvZ76kKQr1lcK4X1VYJI1ayfHpy4Fv4DF+rNaZ40npUhkZ6DkRv+ yA0XkAmnR16aLFie+3uk1Zzs6j2QY3KJqLhGMyIU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id E48463858029 for ; Mon, 18 Oct 2021 10:06:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E48463858029 Received: by mail-ed1-x535.google.com with SMTP id i20so67909431edj.10 for ; Mon, 18 Oct 2021 03:06: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:from:date:message-id:subject:to; bh=0T3jZ36tkqiw9XWAOsgVbKSuh0PMybYQ6duBtwAuOx8=; b=H+fbb/lks8Of+teJKGXXPEbbRg02tuP6pv+WlzdPUu3Kz8lSJu5yIROAGbm/iQYV3x qWO+7U+5zcKdYeBF/qtDvpY3LsqvfIITViLzYCadExyRygKnNphGUdezPW6oviAxcHC7 q3L9Yl2KBdcTNrJgWwLq+oN7/jKUjPfShclkvhUMA/O1tbLY0AH7+ubde0B2Ahqo3OvR wFT2tbujbZzMVb4oKVpTeFK2UNYeKU0glCASyipzPSdc1/QBt99iL4C/ra9LQDs1cJHJ h+wxb3sIg01Yua+ccmrOH5sZRZz8xf0zoM3nMWv6g5WDcKglylgl5dejH5SZqoeVMJJ9 o/Hw== X-Gm-Message-State: AOAM531vsIlvJAvcWDSFsqNAA3Kq1d8/JF3cDzrL65l0DkZpveqEFsMc zyjqMhl/6e1eFLCJzV0VVa5Xo59P65NmlAAq9HRUhbjtsc4= X-Google-Smtp-Source: ABdhPJyZmh/WqGs43sCAg1DJcFcxaOVdFjMtOquWwobuTK7fhatn7N1auupjIeH7vvX3sa29/suYReCKL9/BtkO4ozU= X-Received: by 2002:a17:906:c2cf:: with SMTP id ch15mr27712143ejb.321.1634551560342; Mon, 18 Oct 2021 03:06:00 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 18 Oct 2021 15:35:24 +0530 Message-ID: Subject: [match.pd] PR83750 - CSE erf/erfc pair To: gcc Patches , Richard Biener X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham 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-Patchwork-Original-From: Prathamesh Kulkarni via Gcc-patches From: Prathamesh Kulkarni Reply-To: Prathamesh Kulkarni Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi Richard, As suggested in PR, I have attached WIP patch that adds two patterns to match.pd: erfc(x) --> 1 - erf(x) if canonicalize_math_p() and, 1 - erf(x) --> erfc(x) if !canonicalize_math_p(). This works to remove call to erfc for the following test: double f(double x) { double g(double, double); double t1 = __builtin_erf (x); double t2 = __builtin_erfc (x); return g(t1, t2); } with .optimized dump shows: t1_2 = __builtin_erf (x_1(D)); t2_3 = 1.0e+0 - t1_2; However, for the following test: double f(double x) { double g(double, double); double t1 = __builtin_erfc (x); return t1; } It canonicalizes erfc(x) to 1 - erf(x), but does not transform 1 - erf(x) to erfc(x) again post canonicalization. -fdump-tree-folding shows that 1 - erf(x) --> erfc(x) gets applied, but then it tries to resimplify erfc(x), which fails post canonicalization. So we end up with erfc(x) transformed to 1 - erf(x) in .optimized dump, which I suppose isn't ideal. Could you suggest how to proceed ? Thanks, Prathamesh diff --git a/gcc/match.pd b/gcc/match.pd index a9791ceb74a..217e46ff12c 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -6147,6 +6147,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (floors tree_expr_nonnegative_p@0) (truncs @0)))) +/* Simplify, + erfc(x) -> 1 - erf(x) if canonicalize_math_p(). + 1 - erf(x) -> erfc(x) if !canonicalize_math_p(). */ + +(if (flag_unsafe_math_optimizations) + (simplify + (ERFC @0) + (if (canonicalize_math_p ()) + (minus { build_one_cst (TREE_TYPE (@0)); } (ERF @0)))) + (simplify + (minus real_onep (ERF @0)) + (if (!canonicalize_math_p ()) + (ERFC @0)))) + (match double_value_p @0 (if (TYPE_MAIN_VARIANT (TREE_TYPE (@0)) == double_type_node)))