From patchwork Wed Feb 5 01:04:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1233626 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-518920-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=OSKpHItC; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LjoC7l0F; 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 48C3Hc4DtLz9sSN for ; Wed, 5 Feb 2020 12:04:26 +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 :message-id:subject:from:reply-to:to:cc:date:mime-version :content-type; q=dns; s=default; b=dx74UuJLuJ/F5ESRfdtGz8jcmFdwK JcLQ2LtlDsNtsd5zO59nA815nLj1B6H69uPMLxxFAyAV6ulMeYYnfX0rgh1J3+dn 2kxYrpdAMcMcsevyX6KVmeyuettfJdtPGTrxS59wJ98wUh9O6SvmiI2fYBkTcj55 d5e8jsgAkslpjM= 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 :message-id:subject:from:reply-to:to:cc:date:mime-version :content-type; s=default; bh=Je96j09kVtG6t6dZQXgr75KU9tc=; b=OSK pHItC2F+qDCX0GEVh7f8wGfHMyc43ytF5awYmJRx7Cgh2o8VrEEbGpqdRFk3aR1I e1yEuAj/I+AryeIR2MZcf2IGGN2HdyCc945ZuriKM/DnXsq/pH4LtlZBGctN2/rd /rU3C38q15q0unrtTjjf+7kJfCibD4xNJYiE6zts= Received: (qmail 94040 invoked by alias); 5 Feb 2020 01:04:19 -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 94029 invoked by uid 89); 5 Feb 2020 01:04:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=accomplished, reg_qty, insert_regs, REG_QTY X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Feb 2020 01:04:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580864655; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=GREkwF2QwHiHGNbXrlHCa51YJ8CPWbOOm7eyZu8jU7Q=; b=LjoC7l0FE7zInDCPtT60Su7q1xSIXmHUKe0L3c5VmQ8bh9W/0BW00JwD0cdeF5cPmTHhQ/ XrW3lqTbfHQIZNnCwRBspD+vbZ0Hv2aQjveex/3hitsefWZ5hSno36GFg+/gcxi/elI0Ox E8hhhksZ4/jnYQfGZr3djd+afnM4c3g= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-232-nWDpWdY7Ovi4e2qS4bTEHQ-1; Tue, 04 Feb 2020 20:04:11 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2BCBB8010CB; Wed, 5 Feb 2020 01:04:10 +0000 (UTC) Received: from ovpn-117-120.phx2.redhat.com (ovpn-117-120.phx2.redhat.com [10.3.117.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id B09F71001B23; Wed, 5 Feb 2020 01:04:09 +0000 (UTC) Message-ID: Subject: [RFA] [PR rtl-optimization/90275] Handle nop reg->reg copies in cse From: Jeff Law Reply-To: law@redhat.com To: "richard.sandiford" , segher@kernel.crashing.org Cc: gcc-patches List Date: Tue, 04 Feb 2020 18:04:09 -0700 User-Agent: Evolution 3.34.3 (3.34.3-1.fc31) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes Richard & Segher, if y'all could check my analysis here, it'd be appreciated. pr90275 is a P2 regression that is only triggering on ARM. David's testcase in c#1 is the best for this problem as it doesn't require magic flags like -fno-dce to trigger. The block in question: > (code_label 89 88 90 24 15 (nil) [0 uses]) > (note 90 89 97 24 [bb 24] NOTE_INSN_BASIC_BLOCK) > (insn 97 90 98 24 (parallel [ > (set (reg:CC 100 cc) > (compare:CC (reg:SI 131 [ d_lsm.21 ]) > (const_int 0 [0]))) > (set (reg:SI 135 [ d_lsm.21 ]) > (reg:SI 131 [ d_lsm.21 ])) > ]) "pr90275.c":21:45 248 {*movsi_compare0} > (expr_list:REG_DEAD (reg:SI 131 [ d_lsm.21 ]) > (nil))) > (insn 98 97 151 24 (set (reg:SI 136 [+4 ]) > (reg:SI 132 [ d_lsm.21+4 ])) "pr90275.c":21:45 241 {*arm_movsi_insn} > (expr_list:REG_DEAD (reg:SI 132 [ d_lsm.21+4 ]) > (expr_list:REG_DEAD (reg:CC 100 cc) > (nil)))) > (insn 151 98 152 24 (set (reg:SI 131 [ d_lsm.21 ]) > (reg:SI 131 [ d_lsm.21 ])) "pr90275.c":21:45 241 {*arm_movsi_insn} > (expr_list:REG_DEAD (reg:SI 135 [ d_lsm.21 ]) > (nil))) > (insn 152 151 103 24 (set (reg:SI 132 [ d_lsm.21+4 ]) > (reg:SI 136 [+4 ])) "pr90275.c":21:45 241 {*arm_movsi_insn} > (expr_list:REG_DEAD (reg:SI 136 [+4 ]) > (nil))) > insns 97 and 151 are the most important. We process insn 97 which creates an equivalency between r135 and r131. This is expressed by putting both on on the "same_value" chain (table_elt->{next,prev}_same_value). When we put the REGs on the chain we'll set REG_QTY to a positive number which indicates their values are valid. We continue processing insns forward and run into insn 151 which is a self-copy. First CSE will invalidate r131 (because its set). Invalidation is accomplished by setting REG_QTY for r131 to a negative value. It does not remove r131 from the same value chains. Then CSE will call insert_regs for r131. The qty is not valid, so we get into this code: > if (modified || ! qty_valid) > { > if (classp) > for (classp = classp->first_same_value; > classp != 0; > classp = classp->next_same_value) > if (REG_P (classp->exp) > && GET_MODE (classp->exp) == GET_MODE (x)) > { > unsigned c_regno = REGNO (classp->exp); > > gcc_assert (REGNO_QTY_VALID_P (c_regno)); > [ ... ] So we walk the chain of same values for r131. WHen walking we run into r131 itself. Since r131 has been invalidated we trip the assert. The fix is pretty simple. We just arrange to stop processing insns that are nop reg->reg copies much like we already do for mem->mem copies and (set (pc) (pc)). This has bootstrapped and regression tested on x86_64. I've also verified it fixes the testcase in c#1 of pr90275, the test in pr93125 and pr92388. Interestingly enough I couldn't trigger the original testcase in 90275, but I'm confident this is ultimately all the same problem. OK for the trunk? Thanks, Jeff diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d6b5ded32a4..90d9f9d92d3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2020-02-04 Jeff Law + + PR rtl-optimization/90275 + * cse.c (cse_insn): Stop processing reg->reg nop moves early. + 2020-02-04 Richard Biener PR tree-optimization/93538 diff --git a/gcc/cse.c b/gcc/cse.c index 79ee0ce80e3..6e18bdae85f 100644 --- a/gcc/cse.c +++ b/gcc/cse.c @@ -5572,6 +5572,16 @@ cse_insn (rtx_insn *insn) sets[i].rtl = 0; } + /* Similarly for no-op moves. */ + if (n_sets == 1 + && GET_CODE (src) == REG + && src == dest) + { + cse_cfg_altered |= delete_insn_and_edges (insn); + /* No more processing for this set. */ + sets[i].rtl = 0; + } + /* If this SET is now setting PC to a label, we know it used to be a conditional or computed branch. */ else if (dest == pc_rtx && GET_CODE (src) == LABEL_REF diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d2dc6648bc4..7be52bd6d2a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-02-04 Jeff Law + + PR rtl-optimization/90275 + * gcc.c-torture/compile/pr90275.c: New test + 2020-02-04 David Malcolm * gcc.dg/analyzer/data-model-1.c (struct coord): Convert fields diff --git a/gcc/testsuite/gcc.c-torture/compile/pr90275.c b/gcc/testsuite/gcc.c-torture/compile/pr90275.c new file mode 100644 index 00000000000..83e0df77226 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr90275.c @@ -0,0 +1,27 @@ +a, b, c; + +long long d; + +e() { + + char f; + + for (;;) { + + c = a = c ? 5 : 0; + + if (f) { + + b = a; + + f = d; + + } + + (d || b) < (a > e) ?: (b ? 0 : f) || (d -= f); + + } + +} + +