From patchwork Tue Sep 4 07:20:08 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 181506 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 8DC222C008B for ; Tue, 4 Sep 2012 17:20:34 +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=1347348035; 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=Tl9fwA9 icGnsUBVQq4jI2JUx5TQ=; b=u/JcpCdq8LhEUskLAZHw4FPL0iIx85gET2bqn08 AFZ9PJ6eQzvMuBiDTUuXF7Nq9Lo2hCUhodIx4WtBjAlsiveHf2p06lrsl3Dy1ucX DynigArd0775qcmE6clokfCrbBvnlg6cdQQD6M22QE9V14GUmVkGWsG35tR04FOe yhlU= 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=lnsfqriCn0ldFzltgq6735xj2AXTvNbXnJnYNEdJNFosb3m0pLWnIFNjTgtNVC tM2WgoaTy6VBLd7/x1ly9TjutBtWb5NcW2M6O8Rg6zb+RE1TVttw2r3b6FemCekl kDthxhknPCGXbQqdXt2J0+5Vv4IJCT9Eftp4W7nVSw6Lw=; Received: (qmail 16225 invoked by alias); 4 Sep 2012 07:20:24 -0000 Received: (qmail 16214 invoked by uid 22791); 4 Sep 2012 07:20:22 -0000 X-SWARE-Spam-Status: No, hits=-4.2 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-wg0-f51.google.com (HELO mail-wg0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 04 Sep 2012 07:20:09 +0000 Received: by wgbed3 with SMTP id ed3so3500111wgb.8 for ; Tue, 04 Sep 2012 00:20:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.180.106.137 with SMTP id gu9mr28636454wib.20.1346743208038; Tue, 04 Sep 2012 00:20:08 -0700 (PDT) Received: by 10.216.2.4 with HTTP; Tue, 4 Sep 2012 00:20:08 -0700 (PDT) Date: Tue, 4 Sep 2012 00:20:08 -0700 Message-ID: Subject: [PATCH] Fix PR 54362 (COND_EXPR not understood by ITM) From: Andrew Pinski To: GCC Patches 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 that trans-mem.c does not take into account that COND_EXPR can happen for pointers. This patch modifies thread_private_new_memory to handle COND_EXPR as it can handle PHI nodes. The testcase is a modified version of memopt-12.c but with a loop which both LIM and if-convert can change the conditional to a COND_EXPR. I found this problem when I was producing a pass which does a full if-convert before expanding (well changing the last phi-opt pass) and it produces COND_EXPRs and memopt-12.c started to fail. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. Thanks, Andrew Pinski ChangeLog: * trans-mem.c (thread_private_new_memory): Handle COND_EXPR also. testsuite/ChangeLog: * gcc.dg/tm/memopt-16.c: New testcase. Index: testsuite/gcc.dg/tm/memopt-16.c =================================================================== --- testsuite/gcc.dg/tm/memopt-16.c (revision 0) +++ testsuite/gcc.dg/tm/memopt-16.c (revision 0) @@ -0,0 +1,43 @@ +/* { dg-do compile } */ +/* { dg-options "-fgnu-tm -O3 -fdump-tree-tmmark" } */ +/* Like memopt-12.c but the phi is inside a look which causes + it to be converted into a COND_EXPR. */ + +extern int test(void) __attribute__((transaction_safe)); +extern void *malloc (__SIZE_TYPE__) __attribute__((malloc,transaction_safe)); + +struct large { int foo[500]; }; + +int f(int j) +{ + int *p1, *p2, *p3; + + p1 = malloc (sizeof (*p1)*5000); + __transaction_atomic { + _Bool t; + int i = 1; + *p1 = 0; + + p2 = malloc (sizeof (*p2)*6000); + *p2 = 1; + t = test(); + + for (i = 0;i < j;i++) + { + + /* p3 = PHI (p1, p2) */ + if (t) + p3 = p1; + else + p3 = p2; + + /* Since both p1 and p2 are thread-private, we can inherit the + logging already done. No ITM_W* instrumentation necessary. */ + *p3 = 555; + } + } + return p3[something()]; +} + +/* { dg-final { scan-tree-dump-times "ITM_WU" 0 "tmmark" } } */ +/* { dg-final { cleanup-tree-dump "tmmark" } } */ Index: trans-mem.c =================================================================== --- trans-mem.c (revision 190908) +++ trans-mem.c (working copy) @@ -1379,6 +1379,19 @@ thread_private_new_memory (basic_block e /* x = (cast*) foo ==> foo */ else if (code == VIEW_CONVERT_EXPR || code == NOP_EXPR) x = gimple_assign_rhs1 (stmt); + /* x = c ? op1 : op2 == > op1 or op2 just like a PHI */ + else if (code == COND_EXPR) + { + tree op1 = gimple_assign_rhs2 (stmt); + tree op2 = gimple_assign_rhs3 (stmt); + enum thread_memory_type mem; + retval = thread_private_new_memory (entry_block, op1); + if (retval == mem_non_local) + goto new_memory_ret; + mem = thread_private_new_memory (entry_block, op2); + retval = MIN (retval, mem); + goto new_memory_ret; + } else { retval = mem_non_local;