From patchwork Tue Jun 22 19:18:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Pop X-Patchwork-Id: 56571 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 F1CFFB6F17 for ; Wed, 23 Jun 2010 07:37:29 +1000 (EST) Received: (qmail 3540 invoked by alias); 22 Jun 2010 21:37:27 -0000 Received: (qmail 3524 invoked by uid 22791); 22 Jun 2010 21:37:24 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, TW_DB, TW_TM X-Spam-Check-By: sourceware.org Received: from mail-gy0-f175.google.com (HELO mail-gy0-f175.google.com) (209.85.160.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 22 Jun 2010 21:37:18 +0000 Received: by gyg10 with SMTP id 10so3431215gyg.20 for ; Tue, 22 Jun 2010 14:37:16 -0700 (PDT) Received: by 10.229.242.65 with SMTP id lh1mr3507843qcb.151.1277236748370; Tue, 22 Jun 2010 12:59:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.74.18 with HTTP; Tue, 22 Jun 2010 12:18:05 -0700 (PDT) From: Sebastian Pop Date: Tue, 22 Jun 2010 14:18:05 -0500 Message-ID: Subject: [patch] More improvements for the code generation of the if-conversion To: GCC Patches , Richard Guenther 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 attached patches clean the code generated by the if-conversion: 0001 adds a debug counter, useful to reduce code generation problems due to the tree-if-conversion pass. 0002 calls the cleanup_tree_cfg after if-conversion to ensure that the CFG representation passed to the vectorizer is in good shape. 0003 adds some more sanity checks after the if-conversion pass: verify_loop_structure and verify_loop_closed_ssa. 0004 moves the code needed for the computation of the predicate of a BB at the beginning of the predicated BB. The computation of the insertion place is simplified, and makes it possible to use this predicate in the code of the BB. 0005 implements and calls an unfold SSA function that first expands the SSA_NAMEs and then calls fold on the expanded expression tree. unfold_ssa_names exposes to fold a more complete expression than otherwise available in the predicates of a BB. This patch is now needed to improve the quality of the code generated by the if-conversion as if-convert gimplifies the predicates in order to avoid recomputations of some predicates. With this patch it is possible to fold (a || b) into the true predicate when a and b are the predicates of the two branches of a condition, as the SSA_NAMEs a and b are first unfolded into their respective expressions and then fold finishes by computing the true predicate. Note that this patch needs some adjustment, i.e., replacing the magic constant 5 that is the depth level for the unfold traversal to be some parameter, or so. 0006 uses a single function reset_bb_predicate to reset the predicate of a BB to true. This function has to release all the SSA_NAMEs used in the gimplification of a predicate. 0007 avoids the generation of code computing the true predicate, that occurs for all the BBs merging disjunct predicates leading to the true predicate. 0008 forces the predicate of a BB to be either is_gimple_condexpr or otherwise the predicate is gimplified, avoiding the insertion of the same computation on other predicates. This patch-set passed regstrap on amd64-linux with BOOT_CFLAGS= -g -O3 -msse2. Ok for trunk? Thanks, Sebastian Pop --- AMD / Open Source Compiler Engineering / GNU Tools From 35f74eaa5d4a79f3fcdfeae8bdf3b81751c6f1ba Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Wed, 16 Jun 2010 15:57:53 -0500 Subject: [PATCH 08/10] The predicate of a BB should either be a gimple_condexpr or an SSA_NAME. * tree-if-conv.c (add_to_predicate_list): Call force_gimple_operand when the predicate is not a gimple_condexpr. Call reset_bb_predicate when the predicate is true. * gcc.dg/tree-ssa/ifc-6.c: New. --- gcc/testsuite/gcc.dg/tree-ssa/ifc-6.c | 15 +++++++++++++++ gcc/tree-if-conv.c | 12 +++++++++++- 2 files changed, 26 insertions(+), 1 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ifc-6.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ifc-6.c b/gcc/testsuite/gcc.dg/tree-ssa/ifc-6.c new file mode 100644 index 0000000..a9c5db3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ifc-6.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-c -O2 -ftree-vectorize" { target *-*-* } } */ + +static int x; +foo (int n, int *A) +{ + int i; + for (i = 0; i < n; i++) + { + if (A[i]) + x = 2; + if (A[i + 1]) + x = 1; + } +} diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c index ac3ba93..759920c 100644 --- a/gcc/tree-if-conv.c +++ b/gcc/tree-if-conv.c @@ -278,7 +278,17 @@ add_to_predicate_list (basic_block bb, tree new_cond) cond = unfold_ssa_names (cond, 5); } - set_bb_predicate (bb, cond); + if (!is_gimple_condexpr (cond)) + { + gimple_seq stmts; + cond = force_gimple_operand (cond, &stmts, true, NULL_TREE); + add_bb_predicate_gimplified_stmts (bb, stmts); + } + + if (is_true_predicate (cond)) + reset_bb_predicate (bb); + else + set_bb_predicate (bb, cond); } /* Add the condition COND to the previous condition PREV_COND, and add -- 1.7.0.4