From patchwork Fri Apr 13 12:02:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 152290 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 1B53EB700C for ; Fri, 13 Apr 2012 22:03:25 +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=1334923407; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Subject:Message-ID:MIME-Version:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=LekRVJc8PtC4uVSi7ErA 9EnYXGY=; b=O5YeVihWqpf/Y2TNVuk1IOCDbDE7otMgu2hD2BhXJXo9FQ3gcIin pSnPoYlfHn5I+8qwr9hO/GvnWe1ZiiNkScofj8p85AyeOsVKlRibs39iHVZrqPnO TKmUIm11O+RMJFWI99cx/efzlVX63v1r2xH2jrbqZ3RMgB1ZD3Fxero= 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:Date:From:To:Subject:Message-ID:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=wO+I7Kmg/WRtbDZYzgF9inFh0vpJQkhG7tDMzp8H5K600kXwt6ryhsJ9lb093S sTUUYFxbbwaTvRNesnT812gJoyt51E0/1o5136xieYxClji195qF703xv0RHeeO+ ND9PYsOtoZkfJedwAosnKzj3BH488XEs2OWeeBdgL4mBU=; Received: (qmail 12874 invoked by alias); 13 Apr 2012 12:03:18 -0000 Received: (qmail 12861 invoked by uid 22791); 13 Apr 2012 12:03:16 -0000 X-SWARE-Spam-Status: No, hits=-5.2 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 13 Apr 2012 12:03:01 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 175ED92016 for ; Fri, 13 Apr 2012 14:03:00 +0200 (CEST) Date: Fri, 13 Apr 2012 14:02:59 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR52969 Message-ID: MIME-Version: 1.0 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 The following patch fixes the missed handling of TRUTH_NOT_EXPR predicates in predicate_mem_writes and general combined predicates which need gimplification. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2012-04-13 Richard Guenther PR tree-optimization/52969 * tree-if-conv.c (predicate_mem_writes): Properly gimplify the condition for the COND_EXPR and handle predicate negation by swapping the COND_EXPR arms. * gcc.dg/torture/pr52969.c: New testcase. Index: gcc/tree-if-conv.c =================================================================== --- gcc/tree-if-conv.c (revision 186406) +++ gcc/tree-if-conv.c (working copy) @@ -1543,11 +1522,19 @@ predicate_mem_writes (loop_p loop) gimple_stmt_iterator gsi; basic_block bb = ifc_bbs[i]; tree cond = bb_predicate (bb); + bool swap; gimple stmt; if (is_true_predicate (cond)) continue; + swap = false; + if (TREE_CODE (cond) == TRUTH_NOT_EXPR) + { + swap = true; + cond = TREE_OPERAND (cond, 0); + } + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) if ((stmt = gsi_stmt (gsi)) && gimple_assign_single_p (stmt) @@ -1559,6 +1546,15 @@ predicate_mem_writes (loop_p loop) lhs = ifc_temp_var (type, unshare_expr (lhs), &gsi); rhs = ifc_temp_var (type, unshare_expr (rhs), &gsi); + if (swap) + { + tree tem = lhs; + lhs = rhs; + rhs = tem; + } + cond = force_gimple_operand_gsi_1 (&gsi, unshare_expr (cond), + is_gimple_condexpr, NULL_TREE, + true, GSI_SAME_STMT); rhs = build3 (COND_EXPR, type, unshare_expr (cond), rhs, lhs); gimple_assign_set_rhs1 (stmt, ifc_temp_var (type, rhs, &gsi)); update_stmt (stmt); Index: gcc/testsuite/gcc.dg/torture/pr52969.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr52969.c (revision 0) +++ gcc/testsuite/gcc.dg/torture/pr52969.c (revision 0) @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-ftree-loop-if-convert-stores" } */ + +int a, b; +float xsum[100]; +void foo (float *cluster) +{ + int j; + for (; a ; ++j) { + xsum[j] = cluster[j]; + if (xsum[j] > 0) + xsum[j] = 0; + } + if (xsum[0]) + b = 0; +}