From patchwork Thu Sep 19 12:16:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1164555 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-509263-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="kNFq3axz"; 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 46YwnV6KDFz9sNk for ; Thu, 19 Sep 2019 22:16:45 +1000 (AEST) 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:subject:message-id:mime-version:content-type; q=dns; s= default; b=c8O2T+N5PKgAWeSm9eYTAJCkdDUZMVNPXqCGATVx0LL2RANW/WYAz abI6yunVl/09YddV1Vy/UvYzcX3lw17UjZ5XujbgU3tyhEUSh37rgWHoaKTA29j0 1dLmS4xPajvLqclkFRxsopFzBEJlWHDQdoN5afAwLhQN8MNA1YNWTU= 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:subject:message-id:mime-version:content-type; s= default; bh=mRG83hcEHskILpUoe+J8FGniBFU=; b=kNFq3axzKA6Uun7II6GY FNbDx3k/mY/VJr3OKh1fAGSSvwBO1yAb9MgW8NISKCaCB/tJ47x0NjOrd69tHvJs vJtZcTLeQCSJrkUpbHyGoa/qPRg+16WIZG824JDgYVs3EHx1vb69Ot9ulWSfPjcs er3o8jlCZSmv+tJsOXUQC4g= Received: (qmail 48269 invoked by alias); 19 Sep 2019 12:16:37 -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 48260 invoked by uid 89); 19 Sep 2019 12:16:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.1 spammy=sk:gimple X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Sep 2019 12:16:36 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1E500AF9C for ; Thu, 19 Sep 2019 12:16:34 +0000 (UTC) Date: Thu, 19 Sep 2019 14:16:33 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR91812 Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2019-09-19 Richard Biener PR tree-optimization/91812 * tree-ssa-phiprop.c (propagate_with_phi): Do not replace volatile loads. * gcc.dg/torture/pr91812.c: New testcase. Index: gcc/tree-ssa-phiprop.c =================================================================== --- gcc/tree-ssa-phiprop.c (revision 275698) +++ gcc/tree-ssa-phiprop.c (working copy) @@ -338,8 +338,15 @@ propagate_with_phi (basic_block bb, gphi && (!type || types_compatible_p (TREE_TYPE (gimple_assign_lhs (use_stmt)), type)) - /* We cannot replace a load that may throw or is volatile. */ - && !stmt_can_throw_internal (cfun, use_stmt))) + /* We cannot replace a load that may throw or is volatile. + For volatiles the transform can change the number of + executions if the load is inside a loop but the address + computations outside (PR91812). We could relax this + if we guard against that appropriately. For loads that can + throw we could relax things if the moved loads all are + known to not throw. */ + && !stmt_can_throw_internal (cfun, use_stmt) + && !gimple_has_volatile_ops (use_stmt))) continue; /* Check if we can move the loads. The def stmt of the virtual use Index: gcc/testsuite/gcc.dg/torture/pr91812.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr91812.c (nonexistent) +++ gcc/testsuite/gcc.dg/torture/pr91812.c (working copy) @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-optimized-blocks" } */ + +unsigned register1; +unsigned register2; + +void busy_wait_for_register (int x) +{ + volatile unsigned* ptr; + switch(x) { + case 0x1111: + ptr = ®ister1; + break; + + case 0x2222: + ptr = ®ister2; + break; + + default: + return; + } + while (*ptr) {} +} + +/* { dg-final { scan-tree-dump "loop depth 1" "optimized" } } */