From patchwork Mon Mar 21 21:39:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 717 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:45:07 -0000 Delivered-To: patches@linaro.org Received: by 10.220.28.198 with SMTP id n6cs157298vcc; Mon, 21 Mar 2011 14:39:13 -0700 (PDT) Received: by 10.216.159.69 with SMTP id r47mr5460469wek.105.1300743552520; Mon, 21 Mar 2011 14:39:12 -0700 (PDT) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx.google.com with ESMTPS id u2si12144608weh.145.2011.03.21.14.39.11 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 21 Mar 2011 14:39:11 -0700 (PDT) Received-SPF: pass (google.com: domain of rdsandiford@googlemail.com designates 74.125.82.50 as permitted sender) client-ip=74.125.82.50; Authentication-Results: mx.google.com; spf=pass (google.com: domain of rdsandiford@googlemail.com designates 74.125.82.50 as permitted sender) smtp.mail=rdsandiford@googlemail.com; dkim=pass (test mode) header.i=@googlemail.com Received: by wwc33 with SMTP id 33so7949976wwc.31 for ; Mon, 21 Mar 2011 14:39:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:from:to:mail-followup-to:cc:subject:references :date:in-reply-to:message-id:user-agent:mime-version:content-type; bh=vii4bYfu3wHxmKSZiBavO8WEh9FkBoWgzVv4mtcyUyk=; b=OmiXY6t9N6rB6WVfo6AD0cUT3DY3+6zcBcXscTvGZU9Bd0TLzARkoDz3jJwWBCJNi2 rTwExAQix3+yqP9kWeSPDHJhYoZ4dFK7awcTGl7HCcHrOPwf32SJUjgDLmWLn2MyO3pA KN0VPdYDgUoxXJZUQ4zx3MovnQWvnXScMyNNA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:mail-followup-to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; b=ny6mr1Pv6azYV1tmSPv2cP1+yzNDM1ESz9DvN4xA21zaBF5JXY5m2hmAB4oiS757go iIIrlnqrsnJRQZQbPnZCbfeVNA8m+9AFkN6v4AqmyWsN3H66ByzGRm2D1Rw5SCCuhXtY PNknSGp+AIXIyfAwBzbi5w43CktGPfeEUSxvo= Received: by 10.216.54.133 with SMTP id i5mr5624198wec.23.1300743551012; Mon, 21 Mar 2011 14:39:11 -0700 (PDT) Received: from localhost (rsandifo.gotadsl.co.uk [82.133.89.107]) by mx.google.com with ESMTPS id w25sm2941940wbd.39.2011.03.21.14.39.08 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 21 Mar 2011 14:39:09 -0700 (PDT) From: Richard Sandiford To: Richard Henderson Mail-Followup-To: Richard Henderson , gcc-patches@gcc.gnu.org, patches@linaro.org, rdsandiford@googlemail.com Cc: gcc-patches@gcc.gnu.org, patches@linaro.org Subject: Re: Cleaning up expand optabs code References: <4D825EF5.1010307@redhat.com> <87wrju28hn.fsf@firetop.home> <4D87A69B.90704@redhat.com> Date: Mon, 21 Mar 2011 21:39:07 +0000 In-Reply-To: <4D87A69B.90704@redhat.com> (Richard Henderson's message of "Mon, 21 Mar 2011 12:27:23 -0700") Message-ID: <874o6ww3us.fsf@firetop.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Richard Henderson writes: >> * reload.c (find_reloads_address_1): Use insn_operand_matches. >> * reload1.c (gen_reload): Likewise. > > All the bits that just use insn_operand_matches are approved. > You can commit those first if you like to reduce the patch size. OK, thanks, here's what I applied after testing on x86_64-linux-gnu. Richard gcc/ * expr.h (prepare_operand): Move to... * optabs.h (prepare_operand): ...here and change the insn code parameter from "int" to "enum insn_code". (insn_operand_matches): Declare. * expr.c (init_expr_target): Use insn_operand_matches. (compress_float_constant): Likewise. * function.c (safe_insn_predicate, assign_parm_setup_reg): Likewise. * optabs.c (can_compare_p, prepare_cmp_insn): Likewise. (emit_cmp_and_jump_insn_1, gen_add2_insn, gen_add3_insn): Likewise. (have_add2_insn, gen_sub2_insn, gen_sub3_insn, have_sub2_insn): Likewise. (gen_cond_trap): Likewise. (prepare_operand): Likewise. Change icode to an insn_code. (insn_operand_matches): New function. * reload.c (find_reloads_address_1): Use insn_operand_matches. * reload1.c (gen_reload): Likewise. * targhooks.c (default_secondary_reload): Likewise. Index: gcc/expr.h =================================================================== --- gcc/expr.h 2011-03-21 21:35:04.000000000 +0000 +++ gcc/expr.h 2011-03-21 21:36:40.000000000 +0000 @@ -173,9 +173,6 @@ extern rtx expand_simple_unop (enum mach perform the operation described by CODE and MODE. */ extern int have_insn_for (enum rtx_code, enum machine_mode); -extern rtx prepare_operand (int, rtx, int, enum machine_mode, enum machine_mode, - int); - /* Emit code to make a call to a constant function or a library call. */ extern void emit_libcall_block (rtx, rtx, rtx, rtx); Index: gcc/optabs.h =================================================================== --- gcc/optabs.h 2011-03-21 21:35:04.000000000 +0000 +++ gcc/optabs.h 2011-03-21 21:36:40.000000000 +0000 @@ -923,4 +923,10 @@ set_direct_optab_handler (direct_optab o 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); + +extern bool insn_operand_matches (enum insn_code icode, unsigned int opno, + rtx operand); +extern rtx prepare_operand (enum insn_code, rtx, int, enum machine_mode, + enum machine_mode, int); + #endif /* GCC_OPTABS_H */ Index: gcc/expr.c =================================================================== --- gcc/expr.c 2011-03-21 21:35:04.000000000 +0000 +++ gcc/expr.c 2011-03-21 21:36:40.000000000 +0000 @@ -286,7 +286,7 @@ init_expr_target (void) PUT_MODE (mem, srcmode); - if ((*insn_data[ic].operand[1].predicate) (mem, srcmode)) + if (insn_operand_matches (ic, 1, mem)) float_extend_from_mem[mode][srcmode] = true; } } @@ -3446,7 +3446,7 @@ compress_float_constant (rtx x, rtx y) { /* Skip if the target needs extra instructions to perform the extension. */ - if (! (*insn_data[ic].operand[1].predicate) (trunc_y, srcmode)) + if (!insn_operand_matches (ic, 1, trunc_y)) continue; /* This is valid, but may not be cheaper than the original. */ newcost = rtx_cost (gen_rtx_FLOAT_EXTEND (dstmode, trunc_y), SET, speed); Index: gcc/function.c =================================================================== --- gcc/function.c 2011-03-21 21:35:04.000000000 +0000 +++ gcc/function.c 2011-03-21 21:36:40.000000000 +0000 @@ -1493,16 +1493,7 @@ instantiate_virtual_regs_in_rtx (rtx *lo static int safe_insn_predicate (int code, int operand, rtx x) { - const struct insn_operand_data *op_data; - - if (code < 0) - return true; - - op_data = &insn_data[code].operand[operand]; - if (op_data->predicate == NULL) - return true; - - return op_data->predicate (x, op_data->mode); + return code < 0 || insn_operand_matches ((enum insn_code) code, operand, x); } /* A subroutine of instantiate_virtual_regs. Instantiate any virtual @@ -3013,8 +3004,8 @@ assign_parm_setup_reg (struct assign_par op0 = parmreg; op1 = validated_mem; if (icode != CODE_FOR_nothing - && insn_data[icode].operand[0].predicate (op0, promoted_nominal_mode) - && insn_data[icode].operand[1].predicate (op1, data->passed_mode)) + && insn_operand_matches (icode, 0, op0) + && insn_operand_matches (icode, 1, op1)) { enum rtx_code code = unsignedp ? ZERO_EXTEND : SIGN_EXTEND; rtx insn, insns; Index: gcc/optabs.c =================================================================== --- gcc/optabs.c 2011-03-21 21:35:04.000000000 +0000 +++ gcc/optabs.c 2011-03-21 21:36:40.000000000 +0000 @@ -3943,15 +3943,15 @@ can_compare_p (enum rtx_code code, enum test = gen_rtx_fmt_ee (code, mode, const0_rtx, const0_rtx); do { - int icode; + enum insn_code icode; if (purpose == ccp_jump && (icode = optab_handler (cbranch_optab, mode)) != CODE_FOR_nothing - && insn_data[icode].operand[0].predicate (test, mode)) + && insn_operand_matches (icode, 0, test)) return 1; if (purpose == ccp_store_flag && (icode = optab_handler (cstore_optab, mode)) != CODE_FOR_nothing - && insn_data[icode].operand[1].predicate (test, mode)) + && insn_operand_matches (icode, 1, test)) return 1; if (purpose == ccp_cmov && optab_handler (cmov_optab, mode) != CODE_FOR_nothing) @@ -4112,16 +4112,14 @@ prepare_cmp_insn (rtx x, rtx y, enum rtx enum insn_code icode; icode = optab_handler (cbranch_optab, cmp_mode); if (icode != CODE_FOR_nothing - && insn_data[icode].operand[0].predicate (test, VOIDmode)) + && insn_operand_matches (icode, 0, test)) { rtx last = get_last_insn (); rtx op0 = prepare_operand (icode, x, 1, mode, cmp_mode, unsignedp); rtx op1 = prepare_operand (icode, y, 2, mode, cmp_mode, unsignedp); if (op0 && op1 - && insn_data[icode].operand[1].predicate - (op0, insn_data[icode].operand[1].mode) - && insn_data[icode].operand[2].predicate - (op1, insn_data[icode].operand[2].mode)) + && insn_operand_matches (icode, 1, op0) + && insn_operand_matches (icode, 2, op1)) { XEXP (test, 0) = op0; XEXP (test, 1) = op1; @@ -4200,18 +4198,17 @@ prepare_cmp_insn (rtx x, rtx y, enum rtx that it is accepted by the operand predicate. Return the new value. */ rtx -prepare_operand (int icode, rtx x, int opnum, enum machine_mode mode, +prepare_operand (enum insn_code icode, rtx x, int opnum, enum machine_mode mode, enum machine_mode wider_mode, int unsignedp) { if (mode != wider_mode) x = convert_modes (wider_mode, mode, x, unsignedp); - if (!insn_data[icode].operand[opnum].predicate - (x, insn_data[icode].operand[opnum].mode)) + if (!insn_operand_matches (icode, opnum, x)) { if (reload_completed) return NULL_RTX; - x = copy_to_mode_reg (insn_data[icode].operand[opnum].mode, x); + x = copy_to_mode_reg (insn_data[(int) icode].operand[opnum].mode, x); } return x; @@ -4232,7 +4229,7 @@ emit_cmp_and_jump_insn_1 (rtx test, enum icode = optab_handler (cbranch_optab, optab_mode); gcc_assert (icode != CODE_FOR_nothing); - gcc_assert (insn_data[icode].operand[0].predicate (test, VOIDmode)); + gcc_assert (insn_operand_matches (icode, 0, test)); emit_jump_insn (GEN_FCN (icode) (test, XEXP (test, 0), XEXP (test, 1), label)); } @@ -4699,14 +4696,11 @@ emit_conditional_add (rtx target, enum r rtx gen_add2_insn (rtx x, rtx y) { - int icode = (int) optab_handler (add_optab, GET_MODE (x)); + enum insn_code icode = optab_handler (add_optab, GET_MODE (x)); - gcc_assert (insn_data[icode].operand[0].predicate - (x, insn_data[icode].operand[0].mode)); - gcc_assert (insn_data[icode].operand[1].predicate - (x, insn_data[icode].operand[1].mode)); - gcc_assert (insn_data[icode].operand[2].predicate - (y, insn_data[icode].operand[2].mode)); + gcc_assert (insn_operand_matches (icode, 0, x)); + gcc_assert (insn_operand_matches (icode, 1, x)); + gcc_assert (insn_operand_matches (icode, 2, y)); return GEN_FCN (icode) (x, x, y); } @@ -4717,15 +4711,12 @@ gen_add2_insn (rtx x, rtx y) rtx gen_add3_insn (rtx r0, rtx r1, rtx c) { - int icode = (int) optab_handler (add_optab, GET_MODE (r0)); + enum insn_code icode = optab_handler (add_optab, GET_MODE (r0)); if (icode == CODE_FOR_nothing - || !(insn_data[icode].operand[0].predicate - (r0, insn_data[icode].operand[0].mode)) - || !(insn_data[icode].operand[1].predicate - (r1, insn_data[icode].operand[1].mode)) - || !(insn_data[icode].operand[2].predicate - (c, insn_data[icode].operand[2].mode))) + || !insn_operand_matches (icode, 0, r0) + || !insn_operand_matches (icode, 1, r1) + || !insn_operand_matches (icode, 2, c)) return NULL_RTX; return GEN_FCN (icode) (r0, r1, c); @@ -4734,21 +4725,18 @@ gen_add3_insn (rtx r0, rtx r1, rtx c) int have_add2_insn (rtx x, rtx y) { - int icode; + enum insn_code icode; gcc_assert (GET_MODE (x) != VOIDmode); - icode = (int) optab_handler (add_optab, GET_MODE (x)); + icode = optab_handler (add_optab, GET_MODE (x)); if (icode == CODE_FOR_nothing) return 0; - if (!(insn_data[icode].operand[0].predicate - (x, insn_data[icode].operand[0].mode)) - || !(insn_data[icode].operand[1].predicate - (x, insn_data[icode].operand[1].mode)) - || !(insn_data[icode].operand[2].predicate - (y, insn_data[icode].operand[2].mode))) + if (!insn_operand_matches (icode, 0, x) + || !insn_operand_matches (icode, 1, x) + || !insn_operand_matches (icode, 2, y)) return 0; return 1; @@ -4759,14 +4747,11 @@ have_add2_insn (rtx x, rtx y) rtx gen_sub2_insn (rtx x, rtx y) { - int icode = (int) optab_handler (sub_optab, GET_MODE (x)); + enum insn_code icode = optab_handler (sub_optab, GET_MODE (x)); - gcc_assert (insn_data[icode].operand[0].predicate - (x, insn_data[icode].operand[0].mode)); - gcc_assert (insn_data[icode].operand[1].predicate - (x, insn_data[icode].operand[1].mode)); - gcc_assert (insn_data[icode].operand[2].predicate - (y, insn_data[icode].operand[2].mode)); + gcc_assert (insn_operand_matches (icode, 0, x)); + gcc_assert (insn_operand_matches (icode, 1, x)); + gcc_assert (insn_operand_matches (icode, 2, y)); return GEN_FCN (icode) (x, x, y); } @@ -4777,15 +4762,12 @@ gen_sub2_insn (rtx x, rtx y) rtx gen_sub3_insn (rtx r0, rtx r1, rtx c) { - int icode = (int) optab_handler (sub_optab, GET_MODE (r0)); + enum insn_code icode = optab_handler (sub_optab, GET_MODE (r0)); if (icode == CODE_FOR_nothing - || !(insn_data[icode].operand[0].predicate - (r0, insn_data[icode].operand[0].mode)) - || !(insn_data[icode].operand[1].predicate - (r1, insn_data[icode].operand[1].mode)) - || !(insn_data[icode].operand[2].predicate - (c, insn_data[icode].operand[2].mode))) + || !insn_operand_matches (icode, 0, r0) + || !insn_operand_matches (icode, 1, r1) + || !insn_operand_matches (icode, 2, c)) return NULL_RTX; return GEN_FCN (icode) (r0, r1, c); @@ -4794,21 +4776,18 @@ gen_sub3_insn (rtx r0, rtx r1, rtx c) int have_sub2_insn (rtx x, rtx y) { - int icode; + enum insn_code icode; gcc_assert (GET_MODE (x) != VOIDmode); - icode = (int) optab_handler (sub_optab, GET_MODE (x)); + icode = optab_handler (sub_optab, GET_MODE (x)); if (icode == CODE_FOR_nothing) return 0; - if (!(insn_data[icode].operand[0].predicate - (x, insn_data[icode].operand[0].mode)) - || !(insn_data[icode].operand[1].predicate - (x, insn_data[icode].operand[1].mode)) - || !(insn_data[icode].operand[2].predicate - (y, insn_data[icode].operand[2].mode))) + if (!insn_operand_matches (icode, 0, x) + || !insn_operand_matches (icode, 1, x) + || !insn_operand_matches (icode, 2, y)) return 0; return 1; @@ -6643,8 +6622,7 @@ gen_cond_trap (enum rtx_code code, rtx o return 0; /* Some targets only accept a zero trap code. */ - if (insn_data[icode].operand[3].predicate - && !insn_data[icode].operand[3].predicate (tcode, VOIDmode)) + if (!insn_operand_matches (icode, 3, tcode)) return 0; do_pending_stack_adjust (); @@ -7329,5 +7307,16 @@ expand_sync_lock_test_and_set (rtx mem, return NULL_RTX; } + +/* Return true if OPERAND is suitable for operand number OPNO of + instruction ICODE. */ + +bool +insn_operand_matches (enum insn_code icode, unsigned int opno, rtx operand) +{ + return (!insn_data[(int) icode].operand[opno].predicate + || (insn_data[(int) icode].operand[opno].predicate + (operand, insn_data[(int) icode].operand[opno].mode))); +} #include "gt-optabs.h" Index: gcc/reload.c =================================================================== --- gcc/reload.c 2011-03-21 21:35:04.000000000 +0000 +++ gcc/reload.c 2011-03-21 21:36:40.000000000 +0000 @@ -5819,17 +5819,15 @@ #define REG_OK_FOR_CONTEXT(CONTEXT, REGN rtx equiv = (MEM_P (XEXP (x, 0)) ? XEXP (x, 0) : reg_equiv_mem[regno]); - int icode = (int) optab_handler (add_optab, GET_MODE (x)); + enum insn_code icode = optab_handler (add_optab, GET_MODE (x)); if (insn && NONJUMP_INSN_P (insn) && equiv && memory_operand (equiv, GET_MODE (equiv)) #ifdef HAVE_cc0 && ! sets_cc0_p (PATTERN (insn)) #endif && ! (icode != CODE_FOR_nothing - && ((*insn_data[icode].operand[0].predicate) - (equiv, GET_MODE (x))) - && ((*insn_data[icode].operand[1].predicate) - (equiv, GET_MODE (x))))) + && insn_operand_matches (icode, 0, equiv) + && insn_operand_matches (icode, 1, equiv))) { /* We use the original pseudo for loc, so that emit_reload_insns() knows which pseudo this Index: gcc/reload1.c =================================================================== --- gcc/reload1.c 2011-03-21 21:35:04.000000000 +0000 +++ gcc/reload1.c 2011-03-21 21:36:40.000000000 +0000 @@ -8479,7 +8479,7 @@ gen_reload (rtx out, rtx in, int opnum, not valid than to dummy things up. */ rtx op0, op1, tem, insn; - int code; + enum insn_code code; op0 = find_replacement (&XEXP (in, 0)); op1 = find_replacement (&XEXP (in, 1)); @@ -8517,14 +8517,13 @@ gen_reload (rtx out, rtx in, int opnum, DEFINE_PEEPHOLE should be specified that recognizes the sequence we emit below. */ - code = (int) optab_handler (add_optab, GET_MODE (out)); + code = optab_handler (add_optab, GET_MODE (out)); if (CONSTANT_P (op1) || MEM_P (op1) || GET_CODE (op1) == SUBREG || (REG_P (op1) && REGNO (op1) >= FIRST_PSEUDO_REGISTER) || (code != CODE_FOR_nothing - && ! ((*insn_data[code].operand[2].predicate) - (op1, insn_data[code].operand[2].mode)))) + && !insn_operand_matches (code, 2, op1))) tem = op0, op0 = op1, op1 = tem; gen_reload (out, op0, opnum, type); Index: gcc/targhooks.c =================================================================== --- gcc/targhooks.c 2011-03-21 21:35:04.000000000 +0000 +++ gcc/targhooks.c 2011-03-21 21:36:40.000000000 +0000 @@ -893,8 +893,7 @@ default_secondary_reload (bool in_p ATTR reload_mode); if (icode != CODE_FOR_nothing - && insn_data[(int) icode].operand[in_p].predicate - && ! insn_data[(int) icode].operand[in_p].predicate (x, reload_mode)) + && !insn_operand_matches (icode, in_p, x)) icode = CODE_FOR_nothing; else if (icode != CODE_FOR_nothing) {