From patchwork Tue Nov 8 11:01:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 16983 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2630615wru; Tue, 8 Nov 2022 03:02:49 -0800 (PST) X-Google-Smtp-Source: AMsMyM5uR6DFUkBONnWDRBa3FalK5syLvPxZ/qSIk9YypbUVwnAraduggoL4m6gkOyBtSoBARSXI X-Received: by 2002:a17:907:6e28:b0:7a0:b6b5:5103 with SMTP id sd40-20020a1709076e2800b007a0b6b55103mr51424092ejc.300.1667905369533; Tue, 08 Nov 2022 03:02:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667905369; cv=none; d=google.com; s=arc-20160816; b=QQYD10UTLKNip+vbOS4Q+bOfNwKIcyEN3l/JmxBJQCmvlcnT0DJyRpottyUvwfXkWm gxsVu5K/eoLcHZTnewq9ohlwmoYK2+j3vbG3RapNhA+VNGe/jEJdsB9rmGZ2P9C9qSL3 yx7rBceaxdnN0UA7RhrQ6i5WDEN/He8AKbQ32l8+YZlFZ+b0M861kQrS8UtgeTyYm509 r814ju0EEfnkdsHvSIQuf37kSS3AF6sUWI/DCkyiQlJMzUpCATI8rl7tDio6t1DBdd+M I+xAMWZonPocg2XTPJNoGjEGFb6q09p69FOfVIOsF7QcM8aDkLBnHxAnNVNLRZqkDlAx uKqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=6U1tChH5iK6s2hRgOmSzEOfkNJM6i5BXq8dAXGt1RMs=; b=VmtkUAycqfx4pbEVQxTGTZNePdePjpehV+C7tpc2WMcDvWjw0AFoqI2fMbXjcTERfd +cba7P7CB7ylfCbbNZUSUbhHiCQjdhApudxmA5uMa31wTTp5Ne1qv5mG2CGd9e3xmET8 PWxuzvg246JEBFL1Vah5z0wmFLfF6xNCFXjOV6hjoSLRSXhCVThgooTfNi1wBd4e/nSI niTDKGLBQTFFN/zz+C5a8MMB2pHUGdz/E0RCqH6JV75Mw7LNn1zg0ZA695ePTahskEHr 43rVYedIbccsK63Hg5W6B3AboEg1ADlxaS9H3IH7Ad0dTd2X0usXJdVXxQVlNHqKasmZ GzPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=k1uLz+m3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o17-20020a170906975100b007ae814af6aasi1130929ejy.87.2022.11.08.03.02.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 03:02:49 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=k1uLz+m3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 983903858432 for ; Tue, 8 Nov 2022 11:02:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 983903858432 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667905368; bh=6U1tChH5iK6s2hRgOmSzEOfkNJM6i5BXq8dAXGt1RMs=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=k1uLz+m3ufQZkFE8kR22Fd78dYjTolSkXWJyLnpFQHnr3LbMSTqOhTEJDWrJr3ry0 rW3BmIWoOxWFXltq0Q2XzAum1GmGjEjJXzlDBgB9Pk2Z2XSQ0GsbF6sRbn9KLh3vap A1ITMxaa6i+g+qXWpgcCORm+HnOkzRIoOvhaYmRI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id AFCA63858D28 for ; Tue, 8 Nov 2022 11:02:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AFCA63858D28 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-130-mDSGa8dwOae5Pi_66mX59w-1; Tue, 08 Nov 2022 06:01:59 -0500 X-MC-Unique: mDSGa8dwOae5Pi_66mX59w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 00A691C08967; Tue, 8 Nov 2022 11:01:59 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.252]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7B6BB10197; Tue, 8 Nov 2022 11:01:58 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2A8B1tjm2240531 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 8 Nov 2022 12:01:55 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2A8B1svX2240530; Tue, 8 Nov 2022 12:01:54 +0100 Date: Tue, 8 Nov 2022 12:01:53 +0100 To: Richard Biener , Jeff Law , "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] cdce: Fix up get_no_error_domain for new f{16,32,64,128} builtins [PR107547] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748925540423056119?= X-GMAIL-MSGID: =?utf-8?q?1748925540423056119?= Hi! I've missed that this function needs to handle all the builtins that are handled in can_test_argument_range. The following patch does that. For many of the builtins (like acos, or log) it is the same range regardless of the floating point type, but for some (cosh, sinh, exp{,m1,2}) it is different for each format, so I had to compute those ranges. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Note, seems the existing ranges were in some cases (e.g. for exp2) the smallest in absolute value which results infinite result, in others the largest which still results in finite result (but consistently so for the IEEE single vs. double). I've followed that for IEEE half and quad cases too, just am not sure why it was like that. I think get_domain with true, false is open interval rather than closed and the comments indicate that too, conservatively that is certainly correct. OT, with frange, perhaps we could DCE the calls unconditionally if frange can prove we are in the domain range. 2022-11-08 Jakub Jelinek PR tree-optimization/107547 * tree-call-cdce.cc (get_no_error_domain): Handle CASE_FLT_FN_FLOATN_NX of BUILT_IN_{ACOS,ASIN,ACOSH,ATANH,LOG,LOG2,LOG10,LOG1P}. Handle BUILT_IN_{COSH,SINH,EXP,EXPM1,EXP2}F{16,32,64,128}. * gcc.dg/pr107547.c: New test. Jakub --- gcc/tree-call-cdce.cc.jj 2022-10-31 09:04:56.484075098 +0100 +++ gcc/tree-call-cdce.cc 2022-11-07 14:51:54.223803618 +0100 @@ -693,20 +693,31 @@ get_no_error_domain (enum built_in_funct { /* Trig functions: return [-1, +1] */ CASE_FLT_FN (BUILT_IN_ACOS): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_ACOS): CASE_FLT_FN (BUILT_IN_ASIN): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_ASIN): return get_domain (-1, true, true, 1, true, true); /* Hyperbolic functions. */ CASE_FLT_FN (BUILT_IN_ACOSH): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_ACOSH): /* acosh: [1, +inf) */ return get_domain (1, true, true, 1, false, false); CASE_FLT_FN (BUILT_IN_ATANH): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_ATANH): /* atanh: (-1, +1) */ return get_domain (-1, true, false, 1, true, false); + case BUILT_IN_COSHF16: + case BUILT_IN_SINHF16: + /* coshf16: (-11, +11) */ + return get_domain (-11, true, false, + 11, true, false); case BUILT_IN_COSHF: case BUILT_IN_SINHF: + case BUILT_IN_COSHF32: + case BUILT_IN_SINHF32: /* coshf: (-89, +89) */ return get_domain (-89, true, false, 89, true, false); @@ -714,21 +725,39 @@ get_no_error_domain (enum built_in_funct case BUILT_IN_SINH: case BUILT_IN_COSHL: case BUILT_IN_SINHL: + case BUILT_IN_COSHF64: + case BUILT_IN_SINHF64: /* cosh: (-710, +710) */ return get_domain (-710, true, false, 710, true, false); + case BUILT_IN_COSHF128: + case BUILT_IN_SINHF128: + /* coshf128: (-11357, +11357) */ + return get_domain (-11357, true, false, + 11357, true, false); /* Log functions: (0, +inf) */ CASE_FLT_FN (BUILT_IN_LOG): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_LOG): CASE_FLT_FN (BUILT_IN_LOG2): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_LOG2): CASE_FLT_FN (BUILT_IN_LOG10): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_LOG10): return get_domain (0, true, false, 0, false, false); CASE_FLT_FN (BUILT_IN_LOG1P): + CASE_FLT_FN_FLOATN_NX (BUILT_IN_LOG1P): return get_domain (-1, true, false, 0, false, false); /* Exp functions. */ + case BUILT_IN_EXPF16: + case BUILT_IN_EXPM1F16: + /* expf: (-inf, 11) */ + return get_domain (-1, false, false, + 11, true, false); case BUILT_IN_EXPF: case BUILT_IN_EXPM1F: + case BUILT_IN_EXPF32: + case BUILT_IN_EXPM1F32: /* expf: (-inf, 88) */ return get_domain (-1, false, false, 88, true, false); @@ -736,18 +765,35 @@ get_no_error_domain (enum built_in_funct case BUILT_IN_EXPM1: case BUILT_IN_EXPL: case BUILT_IN_EXPM1L: + case BUILT_IN_EXPF64: + case BUILT_IN_EXPM1F64: /* exp: (-inf, 709) */ return get_domain (-1, false, false, 709, true, false); + case BUILT_IN_EXPF128: + case BUILT_IN_EXPM1F128: + /* expf128: (-inf, 11356) */ + return get_domain (-1, false, false, + 11356, true, false); + case BUILT_IN_EXP2F16: + /* exp2f16: (-inf, 16) */ + return get_domain (-1, false, false, + 16, true, false); case BUILT_IN_EXP2F: + case BUILT_IN_EXP2F32: /* exp2f: (-inf, 128) */ return get_domain (-1, false, false, 128, true, false); case BUILT_IN_EXP2: case BUILT_IN_EXP2L: + case BUILT_IN_EXP2F64: /* exp2: (-inf, 1024) */ return get_domain (-1, false, false, 1024, true, false); + case BUILT_IN_EXP2F128: + /* exp2f128: (-inf, 16384) */ + return get_domain (-1, false, false, + 16384, true, false); case BUILT_IN_EXP10F: case BUILT_IN_POW10F: /* exp10f: (-inf, 38) */ --- gcc/testsuite/gcc.dg/pr107547.c.jj 2022-11-07 15:01:29.836952863 +0100 +++ gcc/testsuite/gcc.dg/pr107547.c 2022-11-07 15:00:22.878866103 +0100 @@ -0,0 +1,40 @@ +/* PR tree-optimization/107547 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int x; + +void +foo (void) +{ +#define TEST(...) \ + __builtin_acos##__VA_ARGS__ (x); \ + __builtin_asin##__VA_ARGS__ (x); \ + __builtin_acosh##__VA_ARGS__ (x); \ + __builtin_atanh##__VA_ARGS__ (x); \ + __builtin_cosh##__VA_ARGS__ (x); \ + __builtin_sinh##__VA_ARGS__ (x); \ + __builtin_log##__VA_ARGS__ (x); \ + __builtin_log2##__VA_ARGS__ (x); \ + __builtin_log10##__VA_ARGS__ (x); \ + __builtin_log1p##__VA_ARGS__ (x); \ + __builtin_exp##__VA_ARGS__ (x); \ + __builtin_expm1##__VA_ARGS__ (x); \ + __builtin_exp2##__VA_ARGS__ (x); \ + __builtin_sqrt##__VA_ARGS__ (x) + TEST (f); + TEST (); + TEST (l); +#ifdef __FLT16_MAX__ + TEST (f16); +#endif +#ifdef __FLT32_MAX__ + TEST (f32); +#endif +#ifdef __FLT64_MAX__ + TEST (f64); +#endif +#ifdef __FLT128_MAX__ + TEST (f128); +#endif +}