From patchwork Wed Sep 5 21:10:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 181957 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]) by ozlabs.org (Postfix) with SMTP id 2DDC62C0093 for ; Thu, 6 Sep 2012 07:10:23 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1347484224; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:Date:Message-ID:Subject:From:To: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=2xitdgl xfd5VdNv+sA1qKBSqKGo=; b=CCqr4Bei4ijhmEgsi/KRYt9R494+ZVSHQaES3zv q6SKp3tXfNPDWtO3wDChTw6LuYXwq9yC8aQbkpFWaBi9y1GCJqbXw6iRJm5+cfGO FTsvyoFGmPeJZdc0P8o0LYzEjW0wh64iQ+f0TqgG68DQHaopAug8gM3gv9g0hTKL xoSk= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=rUdWpSiALLGDOwPDyZFxXhFRtBjycov55dLL2+HiVLP0HjpmorP0WhF8biN2r2 Lz5cFeq3YiQ3sS48G49+zkgsonG385JZZvJsGMeP54apLYbysmdP5OACuyeoO1r1 MVc2TuzyNEcipcBmqZX087OXCBDVltM3PhXEPkNsg1dEw=; Received: (qmail 5848 invoked by alias); 5 Sep 2012 21:10:19 -0000 Received: (qmail 5827 invoked by uid 22791); 5 Sep 2012 21:10:17 -0000 X-SWARE-Spam-Status: No, hits=-4.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-wi0-f169.google.com (HELO mail-wi0-f169.google.com) (209.85.212.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 05 Sep 2012 21:10:05 +0000 Received: by wibhm2 with SMTP id hm2so4745464wib.2 for ; Wed, 05 Sep 2012 14:10:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.131.196 with SMTP id m46mr8807216wei.35.1346879403812; Wed, 05 Sep 2012 14:10:03 -0700 (PDT) Received: by 10.216.2.4 with HTTP; Wed, 5 Sep 2012 14:10:03 -0700 (PDT) Date: Wed, 5 Sep 2012 14:10:03 -0700 Message-ID: Subject: [PATCH] Fix PR 54494, removal of volatile store in strlen optimization From: Andrew Pinski To: GCC Patches , Jakub Jelinek X-IsSubscribed: yes 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 Hi, The problem here is the strlen optimization tries to remove a null character store as we already have done it but it does it for a volatile store which is not a valid thing to do. This patch fixes the problem by ignoring statements which have volatile operands. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Thanks, Andrew Pinski ChangeLog: * tree-ssa-strlen.c (strlen_optimize_stmt): Don't look at statements which have volatile operands. testsuite/ChangeLog: * gcc.dg/tree-ssa/strlen-1.c: New testcase. Index: gcc/tree-ssa-strlen.c =================================================================== --- gcc/tree-ssa-strlen.c (revision 190993) +++ gcc/tree-ssa-strlen.c (working copy) @@ -1782,7 +1782,8 @@ strlen_optimize_stmt (gimple_stmt_iterat break; } } - else if (is_gimple_assign (stmt)) + else if (is_gimple_assign (stmt) + && !gimple_has_volatile_ops (stmt)) { tree lhs = gimple_assign_lhs (stmt); Index: gcc/testsuite/gcc.dg/tree-ssa/strlen-1.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/strlen-1.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/strlen-1.c (revision 0) @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +extern const unsigned long base; +static inline void wreg(unsigned char val, unsigned long addr) __attribute__((always_inline)); +static inline void wreg(unsigned char val, unsigned long addr) +{ + *((volatile unsigned char *) (__SIZE_TYPE__) (base + addr)) = val; +} +void wreg_twice(void) +{ + wreg(0, 42); + wreg(0, 42); +} + +/* We should not remove the second null character store to (base+42) address. */ +/* { dg-final { scan-tree-dump-times " ={v} 0;" 2 "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */