From patchwork Fri May 22 15:42:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 475694 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 2E586140E33 for ; Sat, 23 May 2015 01:42:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=LQXagRxb; 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:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=dXECpdg4gtzlwYOH 35/FeX6UOxDyN/UZsDCF7uYWLI/Az7sKxiqtuYjCpNmczi4zc4m2LAy82EuyrSeL w+1XFosFW4AgqosohVB9U8bMnjH9UR8hvkuJ/s3YblG2NXsAmMV1IzbGJMA08hBP Emdy79LaQB5diCppScKQVcgX7EI= 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:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=sZsvWMc+fuFKSudTiSlJcX hJ258=; b=LQXagRxb61OekgYSAdf24Yitwko9eThjOlhopP+p8nuJoRqkUfN4eo rDUAs42Aqc876J9wxjw5dl+6jx005lM3gq6Y9qBTOpne22785pmOXYXh8KV/eGnd 94GkEnKFHeykUVPQgHoY+PedwMsWBPl7/aVQSWcQJHss7NdiEk8jo= Received: (qmail 76985 invoked by alias); 22 May 2015 15:42:49 -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 76974 invoked by uid 89); 22 May 2015 15:42:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=no 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) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 22 May 2015 15:42:47 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by uk-mta-24.uk.mimecast.lan; Fri, 22 May 2015 16:42:44 +0100 Received: from localhost ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 22 May 2015 16:42:44 +0100 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Reuse predicate code analysis for constraints Date: Fri, 22 May 2015 16:42:44 +0100 Message-ID: <87382o4o0b.fsf@e105548-lin.cambridge.arm.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-MC-Unique: wU4ss1zrRkKH8_wKx3twqw-1 This patch adjusts the fix for PR target/65689 along the lines suggested in https://gcc.gnu.org/ml/gcc-patches/2015-04/msg01559.html. The idea is to reuse the existing gensupport.c routine to work out the codes accepted by constraints. I'd originally done this with an eye to using compute_test_codes for the problem that Andreas found on s390. I don't think it's going to be useful for that after all, but it seems worth having for its on sake. Bootstrapped & regression-tested on x86_64-linux-gnu. OK to install? Thanks, Richard gcc/ * gensupport.h (compute_test_codes): Declare. * gensupport.c (compute_predicate_codes): Rename to... (compute_test_codes): ...this. Generalize error message. (process_define_predicate): Update accordingly. * genpreds.c (compute_maybe_allows): Delete. (add_constraint): Use compute_test_codes to determine whether something can accept a SUBREG, REG or MEM. Index: gcc/gensupport.h =================================================================== --- gcc/gensupport.h 2015-05-21 08:45:32.663464769 +0100 +++ gcc/gensupport.h 2015-05-21 08:45:33.015460604 +0100 @@ -109,5 +109,6 @@ struct pattern_stats }; extern void get_pattern_stats (struct pattern_stats *ranges, rtvec vec); +extern void compute_test_codes (rtx, int, char *); #endif /* GCC_GENSUPPORT_H */ Index: gcc/gensupport.c =================================================================== --- gcc/gensupport.c 2015-05-21 08:45:32.663464769 +0100 +++ gcc/gensupport.c 2015-05-21 08:51:12.667438995 +0100 @@ -204,8 +204,8 @@ #define TRISTATE_NOT(a) \ predicate expression EXP, writing the result to CODES. LINENO is the line number on which the directive containing EXP appeared. */ -static void -compute_predicate_codes (rtx exp, int lineno, char codes[NUM_RTX_CODE]) +void +compute_test_codes (rtx exp, int lineno, char *codes) { char op0_codes[NUM_RTX_CODE]; char op1_codes[NUM_RTX_CODE]; @@ -215,29 +215,29 @@ compute_predicate_codes (rtx exp, int li switch (GET_CODE (exp)) { case AND: - compute_predicate_codes (XEXP (exp, 0), lineno, op0_codes); - compute_predicate_codes (XEXP (exp, 1), lineno, op1_codes); + compute_test_codes (XEXP (exp, 0), lineno, op0_codes); + compute_test_codes (XEXP (exp, 1), lineno, op1_codes); for (i = 0; i < NUM_RTX_CODE; i++) codes[i] = TRISTATE_AND (op0_codes[i], op1_codes[i]); break; case IOR: - compute_predicate_codes (XEXP (exp, 0), lineno, op0_codes); - compute_predicate_codes (XEXP (exp, 1), lineno, op1_codes); + compute_test_codes (XEXP (exp, 0), lineno, op0_codes); + compute_test_codes (XEXP (exp, 1), lineno, op1_codes); for (i = 0; i < NUM_RTX_CODE; i++) codes[i] = TRISTATE_OR (op0_codes[i], op1_codes[i]); break; case NOT: - compute_predicate_codes (XEXP (exp, 0), lineno, op0_codes); + compute_test_codes (XEXP (exp, 0), lineno, op0_codes); for (i = 0; i < NUM_RTX_CODE; i++) codes[i] = TRISTATE_NOT (op0_codes[i]); break; case IF_THEN_ELSE: /* a ? b : c accepts the same codes as (a & b) | (!a & c). */ - compute_predicate_codes (XEXP (exp, 0), lineno, op0_codes); - compute_predicate_codes (XEXP (exp, 1), lineno, op1_codes); - compute_predicate_codes (XEXP (exp, 2), lineno, op2_codes); + compute_test_codes (XEXP (exp, 0), lineno, op0_codes); + compute_test_codes (XEXP (exp, 1), lineno, op1_codes); + compute_test_codes (XEXP (exp, 2), lineno, op2_codes); for (i = 0; i < NUM_RTX_CODE; i++) codes[i] = TRISTATE_OR (TRISTATE_AND (op0_codes[i], op1_codes[i]), TRISTATE_AND (TRISTATE_NOT (op0_codes[i]), @@ -321,7 +321,7 @@ compute_predicate_codes (rtx exp, int li default: error_with_line (lineno, - "'%s' cannot be used in a define_predicate expression", + "'%s' cannot be used in predicates or constraints", GET_RTX_NAME (GET_CODE (exp))); memset (codes, I, NUM_RTX_CODE); break; @@ -373,7 +373,7 @@ process_define_predicate (rtx desc, int if (GET_CODE (desc) == DEFINE_SPECIAL_PREDICATE) pred->special = true; - compute_predicate_codes (XEXP (desc, 1), lineno, codes); + compute_test_codes (XEXP (desc, 1), lineno, codes); for (i = 0; i < NUM_RTX_CODE; i++) if (codes[i] != N) Index: gcc/genpreds.c =================================================================== --- gcc/genpreds.c 2015-05-21 08:45:32.663464769 +0100 +++ gcc/genpreds.c 2015-05-21 08:45:33.015460604 +0100 @@ -716,34 +716,6 @@ mangle (const char *name) return XOBFINISH (rtl_obstack, const char *); } -/* Return a bitmask, bit 1 if EXP maybe allows a REG/SUBREG, 2 if EXP - maybe allows a MEM. Bits should be clear only when we are sure it - will not allow a REG/SUBREG or a MEM. */ -static int -compute_maybe_allows (rtx exp) -{ - switch (GET_CODE (exp)) - { - case IF_THEN_ELSE: - /* Conservative answer is like IOR, of the THEN and ELSE branches. */ - return compute_maybe_allows (XEXP (exp, 1)) - | compute_maybe_allows (XEXP (exp, 2)); - case AND: - return compute_maybe_allows (XEXP (exp, 0)) - & compute_maybe_allows (XEXP (exp, 1)); - case IOR: - return compute_maybe_allows (XEXP (exp, 0)) - | compute_maybe_allows (XEXP (exp, 1)); - case MATCH_CODE: - if (*XSTR (exp, 1) == '\0') - return (strstr (XSTR (exp, 0), "reg") != NULL ? 1 : 0) - | (strstr (XSTR (exp, 0), "mem") != NULL ? 2 : 0); - /* FALLTHRU */ - default: - return 3; - } -} - /* Add one constraint, of any sort, to the tables. NAME is its name; REGCLASS is the register class, if any; EXP is the expression to test, if any; IS_MEMORY and IS_ADDRESS indicate memory and address @@ -899,12 +871,17 @@ add_constraint (const char *name, const c->is_extra = !(regclass || is_const_int || is_const_dbl); c->is_memory = is_memory; c->is_address = is_address; - int maybe_allows = 3; + c->maybe_allows_reg = true; + c->maybe_allows_mem = true; if (exp) - maybe_allows = compute_maybe_allows (exp); - c->maybe_allows_reg = (maybe_allows & 1) != 0; - c->maybe_allows_mem = (maybe_allows & 2) != 0; - + { + char codes[NUM_RTX_CODE]; + compute_test_codes (exp, lineno, codes); + if (!codes[REG] && !codes[SUBREG]) + c->maybe_allows_reg = false; + if (!codes[MEM]) + c->maybe_allows_mem = false; + } c->next_this_letter = *slot; *slot = c;