From patchwork Wed Feb 28 17:51:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 130025 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp1820415edc; Wed, 28 Feb 2018 09:51:51 -0800 (PST) X-Google-Smtp-Source: AH8x226Nd92ihwAQcZSWgEtVQ05fxQfCIDMuS75JNT5iJUAQXDYnwOMBDwjqNlqUkguMWinltFGc X-Received: by 10.98.36.25 with SMTP id r25mr18697654pfj.106.1519840310996; Wed, 28 Feb 2018 09:51:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519840310; cv=none; d=google.com; s=arc-20160816; b=Jn1Pntr+bf03bksnst9qlauD5Q/EibMALqkLYg8X+TVq/XKxWbuHffsGOnOEp9PN3l 6nWFyDKQ6I+zKkoZ3LjLaLUhLZuaQEi79hG0gSTxsMApz5ioMT6GBUf7HPRB9HPLvg6P V9hSS3JQ0hHAqo/2U0Wx50PKZQD+m2nDtO2TwWg9rqTMmz0juNacn3eVIwJnGc1jhhNl ttGkCY0774sF3y5iHMk9+71viI5aHdTzbdvyzQQP8rjkiAia3nFc64e0y8OqaJDdBOkV InRDC5000ToRf4zYSZzpXTZEldGrwvUL5XPPrLBADd3xsmcuVoXmZP62QUmcADhcTHNa M+sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=UNuqEml/na8bXMhrsLbc7TNDGjo26/ysTd6XHmLGqek=; b=KVdrGiVdDOTyTo6RIdWcRP/oMi8zVPIyt6oQTB++QDaNjduaDz+B7Mmm1NzQA0mo4r u2dooDuGAOkeoRu3AZ4ZHV2oE5j3MotQmzFjH48UFDiz/ZwQKWnpRciFpwjB/QxTE81J eZMxKiZJz3S2lFZl4IX5C5NrU9c8n9sl3yteuolj6n0WD5yf9xOhpcXX1MZIcdHfLuZC sZEt1j/Y89hh1HsHzCezUOUt/+hBGm+8mW+6fLT17UBFqJXFSiaS22+4xlqafYFSjnfT /8p0wZFpX/4bE5GZxcimRMiGguN8KImiyTUc2uJNbLm+692R3KqV2ST8+nMOFg49NyT4 6HOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=U7cVwHrs; spf=pass (google.com: domain of gcc-patches-return-474040-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-474040-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id p11si1580396pfl.127.2018.02.28.09.51.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 09:51:50 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-474040-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=U7cVwHrs; spf=pass (google.com: domain of gcc-patches-return-474040-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-474040-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=W9GDENYO35bjisohukY0RFoGGDVVVOORj07PocITgtEb3KTWgAmQ9 fyiCksnrVLN7D97oGL227MexQ3McV+8xyVfAhNYU+f21M+EbjV3A+sdd1JSdN0Cv aRlNCmwViDh/Qea9/bt2nRqVlRVXE+cyLjHsU650kcXodAMYbgr+/4= 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=Vu7vM6rURgDWeLTgreU54xM+A8Q=; b=U7cVwHrsFy1/gbxZTDzv YUsMWn1To5Vt7YOHt+qdhD4BtdOwi6Jd38QpT2lyh1z9wRIws/4o+gjTnf0eqBoh HIHxJyVmhl+nTVCZ8A6H35uxHW79HFd6fx1xOka7I8kxqPLcZWjJlhXW/NuTqoE3 8P3OiEPVHirGWIMVXWGNa4Y= Received: (qmail 7531 invoked by alias); 28 Feb 2018 17:51:39 -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 7512 invoked by uid 89); 28 Feb 2018 17:51:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f54.google.com Received: from mail-wm0-f54.google.com (HELO mail-wm0-f54.google.com) (74.125.82.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 28 Feb 2018 17:51:37 +0000 Received: by mail-wm0-f54.google.com with SMTP id q83so6672277wme.5 for ; Wed, 28 Feb 2018 09:51:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=UNuqEml/na8bXMhrsLbc7TNDGjo26/ysTd6XHmLGqek=; b=bt5mAEg7r87YyVgDSGd8veOYl2MyiMLckBqWbOlUG7wiY1+/10dLjUzfimvmQCO+FJ uOb8ltK+KDOcfTL+1AOeqefd/haliy+yCznyZx7UzbsNT3xqawUQVzxjxHjaFScRoarD AuSU8THl1nU5Z6dMH22NeZuEvN3FzrkQ5c8XotKyOnfaaZ/+dlgL7hoEKmfHD5WcW4N6 TcZeNWcRbF4XyfyoBAUA8GZ8glDINRjHJGV9S+IKeCxUOkA2wXIgKBQ5JVPzveouQmgy dKDDQ6IpcawAXdj74ZmA5dcCmVhcZFlRo4DpWbT/vRpnKn+7BXHVkk12SEmVfLVG1I0Q Waew== X-Gm-Message-State: APf1xPBO4zdEnYPmOQAnCt9fO09Cu6vopuIQAgrfk7DbmEE0ZLMmGNaJ TOjTGPQ2GGvzgm6fyXTp3FD8AVSrXtI= X-Received: by 10.28.147.12 with SMTP id v12mr14607098wmd.139.1519840295140; Wed, 28 Feb 2018 09:51:35 -0800 (PST) Received: from localhost (94.197.120.165.threembb.co.uk. [94.197.120.165]) by smtp.gmail.com with ESMTPSA id e18sm4675587wmc.21.2018.02.28.09.51.32 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2018 09:51:33 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Tighten use of HARD_FRAME_POINTER_REGNUM in alias.c (PR 84538) Date: Wed, 28 Feb 2018 17:51:32 +0000 Message-ID: <87efl580kb.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 RTL code needs to be consistent about whether it uses the stack pointer, the frame pointer or the argument pointer to access a given part of the frame. alias.c used this to divide accesses into three independent areas. The problem in the PR is that we did this for HARD_FRAME_POINTER_REGNUM even when the register wasn't being used as a frame pointer. We can't do that because the frame pointer is then just any old allocatable register and could certainly point to info accessed through the argument pointer or stack pointer. In this case the bug triggered wrong code, but diffing the before and after assembly output for one target per CPU shows that the bug also introduced an unnecessary scheduling dependence between B and C in things like: A: (set hfp (symbol_ref "...")) B: ...(mem hfp)... C: (clobber (mem sp)) where the hard frame pointer points to something that is obviously distinct from the frame. So it looks like this patch is both a correctness fix and a very minor scheduling improvement. Tested on aarch64-linux-gnu, and by diffing output as above. OK to install? Richard 2018-02-28 Richard Sandiford gcc/ PR rtl-optimization/84538 * alias.c (init_alias_target): Add commentary. (init_alias_analysis): Only give HARD_FRAME_POINTER_REGNUM a unique base value if the frame pointer is not eliminated to the stack pointer. gcc/testsuite/ PR rtl-optimization/84538 * gcc.dg/torture/pr84538.c: New test. Index: gcc/alias.c =================================================================== --- gcc/alias.c 2018-01-14 08:42:44.497155977 +0000 +++ gcc/alias.c 2018-02-28 17:47:36.486754143 +0000 @@ -3191,12 +3191,21 @@ init_alias_target (void) && targetm.hard_regno_mode_ok (i, Pmode)) static_reg_base_value[i] = arg_base_value; + /* RTL code is required to be consistent about whether it uses the + stack pointer, the frame pointer or the argument pointer to + access a given area of the frame. We can therefore use the + base address to distinguish between the different areas. */ static_reg_base_value[STACK_POINTER_REGNUM] = unique_base_value (UNIQUE_BASE_VALUE_SP); static_reg_base_value[ARG_POINTER_REGNUM] = unique_base_value (UNIQUE_BASE_VALUE_ARGP); static_reg_base_value[FRAME_POINTER_REGNUM] = unique_base_value (UNIQUE_BASE_VALUE_FP); + + /* The above rules extend post-reload, with eliminations applying + consistently to each of the three pointers. Cope with cases in + which the frame pointer is eliminated to the hard frame pointer + rather than the stack pointer. */ if (!HARD_FRAME_POINTER_IS_FRAME_POINTER) static_reg_base_value[HARD_FRAME_POINTER_REGNUM] = unique_base_value (UNIQUE_BASE_VALUE_HFP); @@ -3329,7 +3338,14 @@ init_alias_analysis (void) /* Initialize the alias information for this pass. */ for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) - if (static_reg_base_value[i]) + if (static_reg_base_value[i] + /* Don't treat the hard frame pointer as special if we + eliminated the frame pointer to the stack pointer instead. */ + && !(i == HARD_FRAME_POINTER_REGNUM + && reload_completed + && !frame_pointer_needed + && targetm.can_eliminate (FRAME_POINTER_REGNUM, + STACK_POINTER_REGNUM))) { new_reg_base_value[i] = static_reg_base_value[i]; bitmap_set_bit (reg_seen, i); Index: gcc/testsuite/gcc.dg/torture/pr84538.c =================================================================== --- /dev/null 2018-02-26 10:26:41.624847060 +0000 +++ gcc/testsuite/gcc.dg/torture/pr84538.c 2018-02-28 17:47:36.491754008 +0000 @@ -0,0 +1,16 @@ +/* { dg-do run } */ +/* { dg-additional-options "-fno-omit-frame-pointer -w" } */ + +#define SIZE 8 + +main() +{ + int a[SIZE] = {1}; + int i; + + for (i = 1; i < SIZE; i++) + if (a[i] != 0) + abort(); + + exit (0); +}