From patchwork Mon Mar 5 11:47:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 144666 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 51089B6EF3 for ; Mon, 5 Mar 2012 22:48:01 +1100 (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=1331552885; 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=rFL3oQSGgrF+H8XC7Uc9 5KziCOY=; b=IV7lUb8OwZ8xt5zrZM/9JV+UhsbLeXElymn5ML/YSM5b3iPGtRAo oQkRvRRDjMHCt4wEGvCWBmGCu51uuwYEJ8TDfDccJGQ6YNHX91fqL48RorhD3D6/ S8LhnaAa9v7mx63hIbdRKoDgXkwTsu6+iXBYiu2V+z4KhIhItZ9Tqzs= 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=YdlC52EU6DQTx/Tpg6FZkHcO6hd2SEW15A6v384DxCzpO8f/8IETWpV5o3R15z 5lI9EywNmv8Cjdf1kbaM+sfLUQxynghGeeoN3Qt7ZViL4ytxQNoYB6qYhw+iiyBA f9Buccqzh24NG1TxTNPLV6cm8UuZ/l1SjqHpgAkBAx3ys=; Received: (qmail 10937 invoked by alias); 5 Mar 2012 11:47:57 -0000 Received: (qmail 10928 invoked by uid 22791); 5 Mar 2012 11:47:56 -0000 X-SWARE-Spam-Status: No, hits=-5.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, TW_EG, T_RP_MATCHES_RCVD 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, 05 Mar 2012 11:47:42 +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 4EB638BB22 for ; Mon, 5 Mar 2012 12:47:41 +0100 (CET) Date: Mon, 5 Mar 2012 12:47:41 +0100 (CET) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH][1/N] Preserve loop structures from tree loop to RTL loop optimizers 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 patch fixes PR52353 towards a point we no longer ICE. We fail to properly treat -ftrapv operations (or rather their libcall block) as trapping after RTL expansion because we simply check may_trap_p on the REG_EQUAL note. The following patch re-arranges emit_libcall_block to take an additional argument overriding that result properly. The testcase is still miscompiled later by RTL DCE, I'll open a bug for that once this patch is in. Thus, no testcase, but it avoids an existing one from ICEing after preserving loops over RTL expansion. The new predicates will help fixing PR52478 as well (trying a fix now). Bootstrap and regtest pending on x86_64-unknown-linux-gnu. Richard. 2012-03-05 Richard Guenther PR middle-end/52353 * optabs.h (trapv_unoptab_p): New function. (trapv_binoptab_p): Likewise. * optabs.c (expand_binop): Use emit_libcall_block_1 with a proper equiv_may_trap argument. (expand_unop): Likewise. (emit_libcall_block_1): Take extra argument whether the instruction may trap. Renamed from ... (emit_libcall_block): ... this. New wrapper. Index: gcc/optabs.h =================================================================== --- gcc/optabs.h (revision 184918) +++ gcc/optabs.h (working copy) @@ -1103,6 +1103,25 @@ set_direct_optab_handler (direct_optab o op->handlers[(int) mode].insn_code = (int) code - (int) CODE_FOR_nothing; } +/* Return true if UNOPTAB is for a trapping-on-overflow operation. */ + +static inline bool +trapv_unoptab_p (optab unoptab) +{ + return (unoptab == negv_optab + || unoptab == absv_optab); +} + +/* Return true if BINOPTAB is for a trapping-on-overflow operation. */ + +static inline bool +trapv_binoptab_p (optab binoptab) +{ + return (binoptab == addv_optab + || binoptab == subv_optab + || binoptab == smulv_optab); +} + extern rtx optab_libfunc (optab optab, enum machine_mode mode); extern rtx convert_optab_libfunc (convert_optab optab, enum machine_mode mode1, enum machine_mode mode2); Index: gcc/optabs.c =================================================================== --- gcc/optabs.c (revision 184918) +++ gcc/optabs.c (working copy) @@ -60,6 +60,7 @@ optab code_to_optab[NUM_RTX_CODE + 1]; static void prepare_float_lib_cmp (rtx, rtx, enum rtx_code, rtx *, enum machine_mode *); static rtx expand_unop_direct (enum machine_mode, optab, rtx, rtx, int); +static void emit_libcall_block_1 (rtx, rtx, rtx, rtx, bool); /* Debug facility for use in GDB. */ void debug_optab_libfuncs (void); @@ -2115,8 +2116,9 @@ expand_binop (enum machine_mode mode, op end_sequence (); target = gen_reg_rtx (mode); - emit_libcall_block (insns, target, value, - gen_rtx_fmt_ee (binoptab->code, mode, op0, op1)); + emit_libcall_block_1 (insns, target, value, + gen_rtx_fmt_ee (binoptab->code, mode, op0, op1), + trapv_binoptab_p (binoptab)); return target; } @@ -3197,7 +3199,8 @@ expand_unop (enum machine_mode mode, opt eq_value = simplify_gen_unary (TRUNCATE, outmode, eq_value, mode); else if (GET_MODE_SIZE (outmode) > GET_MODE_SIZE (mode)) eq_value = simplify_gen_unary (ZERO_EXTEND, outmode, eq_value, mode); - emit_libcall_block (insns, target, value, eq_value); + emit_libcall_block_1 (insns, target, value, eq_value, + trapv_unoptab_p (unoptab)); return target; } @@ -3775,8 +3778,9 @@ no_conflict_move_test (rtx dest, const_r an insn to move RESULT to TARGET. This last insn will have a REQ_EQUAL note with an operand of EQUIV. */ -void -emit_libcall_block (rtx insns, rtx target, rtx result, rtx equiv) +static void +emit_libcall_block_1 (rtx insns, rtx target, rtx result, rtx equiv, + bool equiv_may_trap) { rtx final_dest = target; rtx next, last, insn; @@ -3789,7 +3793,8 @@ emit_libcall_block (rtx insns, rtx targe /* If we're using non-call exceptions, a libcall corresponding to an operation that may trap may also trap. */ /* ??? See the comment in front of make_reg_eh_region_note. */ - if (cfun->can_throw_non_call_exceptions && may_trap_p (equiv)) + if (cfun->can_throw_non_call_exceptions + && (equiv_may_trap || may_trap_p (equiv))) { for (insn = insns; insn; insn = NEXT_INSN (insn)) if (CALL_P (insn)) @@ -3870,6 +3875,12 @@ emit_libcall_block (rtx insns, rtx targe if (final_dest != target) emit_move_insn (final_dest, target); } + +void +emit_libcall_block (rtx insns, rtx target, rtx result, rtx equiv) +{ + emit_libcall_block_1 (insns, target, result, equiv, false); +} /* Nonzero if we can perform a comparison of mode MODE straightforwardly. PURPOSE describes how this comparison will be used. CODE is the rtx