From patchwork Mon Apr 4 15:02:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Schmidt X-Patchwork-Id: 605896 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qdwT00g4rz9sC4 for ; Tue, 5 Apr 2016 01:12:19 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=v1XHJ1bk; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:content-transfer-encoding; q=dns; s= default; b=thG+1vExWtGslragBZ75z8LRypSeS/BouS1EAK3ggGqU8u7ArfiZN qPedM1Wa1WvqsHYJlDM88a/hqB85fR3TvgP22dsQiK0L1q5nlyEVW8wh2QTnN31B RxL+Pk7o3esgCFLis8kRferjA5ST/sBgYU5Oey+8tOzZfPlWThVY9U= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:content-transfer-encoding; s=default; bh=T22q1fdmlXYzA68ZXZ7MfNIaS7g=; b=v1XHJ1bktdP6mcpKJTUYEFHpEtQn U0sqQUCMXeH4vAgBuhpAUXBVFJBhLf6XE+J1s4nWHnwwkeHajUODw3co8T8yMmCr Z1TLuqjh+zHuFRDIbsDJ+DpuzCi4XkQlKGGA21i7JPFE/Ina7C3NDFFmJvKa4lzE JLD66rjckOYMGek= Received: (qmail 8403 invoked by alias); 4 Apr 2016 15:12:09 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 8388 invoked by uid 89); 4 Apr 2016 15:12:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=AWL, BAYES_50, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=formerly, iced, U*wschmidt, p_pow X-HELO: e36.co.us.ibm.com Received: from e36.co.us.ibm.com (HELO e36.co.us.ibm.com) (32.97.110.154) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Mon, 04 Apr 2016 15:12:07 +0000 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 4 Apr 2016 09:12:04 -0600 Received: from d03dlp01.boulder.ibm.com (9.17.202.177) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 4 Apr 2016 09:12:02 -0600 X-IBM-Helo: d03dlp01.boulder.ibm.com X-IBM-MailFrom: wschmidt@linux.vnet.ibm.com X-IBM-RcptTo: gcc-patches@gcc.gnu.org Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id 70D57C404F8 for ; Mon, 4 Apr 2016 08:50:59 -0600 (MDT) Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u34F2oRN34472022 for ; Mon, 4 Apr 2016 15:02:50 GMT Received: from d01av01.pok.ibm.com (localhost [127.0.0.1]) by d01av01.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u34F2o6G019452 for ; Mon, 4 Apr 2016 11:02:50 -0400 Received: from [9.77.154.91] (sig-9-77-154-91.ibm.com [9.77.154.91]) by d01av01.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u34F2jLL018802; Mon, 4 Apr 2016 11:02:45 -0400 Subject: Re: [PATCH] Fix PR70457 (ICE on incompatible call to built-in pow) From: Bill Schmidt To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org In-Reply-To: <20160404065739.GA19207@tucnak.redhat.com> References: <1459727027.6430.52.camel@oc8801110288.ibm.com> <20160404065739.GA19207@tucnak.redhat.com> Date: Mon, 04 Apr 2016 10:02:44 -0500 Message-ID: <1459782164.6430.64.camel@oc8801110288.ibm.com> Mime-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16040415-0021-0000-0000-00002CB125C1 X-IsSubscribed: yes Hi Jakub, Sorry again for the misunderstanding. Here are revised patches and change logs for trunk, GCC 5, and GCC 4.9. Note that GCC 5 and GCC 4.9 have additional exposures in tree-ssa-math-opts.c that I've repaired similarly. The only differences between 5 and 4.9 are the names of the affected functions. All have passed regstrap on powerpc64le-unknown-linux-gnu. Are these ok? Thanks, Bill Trunk ===== [gcc] 2016-04-04 Bill Schmidt Jakub Jelinek PR middle-end/70457 * tree-inline.c (estimate_num_insn): Use gimple_call_builtin_p to ensure a call statement is compatible with a built-in's prototype. * tree-ssa-math-opts.c (pass_optimize_windening_mul::execute): Likewise. [gcc/testsuite] 2016-04-04 Bill Schmidt Jakub Jelinek PR middle-end/70457 * gcc.dg/torture/pr70457.c: New. Index: gcc/testsuite/gcc.dg/torture/pr70457.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr70457.c (revision 0) +++ gcc/testsuite/gcc.dg/torture/pr70457.c (working copy) @@ -0,0 +1,32 @@ +/* { dg-do compile } */ + +/* This formerly ICEd when trying to expand pow as a built-in with + the wrong number of arguments. */ + +extern double pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__)); +extern double __pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__)); + +typedef int int64_t __attribute__ ((__mode__ (__DI__))); + +typedef struct { + int64_t data; + int tag; +} Object; + +extern Object Make_Flonum (double); +extern Object P_Pow (Object, Object); + +Object General_Function (Object x, Object y, double (*fun)()) { + double d, ret; + + d = 1.0; + + if (y.tag >> 1) + ret = (*fun) (d); + else + ret = (*fun) (d, 0.0); + + return Make_Flonum (ret); +} + +Object P_Pow (Object x, Object y) { return General_Function (x, y, pow); } Index: gcc/tree-inline.c =================================================================== --- gcc/tree-inline.c (revision 234702) +++ gcc/tree-inline.c (working copy) @@ -4065,7 +4065,7 @@ estimate_num_insns (gimple *stmt, eni_weights *wei return 0; else if (is_inexpensive_builtin (decl)) return weights->target_builtin_call_cost; - else if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL) + else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) { /* We canonicalize x * x to pow (x, 2.0) with -ffast-math, so specialize the cheap expansion we do here. Index: gcc/tree-ssa-math-opts.c =================================================================== --- gcc/tree-ssa-math-opts.c (revision 234702) +++ gcc/tree-ssa-math-opts.c (working copy) @@ -3827,7 +3827,7 @@ pass_optimize_widening_mul::execute (function *fun { tree fndecl = gimple_call_fndecl (stmt); if (fndecl - && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL) + && gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) { switch (DECL_FUNCTION_CODE (fndecl)) { GCC 5 ===== [gcc] 2016-04-04 Bill Schmidt Jakub Jelinek PR middle-end/70457 * tree-inline.c (estimate_num_insn): Use gimple_call_builtin_p to ensure a call statement is compatible with a built-in's prototype. * tree-ssa-math-opts.c (execute_cse_sincos_1): Likewise. (pass_cse_sincos::execute): Likewise. (pass_optimize_widening_mul::execute): Likewise. [gcc/testsuite] 2016-04-04 Bill Schmidt Jakub Jelinek PR middle-end/70457 * gcc.dg/torture/pr70457.c: New. Index: gcc/testsuite/gcc.dg/torture/pr70457.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr70457.c (revision 0) +++ gcc/testsuite/gcc.dg/torture/pr70457.c (working copy) @@ -0,0 +1,32 @@ +/* { dg-do compile } */ + +/* This formerly ICEd when trying to expand pow as a built-in with + the wrong number of arguments. */ + +extern double pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__)); +extern double __pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__)); + +typedef int int64_t __attribute__ ((__mode__ (__DI__))); + +typedef struct { + int64_t data; + int tag; +} Object; + +extern Object Make_Flonum (double); +extern Object P_Pow (Object, Object); + +Object General_Function (Object x, Object y, double (*fun)()) { + double d, ret; + + d = 1.0; + + if (y.tag >> 1) + ret = (*fun) (d); + else + ret = (*fun) (d, 0.0); + + return Make_Flonum (ret); +} + +Object P_Pow (Object x, Object y) { return General_Function (x, y, pow); } Index: gcc/tree-inline.c =================================================================== --- gcc/tree-inline.c (revision 234705) +++ gcc/tree-inline.c (working copy) @@ -4111,7 +4111,7 @@ estimate_num_insns (gimple stmt, eni_weights *weig return 0; else if (is_inexpensive_builtin (decl)) return weights->target_builtin_call_cost; - else if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL) + else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) { /* We canonicalize x * x to pow (x, 2.0) with -ffast-math, so specialize the cheap expansion we do here. Index: gcc/tree-ssa-math-opts.c =================================================================== --- gcc/tree-ssa-math-opts.c (revision 234705) +++ gcc/tree-ssa-math-opts.c (working copy) @@ -769,7 +769,7 @@ execute_cse_sincos_1 (tree name) if (gimple_code (use_stmt) != GIMPLE_CALL || !gimple_call_lhs (use_stmt) || !(fndecl = gimple_call_fndecl (use_stmt)) - || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL) + || !gimple_call_builtin_p (use_stmt, BUILT_IN_NORMAL)) continue; switch (DECL_FUNCTION_CODE (fndecl)) @@ -1488,7 +1488,7 @@ pass_cse_sincos::execute (function *fun) if (is_gimple_call (stmt) && gimple_call_lhs (stmt) && (fndecl = gimple_call_fndecl (stmt)) - && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL) + && gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) { tree arg, arg0, arg1, result; HOST_WIDE_INT n; @@ -3339,7 +3339,7 @@ pass_optimize_widening_mul::execute (function *fun { tree fndecl = gimple_call_fndecl (stmt); if (fndecl - && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL) + && gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) { switch (DECL_FUNCTION_CODE (fndecl)) { GCC 4.9 ======= [gcc] 2016-04-04 Bill Schmidt Jakub Jelinek PR middle-end/70457 * tree-inline.c (estimate_num_insn): Use gimple_call_builtin_p to ensure a call statement is compatible with a built-in's prototype. * tree-ssa-math-opts.c (execute_cse_sincos_1): Likewise. (execute_cse_sincos): Likewise. (execute_optimize_widening_mul): Likewise. [gcc/testsuite] 2016-04-04 Bill Schmidt Jakub Jelinek PR middle-end/70457 * gcc.dg/torture/pr70457.c: New. Index: gcc/testsuite/gcc.dg/torture/pr70457.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr70457.c (revision 0) +++ gcc/testsuite/gcc.dg/torture/pr70457.c (working copy) @@ -0,0 +1,32 @@ +/* { dg-do compile } */ + +/* This formerly ICEd when trying to expand pow as a built-in with + the wrong number of arguments. */ + +extern double pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__)); +extern double __pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__)); + +typedef int int64_t __attribute__ ((__mode__ (__DI__))); + +typedef struct { + int64_t data; + int tag; +} Object; + +extern Object Make_Flonum (double); +extern Object P_Pow (Object, Object); + +Object General_Function (Object x, Object y, double (*fun)()) { + double d, ret; + + d = 1.0; + + if (y.tag >> 1) + ret = (*fun) (d); + else + ret = (*fun) (d, 0.0); + + return Make_Flonum (ret); +} + +Object P_Pow (Object x, Object y) { return General_Function (x, y, pow); } Index: gcc/tree-inline.c =================================================================== --- gcc/tree-inline.c (revision 234702) +++ gcc/tree-inline.c (working copy) @@ -3850,7 +3850,7 @@ estimate_num_insns (gimple stmt, eni_weights *weig return 0; else if (is_inexpensive_builtin (decl)) return weights->target_builtin_call_cost; - else if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL) + else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) { /* We canonicalize x * x to pow (x, 2.0) with -ffast-math, so specialize the cheap expansion we do here. Index: gcc/tree-ssa-math-opts.c =================================================================== --- gcc/tree-ssa-math-opts.c (revision 234702) +++ gcc/tree-ssa-math-opts.c (working copy) @@ -746,7 +746,7 @@ execute_cse_sincos_1 (tree name) if (gimple_code (use_stmt) != GIMPLE_CALL || !gimple_call_lhs (use_stmt) || !(fndecl = gimple_call_fndecl (use_stmt)) - || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL) + || !gimple_call_builtin_p (use_stmt, BUILT_IN_NORMAL)) continue; switch (DECL_FUNCTION_CODE (fndecl)) @@ -1437,7 +1437,7 @@ execute_cse_sincos (void) if (is_gimple_call (stmt) && gimple_call_lhs (stmt) && (fndecl = gimple_call_fndecl (stmt)) - && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL) + && gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) { tree arg, arg0, arg1, result; HOST_WIDE_INT n; @@ -2860,7 +2860,7 @@ execute_optimize_widening_mul (void) { tree fndecl = gimple_call_fndecl (stmt); if (fndecl - && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL) + && gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) { switch (DECL_FUNCTION_CODE (fndecl)) {