From patchwork Sat Jun 4 21:21:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 98745 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 EAEDBB6FC3 for ; Sun, 5 Jun 2011 07:22:09 +1000 (EST) Received: (qmail 18750 invoked by alias); 4 Jun 2011 21:22:07 -0000 Received: (qmail 18728 invoked by uid 22791); 4 Jun 2011 21:22:06 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RFC_ABUSE_POST X-Spam-Check-By: sourceware.org Received: from mail-wy0-f175.google.com (HELO mail-wy0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 04 Jun 2011 21:21:52 +0000 Received: by wye20 with SMTP id 20so2495655wye.20 for ; Sat, 04 Jun 2011 14:21:51 -0700 (PDT) Received: by 10.227.55.139 with SMTP id u11mr3304668wbg.37.1307222511274; Sat, 04 Jun 2011 14:21:51 -0700 (PDT) Received: from localhost (rsandifo.gotadsl.co.uk [82.133.89.107]) by mx.google.com with ESMTPS id ex2sm1858936wbb.31.2011.06.04.14.21.48 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 04 Jun 2011 14:21:49 -0700 (PDT) From: Richard Sandiford To: Eric Botcazou Mail-Followup-To: Eric Botcazou , gcc-patches@gcc.gnu.org, rdsandiford@googlemail.com Cc: gcc-patches@gcc.gnu.org Subject: Re: PR 49145: Another (zero_extend (const_int ...)) in combine References: <877h9ahflh.fsf@firetop.home> <201106012220.49874.ebotcazou@adacore.com> Date: Sat, 04 Jun 2011 22:21:44 +0100 In-Reply-To: <201106012220.49874.ebotcazou@adacore.com> (Eric Botcazou's message of "Wed, 1 Jun 2011 22:20:49 +0200") Message-ID: <87oc2dmgwn.fsf@firetop.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) 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 Eric Botcazou writes: > SUBREG and ZERO_EXTEND of CONST_INTs are treated somewhat specially in the > entire file, see for example do_SUBST. This isn't the case for other unary > operators, presumably because this isn't really necessary here. So I'm not > convinced that such a generalization is really a good thing in this case. OK. The version below just adds a special case tomake_compound_operation instead. As before, I've restricted the simplification to constants, so that we don't inadvertently undo the effects of m_c_o itself. Tested on x86_64-linux-gnu and mips-linux-gnu. OK for trunk? Richard gcc/ PR rtl-optimization/49145 * combine.c (make_compound_operation): Handle ZERO_EXTEND specially. gcc/testsuite/ PR rtl-optimization/49145 From Ryan Mansfield * gcc.c-torture/compile/pr49145.c: New test. Index: gcc/combine.c =================================================================== --- gcc/combine.c 2011-06-01 22:09:09.000000000 +0100 +++ gcc/combine.c 2011-06-01 22:09:26.000000000 +0100 @@ -7881,7 +7881,20 @@ make_compound_operation (rtx x, enum rtx code = GET_CODE (x); } - /* Now recursively process each operand of this operation. */ + /* Now recursively process each operand of this operation. We need to + handle ZERO_EXTEND specially so that we don't lose track of the + inner mode. */ + if (GET_CODE (x) == ZERO_EXTEND) + { + new_rtx = make_compound_operation (XEXP (x, 0), next_code); + tem = simplify_const_unary_operation (ZERO_EXTEND, GET_MODE (x), + new_rtx, GET_MODE (XEXP (x, 0))); + if (tem) + return tem; + SUBST (XEXP (x, 0), new_rtx); + return x; + } + fmt = GET_RTX_FORMAT (code); for (i = 0; i < GET_RTX_LENGTH (code); i++) if (fmt[i] == 'e') Index: gcc/testsuite/gcc.c-torture/compile/pr49145.c =================================================================== --- /dev/null 2011-06-04 08:47:56.158317425 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr49145.c 2011-06-01 22:09:26.000000000 +0100 @@ -0,0 +1,30 @@ +static int +func1 (int a, int b) +{ + return b ? a : a / b; +} + +static unsigned char +func2 (unsigned char a, int b) +{ + return b ? a : b; +} + +int i; + +void +func3 (const int arg) +{ + for (i = 0; i != 10; i = foo ()) + { + if (!arg) + { + int j; + for (j = 0; j < 5; j += 1) + { + int *ptr; + *ptr = func2 (func1 (arg, *ptr), foo (arg)); + } + } + } +}