From patchwork Wed Jun 3 06:28:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 479775 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 6D47C140295 for ; Wed, 3 Jun 2015 16:28:37 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=SAr3a5o2; 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:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=IanpK27rm9ICejblxiCa9g7DpYoL6hZskFnIFtg9NLlWFP4k/zwFq LS6c2rjUycKt+MoIIcaQ6NcFYqqeophCe68s4poqgEb+9SuekMjz5GqBI30VQrsz DgZndugXFVAFKJ9+fJW0ZRfJAFUXL4EwxUcT9lK6CYCEwZpbIjLv+0= 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:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type:content-transfer-encoding; s=default; bh=5ogR0i0R4KI99bJVL3r+1E0h73M=; b=SAr3a5o22vHToXgn2GHOwljaNjLv xpGMDll5gr4eecbYg+J5IrJqctknzq6iXwvj4/0/0e9y8H2XBZ/8rAmuma1aU+De lq+FvZ8gWhcwIKnSc/+H1kehZbkfXuUHgGTnKyZ/roEUmO57ezT6s6nyLdPjX2+G A9CrFEtbuJWSRVQ= Received: (qmail 109752 invoked by alias); 3 Jun 2015 06:28:28 -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 109742 invoked by uid 89); 3 Jun 2015 06:28:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 03 Jun 2015 06:28:25 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by uk-mta-13.uk.mimecast.lan; Wed, 03 Jun 2015 07:28:20 +0100 Received: from localhost ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 3 Jun 2015 07:28:20 +0100 From: Richard Sandiford To: Richard Henderson Mail-Followup-To: Richard Henderson , "gcc-patches\@gcc.gnu.org" , Andreas Krebbel , richard.sandiford@arm.com Cc: "gcc-patches\@gcc.gnu.org" , Andreas Krebbel Subject: Re: RFA: Fix mode checks for possibly-constant predicates In-Reply-To: <5568A761.20705@redhat.com> (Richard Henderson's message of "Fri, 29 May 2015 18:52:33 +0100") References: <87egn5yis1.fsf@e105548-lin.cambridge.arm.com> <5556DF07.6020000@linux.vnet.ibm.com> <87bnhix61c.fsf@e105548-lin.cambridge.arm.com> <555F4FCC.5020501@linux.vnet.ibm.com> <87siao38dq.fsf@e105548-lin.cambridge.arm.com> <87pp5jl2m1.fsf_-_@e105548-lin.cambridge.arm.com> <5568A761.20705@redhat.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (gnu/linux) Date: Wed, 03 Jun 2015 07:28:20 +0100 Message-ID: <87sia971bv.fsf@e105548-lin.cambridge.arm.com> MIME-Version: 1.0 X-MC-Unique: RuFRgYqYSGykOuqs52Nluw-1 Richard Henderson writes: > On 05/29/2015 10:23 AM, Richard Sandiford wrote: >> + /* Check whether the predicate accepts const scalar ints (which always >> + have a stored mode of VOIDmode, but logically have a real mode) >> + and whether it matches anything besides const scalar ints. */ >> + bool matches_const_scalar_int_p = false; >> + bool matches_other_p = false; >> + for (int i = 0; i < NUM_RTX_CODE; ++i) >> + if (p->codes[i]) >> + switch (i) >> + { >> + CASE_CONST_SCALAR_INT: >> + matches_const_scalar_int_p = true; >> + break; >> + >> + default: >> + matches_other_p = true; >> + break; >> + } >> + >> + /* There's no need for a mode check if the predicate only accepts >> + constant integers. The code checks in the predicate are enough >> + to establish that the mode is VOIDmode. >> + >> + Note that the predicate itself should check whether a scalar >> + integer is in range of the given mode. */ >> + if (!matches_other_p && !p->codes[CONST_DOUBLE]) >> + return; > > I think perhaps it would be cleaner to not use CASE_CONST_SCALAR_INT, > and then do > > switch (i) > { > case CONST_INT: > case CONST_WIDE_INT: > matches_const_scalar_int_p = true; > break; > > case CONST_DOUBLE: > if (!TARGET_SUPPORTS_WIDE_INT) > matches_const_scalar_int_p = true; > matches_other_p = true; > break; > > default: > matches_other_p = true; > break; > } > > if (!matches_other_p) > return; > > Otherwise ok. Ah, yeah, that's better. Here's what I applied after testing on x86_64-linux-gnu. Thanks, Richard gcc/ * genpreds.c (mark_mode_tests): Mark all MATCH_CODEs as NO_MODE_TEST. (add_mode_tests): Don't add mode tests if the predicate only accepts scalar constant integers. Otherwise, allow the mode of "op" to be VOIDmode if the predicate does accept such integers. Index: gcc/genpreds.c =================================================================== --- gcc/genpreds.c 2015-06-02 13:32:21.394938060 +0100 +++ gcc/genpreds.c 2015-06-02 13:34:50.377221396 +0100 @@ -218,11 +218,11 @@ needs_variable (rtx exp, const char *var /* Given an RTL expression EXP, find all subexpressions which we may assume to perform mode tests. Normal MATCH_OPERAND does; - MATCH_CODE does if it applies to the whole expression and accepts - CONST_INT or CONST_DOUBLE; and we have to assume that MATCH_TEST - does not. These combine in almost-boolean fashion - the only - exception is that (not X) must be assumed not to perform a mode - test, whether or not X does. + MATCH_CODE doesn't as such (although certain codes always have + VOIDmode); and we have to assume that MATCH_TEST does not. + These combine in almost-boolean fashion - the only exception is + that (not X) must be assumed not to perform a mode test, whether + or not X does. The mark is the RTL /v flag, which is true for subexpressions which do *not* perform mode tests. @@ -244,10 +244,7 @@ mark_mode_tests (rtx exp) break; case MATCH_CODE: - if (XSTR (exp, 1)[0] != '\0' - || (!strstr (XSTR (exp, 0), "const_int") - && !strstr (XSTR (exp, 0), "const_double"))) - NO_MODE_TEST (exp) = 1; + NO_MODE_TEST (exp) = 1; break; case MATCH_TEST: @@ -313,6 +310,40 @@ add_mode_tests (struct pred_data *p) if (p->special) return; + /* Check whether the predicate accepts const scalar ints (which always + have a stored mode of VOIDmode, but logically have a real mode) + and whether it matches anything besides const scalar ints. */ + bool matches_const_scalar_int_p = false; + bool matches_other_p = false; + for (int i = 0; i < NUM_RTX_CODE; ++i) + if (p->codes[i]) + switch (i) + { + case CONST_INT: + case CONST_WIDE_INT: + matches_const_scalar_int_p = true; + break; + + case CONST_DOUBLE: + if (!TARGET_SUPPORTS_WIDE_INT) + matches_const_scalar_int_p = true; + matches_other_p = true; + break; + + default: + matches_other_p = true; + break; + } + + /* There's no need for a mode check if the predicate only accepts + constant integers. The code checks in the predicate are enough + to establish that the mode is VOIDmode. + + Note that the predicate itself should check whether a scalar + integer is in range of the given mode. */ + if (!matches_other_p) + return; + mark_mode_tests (p->exp); /* If the whole expression already tests the mode, we're done. */ @@ -320,7 +351,11 @@ add_mode_tests (struct pred_data *p) return; match_test_exp = rtx_alloc (MATCH_TEST); - XSTR (match_test_exp, 0) = "mode == VOIDmode || GET_MODE (op) == mode"; + if (matches_const_scalar_int_p) + XSTR (match_test_exp, 0) = ("mode == VOIDmode || GET_MODE (op) == mode" + " || GET_MODE (op) == VOIDmode"); + else + XSTR (match_test_exp, 0) = "mode == VOIDmode || GET_MODE (op) == mode"; and_exp = rtx_alloc (AND); XEXP (and_exp, 1) = match_test_exp;