From patchwork Thu Apr 27 07:32:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 755842 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 3wD7w654gmz9s4s for ; Thu, 27 Apr 2017 17:33:10 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="d2ioHuju"; 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=PZZzP7WqUbaxJe+caCwZEQjWsMsG1 ripwsFR4Bfk+PVnsdGOna9kGGg1YK9Cwrnjvg+h/P28lVaVi2zFfRhvYqaLpLnXi twPRA0DW1jrWZvx+4mFmo1nOr+cCgLamuhFmcL0yCNLwK1DuzyjkZWkODy1FCoEZ gETAhmCW/5mWK0= 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=bcElk1Y3T4KiV9AS14uSHU6u/+o=; b=d2i oHuju+BsKpncTwc+3i+qCEWStGtbn2iTlOD8aDjZjGqxXtAgnKpDyl9+WgdgxOd3 DH3bF1Kzxsk/NVwEFMuxQfzIUQt1+xlwo0fRjIwDLmAoZyS78RtRky9CxzrNueF1 eO9V0ZVj7uUr2VCfCyIZc7QJ3yDep/7R0HpXDewc= Received: (qmail 18142 invoked by alias); 27 Apr 2017 07:32:58 -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 18126 invoked by uid 89); 27 Apr 2017 07:32:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-16.9 required=5.0 tests=BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=tons 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, 27 Apr 2017 07:32:56 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1338A7F3E1; Thu, 27 Apr 2017 07:32:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1338A7F3E1 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1338A7F3E1 Received: from tucnak.zalov.cz (ovpn-116-29.ams2.redhat.com [10.36.116.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 89C5F171B2; Thu, 27 Apr 2017 07:32:55 +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 v3R7WqiM028860; Thu, 27 Apr 2017 09:32:52 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v3R7WoVt028859; Thu, 27 Apr 2017 09:32:50 +0200 Date: Thu, 27 Apr 2017 09:32:50 +0200 From: Jakub Jelinek To: Richard Biener , Jeff Law , Eric Botcazou , Uros Bizjak Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Check for sp push/pop insns in reg_set_p (PR target/79430) Message-ID: <20170427073250.GW1809@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! As mentioned in the PR and can be seen on the testcase (too large for testsuite, with lots of delta reduction I got 48KB *.f90 file still using a dozen of modules), we miscompile it because we have mem(sp+64) memory (what %st is loaded from) and are checking whether it is safe to move earlier in the insn stream, and modified_between_p tells us it is, except there is a stack pop instruction (i.e. sp autoinc). And sp autoinc is apparently special in GCC: /* There are no REG_INC notes for SP. */ /* Cannot handle auto inc of the stack. */ if (inc_reg == stack_pointer_rtx) etc. - it is present even on targets that have AUTO_INC_DEC 0 (like i?86/x86_64), don't have REG_INC notes etc. reg_set_p currently has: /* We can be passed an insn or part of one. If we are passed an insn, check if a side-effect of the insn clobbers REG. */ if (INSN_P (insn) && (FIND_REG_INC_NOTE (insn, reg) so it handles insns with REG_INC notes fine, but doesn't know about the SP special case. The following patch handles that, plus then undoes that in ix86_agi_dependent where from what I understood we want the previous behavior - push, pop and call modifications of SP don't cause AGI stalls for addresses that have SP base (SP can't appear as index). Not really sure about the == stack_pointer_rtx vs. REG_P () && REGNO () == STACK_POINTER_REGNUM, there is lots of code that just uses pointer comparisons and others that check REGNO, as an example of the former e.g. push/pop_operand. So, is SP always shared, or can there be other REGs with SP regno? Other than the ix86_agi_dependent which in my stats was the single case that hit this difference, I've seen it making a difference e.g. in ifcvt decisions, but at least the cases I've debugged didn't end up in any code generation changes. E.g. both x86_64 and i686 libstdc++.so.6 and libgo.so.11 as the two largest shared libraries built during bootstrap are identical without/with this patch (objdump -dr is identical that is). While without the config/i386/i386.c changes there were tons of differences. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-04-27 Jakub Jelinek PR target/79430 * rtlanal.c (reg_set_p): If reg is a stack_pointer_rtx, also check for stack push/pop autoinc. * config/i386/i386.c (ix86_agi_dependent): Return false if the only reason why modified_in_p returned true is that addr is SP based and set_insn is a push or pop. Jakub --- gcc/rtlanal.c.jj 2017-04-26 12:11:04.019878187 +0200 +++ gcc/rtlanal.c 2017-04-26 17:48:14.131705330 +0200 @@ -1221,6 +1221,24 @@ reg_set_p (const_rtx reg, const_rtx insn || find_reg_fusage (insn, CLOBBER, reg))))) return true; + /* There are no REG_INC notes for SP autoinc. */ + if (reg == stack_pointer_rtx && INSN_P (insn)) + { + subrtx_var_iterator::array_type array; + FOR_EACH_SUBRTX_VAR (iter, array, PATTERN (insn), NONCONST) + { + rtx mem = *iter; + if (mem + && MEM_P (mem) + && GET_RTX_CLASS (GET_CODE (XEXP (mem, 0))) == RTX_AUTOINC) + { + if (XEXP (XEXP (mem, 0), 0) == stack_pointer_rtx) + return true; + iter.skip_subrtxes (); + } + } + } + return set_of (reg, insn) != NULL_RTX; } --- gcc/config/i386/i386.c.jj 2017-04-26 17:48:01.108877052 +0200 +++ gcc/config/i386/i386.c 2017-04-26 17:50:44.890717389 +0200 @@ -29243,7 +29243,27 @@ ix86_agi_dependent (rtx_insn *set_insn, if (MEM_P (recog_data.operand[i])) { rtx addr = XEXP (recog_data.operand[i], 0); - return modified_in_p (addr, set_insn) != 0; + if (modified_in_p (addr, set_insn) != 0) + { + /* No AGI stall if SET_INSN is a push or pop and USE_INSN + has SP based memory (unless index reg is modified in a pop). */ + rtx set = single_set (set_insn); + if (set + && (push_operand (SET_DEST (set), GET_MODE (SET_DEST (set))) + || pop_operand (SET_SRC (set), GET_MODE (SET_SRC (set))))) + { + struct ix86_address parts; + if (ix86_decompose_address (addr, &parts) + && REG_P (parts.base) + && REGNO (parts.base) == STACK_POINTER_REGNUM + && (parts.index == NULL_RTX + || MEM_P (SET_DEST (set)) + || !modified_in_p (parts.index, set_insn))) + return false; + } + return true; + } + return false; } return false; }