From patchwork Wed Jan 22 12:11:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1227209 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-518015-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.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=V1VS8i50; 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 482klR57VSz9sP6 for ; Wed, 22 Jan 2020 23:11:15 +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:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=T2tf30tFiUEQt/O8C7kBmIhOd8jhxwU+AFNMX8D7r1YhMqBXYVxmo izadHNSMvnNozi5y0JrY4Yat/ZkFJnxb24FCPjxqT9xkk74djux2ihLrjWhFL1GE AkRgimFKmf+jIyUM2Ppq/aitxvRNVoQJnLOpBT1cxlDfQOOBq9NSRw= 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; s= default; bh=I3CROXYQJtTUuU3mqcASLGLL9QM=; b=V1VS8i50fvCd43jveOBF etb6e1x0K0jD6J0Q8ChUDfL5/bvcOjB8ECbiTmE4bUOamiAxc3saasS9R78N3U+l dWm1RN3Hkq5ohIJE/L37U8s2Dre/Uz2pxqm180/AD6O4iQxYNkKt3/IufbD39e39 fRvpY8CER4Ucgxi5VgggVg4= Received: (qmail 66763 invoked by alias); 22 Jan 2020 12:11:07 -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 66752 invoked by uid 89); 22 Jan 2020 12:11:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 spammy=s.a, sa X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 Jan 2020 12:11:06 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 92CA9328 for ; Wed, 22 Jan 2020 04:11:04 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3C1853F52E for ; Wed, 22 Jan 2020 04:11:04 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH] auto-inc-dec: Don't add incs/decs to bare CLOBBERs [PR93124] Date: Wed, 22 Jan 2020 12:11:03 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes In this PR, auto-inc-dec was trying to turn: (set (reg X) (plus (reg X) (const_int N))) (clobber (mem (reg X))) into: (clobber (mem (pre_modify (reg X) ...))) But bare clobber insns are just there to describe dataflow. They're not supposed to generate any code. This is part 2 of the fix for PR93124. The reason we have the clobber above is that cprop replaced (reg sp) with (reg X) in: (clobber (mem (reg sp))) Part 1 stops that from happening, but I still think we should prevent auto-inc-dec from "optimising" bare USEs and CLOBBERs as a belt-and-braces fix. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard 2020-01-22 Richard Sandiford gcc/ PR rtl-optimization/93124 * auto-inc-dec.c (merge_in_block): Don't add auto inc/decs to bare USE and CLOBBER insns. gcc/testsuite/ * gcc.dg/torture/pr93124.c: New test. --- gcc/auto-inc-dec.c | 12 +++++-- gcc/testsuite/gcc.dg/torture/pr93124.c | 44 ++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr93124.c diff --git a/gcc/auto-inc-dec.c b/gcc/auto-inc-dec.c index 268231ecaff..7d0d91403f3 100644 --- a/gcc/auto-inc-dec.c +++ b/gcc/auto-inc-dec.c @@ -1602,9 +1602,15 @@ merge_in_block (int max_reg, basic_block bb) else { insn_is_add_or_inc = false; - mem_insn.insn = insn; - if (find_mem (&PATTERN (insn))) - success_in_block++; + /* We can't use auto inc/dec for bare USEs and CLOBBERs, + since they aren't supposed to generate any code. */ + rtx_code code = GET_CODE (PATTERN (insn)); + if (code != USE && code != CLOBBER) + { + mem_insn.insn = insn; + if (find_mem (&PATTERN (insn))) + success_in_block++; + } } /* If the inc insn was merged with a mem, the inc insn is gone diff --git a/gcc/testsuite/gcc.dg/torture/pr93124.c b/gcc/testsuite/gcc.dg/torture/pr93124.c new file mode 100644 index 00000000000..16bc8b54f14 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr93124.c @@ -0,0 +1,44 @@ +/* { dg-additional-options "-fno-rerun-cse-after-loop -fno-guess-branch-probability -fno-tree-fre" } */ + +int x; + +void fn2 (); +void fn3 (); +void fn4 (); +void fn5 (); +void fn6 (); + +void +fn1 (void) +{ + int n; + for (n = 0;; ++n) { + { + struct { char a[n]; } s; + fn2 (s); + } + struct { unsigned a[x]; } s; + int i, b; + for (i = 0; i < n; ++i) + ; + fn2 (s); + { + struct { char a[n]; } s; + int i; + for (i = 0; i < n; ++i) + s.a[i] = i; + fn3 (s, s); + } + fn4 (); + { + struct { unsigned a[n]; } s; + fn5 (s); + } + { + struct { char a[b]; } s; + for (; i < n;) + s.a[i] = i; + fn6 (s); + } + } +}