From patchwork Mon Sep 24 12:49:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 186395 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]) by ozlabs.org (Postfix) with SMTP id 6A63A2C0086 for ; Mon, 24 Sep 2012 22:53:29 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1349096009; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=XhdPsqMVcNqoVe5w7Erf I7tKRhs=; b=L2yuT1L/XxFd2ygp2pD1JW3IVeflOvfeVCTrGm3Dx1MzmhhfCm0T qAXItT4NhTCbRbywusd7bncynH6dP55iW+oJZ/H4Zc/wmWsfcWoJMLRyzY2z7GhN a2dXMWP7urCH6nFC68gIYKrr5M092nRLIof0NNeWcS3VWZuVoSTuYU0= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Date:From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=rIMdl3JLtUTemjjdI3TkPNziAdJYhLLaiCi8N+aAT/XZjxWPHVR7zZyCmZ9aYI tj7nWNQM6VHLx7End10xXUBmcB19aHlgdFAEvi340rIejs8Wv9hU+u0qCcIlAZlz /KTyt0Wxgt40VVoIICOYw8aVhvcNvKz+N8CHC1PtBsQFs=; Received: (qmail 2512 invoked by alias); 24 Sep 2012 12:53:21 -0000 Received: (qmail 2499 invoked by uid 22791); 24 Sep 2012 12:53:20 -0000 X-SWARE-Spam-Status: No, hits=-5.8 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, TW_TM X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 24 Sep 2012 12:53:07 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id DE4DBA329D for ; Mon, 24 Sep 2012 14:53:05 +0200 (CEST) Date: Mon, 24 Sep 2012 14:49:59 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR54684 Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 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 This fixes PR54684 where optimizing __builtin_unreachable () during builtin folding fails to update SSA operands properly. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2012-09-24 Richard Guenther PR tree-optimization/54684 * tree-ssa-ccp.c (optimize_unreachable): Properly update stmts. * g++.dg/torture/pr54684.C: New testcase. Index: gcc/tree-ssa-ccp.c =================================================================== --- gcc/tree-ssa-ccp.c (revision 191664) +++ gcc/tree-ssa-ccp.c (working copy) @@ -2355,6 +2355,7 @@ optimize_unreachable (gimple_stmt_iterat gimple_cond_make_true (stmt); else gcc_unreachable (); + update_stmt (stmt); } else { Index: gcc/testsuite/g++.dg/torture/pr54684.C =================================================================== --- gcc/testsuite/g++.dg/torture/pr54684.C (revision 0) +++ gcc/testsuite/g++.dg/torture/pr54684.C (working copy) @@ -0,0 +1,62 @@ +// { dg-do compile } + +typedef union tree_node *tree; +typedef union gimple_statement_d *gimple; +struct vec_prefix { unsigned num_; }; +template struct vec_t { + unsigned length (void) const; + T &operator[] (unsigned); + vec_prefix prefix_; + T vec_[1]; +}; +template inline unsigned vec_t::length (void) const { + return prefix_.num_; +} +template T & vec_t::operator[] (unsigned ix) { + ((void)(__builtin_expect(!(ix < prefix_.num_), 0) ? __builtin_unreachable(), 0 : 0)); + return vec_[ix]; +} +enum tree_code { PARM_DECL }; +struct tree_base { + enum tree_code code : 16; + unsigned default_def_flag : 1; +}; +union tree_node { + struct tree_base base; +}; +struct ipa_param_descriptor { + tree decl; + unsigned used : 1; +}; +typedef struct ipa_param_descriptor ipa_param_descriptor_t; +struct ipa_node_params { + vec_t *descriptors; +}; +static inline int ipa_get_param_count (struct ipa_node_params *info) { + return ((info->descriptors) ? (info->descriptors)->length () : 0); +} +static inline tree ipa_get_param (struct ipa_node_params *info, int i) { + return ((*(info->descriptors))[i]).decl; +} +static inline void ipa_set_param_used (struct ipa_node_params *info, int i, bool val) { + ((*(info->descriptors))[i]).used = val; +} +int ipa_get_param_decl_index (struct ipa_node_params *info, tree ptree) +{ + int i, count; + count = ipa_get_param_count (info); + for (i = 0; i < count; i++) + if (ipa_get_param (info, i) == ptree) return i; + return -1; +} +bool visit_ref_for_mod_analysis (gimple stmt __attribute__ ((__unused__)), + tree op, void *data) +{ + struct ipa_node_params *info = (struct ipa_node_params *) data; + if (op && ((enum tree_code) (op)->base.code) == PARM_DECL) + { + int index = ipa_get_param_decl_index (info, op); + ((void)(__builtin_expect(!(index >= 0), 0) ? __builtin_unreachable(), 0 : 0)); + ipa_set_param_used (info, index, true); + } +}