From patchwork Thu Jan 11 18:32:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 859233 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-470863-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CO+fjxLG"; dkim-atps=neutral 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 3zHZJ93ctqz9s7M for ; Fri, 12 Jan 2018 05:33:11 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=llZ71uR7D8N6XXUvkEimSCLqCGmC0 TTcnAD/4OpL2RvE5N5SCP0Nlc+uX+gUCschGvHb7ULOGLTqKuUFdiDGCV8i00YDs Nwxn6nFbbUTTbyI1jPQrKZ/KgkW5S6ul3izeGINsRZY1EKkl8vUKTvBvTO5ynFee bTofoubn3aKgeM= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=1cpLWfhTL7CtroPST/ypgf7+AmM=; b=CO+ fjxLGdBM+GzITisbiEB3LKS6v/iK7Jet44PO2QNc74oxOuxO/72n7nk25mBDSxX7 0krzpDVQxteAseHFAoHeYMnjILZKa6YYlelYaLpYQIEtG1XOy1BGaFbkMQb2s3q4 dc5SNWtc2gQeujUrtPsJKulbkP5C7bkoSexa4GDQ= Received: (qmail 32394 invoked by alias); 11 Jan 2018 18:33:04 -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 31980 invoked by uid 89); 11 Jan 2018 18:33:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 11 Jan 2018 18:33:02 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BE649356E3 for ; Thu, 11 Jan 2018 18:32:55 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-37.ams2.redhat.com [10.36.116.37]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 00974944B9; Thu, 11 Jan 2018 18:32:52 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w0BIWnTw008586; Thu, 11 Jan 2018 19:32:50 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w0BIWmvd008585; Thu, 11 Jan 2018 19:32:48 +0100 Date: Thu, 11 Jan 2018 19:32:48 +0100 From: Jakub Jelinek To: Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Small REE improvement (PR target/82682) Message-ID: <20180111183248.GU1833@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) X-IsSubscribed: yes Hi! As mentioned in this PR, we have effectively: (set (reg2) (expression)) ... (set (reg1) (reg2)) ... (set (reg2) (any_extend (reg1))) in pr50083.c with -O2 -m32, where the expression in this case is actually a QImode memory read has any_extend is zero extension to SImode. Currently REE tries to change that to just (set (reg2) (any_extend (reg2))) ... (set (reg1) (reg2)) which for one isn't useful, and fails because reg2 is %si which doesn't have a QImode subreg in 32-bit code. This patch instead sees the copying of the reg2 to reg1 as def_insn and in that case looks further for the defining insn of that (def_insn2) and transforms it thus to: (set (reg2) (any_extend (expression)) ... (set (reg1) (reg2)) // This insn is untouched, stays in the // mode it used before, but can be DCEd // later if the reg isn't really used Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? No testcase included, as it fixes an existing one: -FAIL: gcc.target/i386/pr50038.c scan-assembler-times movzbl 2 (found 3 times) 2018-01-11 Jakub Jelinek PR target/82682 * ree.c (combine_reaching_defs): Optimize also reg2=exp; reg1=reg2; reg2=any_extend(reg1); into reg2=any_extend(exp); reg1=reg2;, formatting fix. Jakub --- gcc/ree.c.jj 2018-01-04 00:43:17.635703232 +0100 +++ gcc/ree.c 2018-01-11 11:37:10.312822260 +0100 @@ -901,7 +901,7 @@ combine_reaching_defs (ext_cand *cand, c REGNO (SET_DEST (pat))); emit_move_insn (new_dst, new_src); - rtx_insn *insn = get_insns(); + rtx_insn *insn = get_insns (); end_sequence (); if (NEXT_INSN (insn)) return false; @@ -910,8 +910,81 @@ combine_reaching_defs (ext_cand *cand, c extract_insn (insn); if (!constrain_operands (1, get_preferred_alternatives (insn, bb))) return false; - } + while (REG_P (SET_SRC (*dest_sub_rtx)) + && (REGNO (SET_SRC (*dest_sub_rtx)) == REGNO (SET_DEST (pat)))) + { + /* Considering transformation of + (set (reg2) (expression)) + ... + (set (reg1) (reg2)) + ... + (set (reg2) (any_extend (reg1))) + + into + + (set (reg2) (any_extend (expression))) + (set (reg1) (reg2)) + ... */ + struct df_link *defs + = get_defs (def_insn, SET_SRC (*dest_sub_rtx), NULL); + if (defs == NULL || defs->next) + break; + + /* There is only one reaching def. */ + rtx_insn *def_insn2 = DF_REF_INSN (defs->ref); + + /* The defining statement must not have been modified either. */ + if (state->modified[INSN_UID (def_insn2)].kind != EXT_MODIFIED_NONE) + break; + + /* The def_insn2 and candidate insn must be in the same + block and def_insn follows def_insn2. */ + if (bb != BLOCK_FOR_INSN (def_insn2) + || DF_INSN_LUID (def_insn2) > DF_INSN_LUID (def_insn)) + break; + + rtx *dest_sub_rtx2 = get_sub_rtx (def_insn2); + if (dest_sub_rtx2 == NULL + || !REG_P (SET_DEST (*dest_sub_rtx2))) + break; + + /* On RISC machines we must make sure that changing the mode of + SRC_REG as destination register will not affect its reaching + uses, which may read its value in a larger mode because DEF_INSN + implicitly sets it in word mode. */ + if (WORD_REGISTER_OPERATIONS && known_lt (prec, BITS_PER_WORD)) + { + struct df_link *uses = get_uses (def_insn2, SET_DEST (pat)); + if (!uses) + break; + + df_link *use; + rtx dest2 = SET_DEST (*dest_sub_rtx2); + for (use = uses; use; use = use->next) + if (paradoxical_subreg_p (GET_MODE (*DF_REF_LOC (use->ref)), + GET_MODE (dest2))) + break; + if (use) + break; + } + + /* The destination register of the extension insn must not be + used or set between the def_insn2 and def_insn exclusive. + Likewise for the other reg, i.e. check both reg1 and reg2 + in the above comment. */ + if (reg_used_between_p (SET_DEST (PATTERN (cand->insn)), + def_insn2, def_insn) + || reg_set_between_p (SET_DEST (PATTERN (cand->insn)), + def_insn2, def_insn) + || reg_used_between_p (src_reg, def_insn2, def_insn) + || reg_set_between_p (src_reg, def_insn2, def_insn)) + break; + + state->defs_list[0] = def_insn2; + break; + } + } /* If cand->insn has been already modified, update cand->mode to a wider mode if possible, or punt. */