From patchwork Mon Jul 27 01:05:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 51476 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id E8EBA22DA5 for ; Mon, 27 Jul 2015 01:06:29 +0000 (UTC) Received: by wicmv11 with SMTP id mv11sf22392735wic.1 for ; Sun, 26 Jul 2015 18:06:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:message-id:date:from:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type:x-original-sender :x-original-authentication-results; bh=OKqtWMMdlPRi2aGjmeXo6o4keYgk17Bdhs22epH24yo=; b=Dr1Mago3DiMUhnFfbdQRzl+EoPaG+v89H3Lv5GJsSKCXn2hm8F9HUhghXsiNGpAQrO kzdOw8XjDrZ9mETqkYz/TIHhvmQ3FRrIDH+3vmpPhoqqgSV9VF0f1iFWeo9YWxXbzKfl UNj6VUp8g0aQN/kOJY07ZrWAX2HzaDOFQd+d9LW36NK8XSVz1/CJvetLa6itvfmYAlPa eaJ7QAto8sIYvsKTSxvo1931K6E/DRQRXeMuiHu0Pi9wwUN+gI9a68KerFxjgC9JoR6f F/G6qixbIi7xzxf5IOX/hofwTqCoVnPYWgNiItah4CQoVT3up1iJ1imz5YmsBbT1Sh8N 2+DQ== X-Gm-Message-State: ALoCoQlY6iVRCMqdHcxCJASCsSkrV8KFSdZEu7X8ozpwoW6sMXyUr8YW3IbVgldLmUb175k1r7zj X-Received: by 10.112.9.100 with SMTP id y4mr10991520lba.20.1437959188826; Sun, 26 Jul 2015 18:06:28 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.99 with SMTP id p3ls500819laj.57.gmail; Sun, 26 Jul 2015 18:06:28 -0700 (PDT) X-Received: by 10.152.10.97 with SMTP id h1mr24698210lab.45.1437959188618; Sun, 26 Jul 2015 18:06:28 -0700 (PDT) Received: from mail-la0-x233.google.com (mail-la0-x233.google.com. [2a00:1450:4010:c03::233]) by mx.google.com with ESMTPS id j10si13953194lbp.23.2015.07.26.18.06.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jul 2015 18:06:28 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::233 as permitted sender) client-ip=2a00:1450:4010:c03::233; Received: by lagw2 with SMTP id w2so39863285lag.3 for ; Sun, 26 Jul 2015 18:06:28 -0700 (PDT) X-Received: by 10.152.207.76 with SMTP id lu12mr24458087lac.29.1437959188267; Sun, 26 Jul 2015 18:06:28 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.7.198 with SMTP id l6csp1247269lba; Sun, 26 Jul 2015 18:06:26 -0700 (PDT) X-Received: by 10.107.16.99 with SMTP id y96mr36549482ioi.93.1437959186260; Sun, 26 Jul 2015 18:06:26 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id rj10si39840638pdb.132.2015.07.26.18.06.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jul 2015 18:06:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-403937-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 40569 invoked by alias); 27 Jul 2015 01:06:11 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 40557 invoked by uid 89); 27 Jul 2015 01:06:10 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f42.google.com Received: from mail-pa0-f42.google.com (HELO mail-pa0-f42.google.com) (209.85.220.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 27 Jul 2015 01:06:08 +0000 Received: by pabkd10 with SMTP id kd10so42154386pab.2 for ; Sun, 26 Jul 2015 18:06:06 -0700 (PDT) X-Received: by 10.66.119.201 with SMTP id kw9mr62905658pab.49.1437959165904; Sun, 26 Jul 2015 18:06:05 -0700 (PDT) Received: from [10.1.1.8] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.googlemail.com with ESMTPSA id ex13sm26209949pac.17.2015.07.26.18.06.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jul 2015 18:06:03 -0700 (PDT) Message-ID: <55B583F6.4080904@linaro.org> Date: Mon, 27 Jul 2015 11:05:58 +1000 From: Kugan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Jeff Law , Bernhard Reutner-Fischer CC: "gcc-patches@gcc.gnu.org" Subject: Re: [PR66726] Factor conversion out of COND_EXPR References: <55974BF2.3060603@linaro.org> <20150704085143.GA14895@nbbrfq.cc.univie.ac.at> <5597D24B.8010900@linaro.org> <559AF515.6010700@redhat.com> <559BCB15.9010209@linaro.org> <559BE505.5070802@redhat.com> <559EFEE5.6030006@linaro.org> <55A02DBF.6030608@redhat.com> <55A24E7D.4080609@linaro.org> <55A6073D.1020800@linaro.org> <55A6AA4D.1030106@redhat.com> <55A74691.3050303@linaro.org> <55B13AF0.3020204@redhat.com> In-Reply-To: <55B13AF0.3020204@redhat.com> X-IsSubscribed: yes X-Original-Sender: kugan.vivekanandarajah@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::233 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 On 24/07/15 05:05, Jeff Law wrote: > On 07/15/2015 11:52 PM, Kugan wrote: >> >>>> >>>> diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c >>>> index 932c83a..3058eb5 100644 >>>> --- a/gcc/tree-ssa-reassoc.c >>>> +++ b/gcc/tree-ssa-reassoc.c >>> >>>> return false; >>>> bb = gimple_bb (stmt); >>>> if (!single_succ_p (bb)) >>>> @@ -2729,9 +2743,8 @@ final_range_test_p (gimple stmt) >>>> >>>> lhs = gimple_assign_lhs (stmt); >>>> rhs = gimple_assign_rhs1 (stmt); >>>> - if (!INTEGRAL_TYPE_P (TREE_TYPE (lhs)) >>>> - || TREE_CODE (rhs) != SSA_NAME >>>> - || TREE_CODE (TREE_TYPE (rhs)) != BOOLEAN_TYPE) >>>> + if (TREE_CODE (TREE_TYPE (rhs)) != BOOLEAN_TYPE >>>> + && TREE_CODE (TREE_TYPE (lhs)) != BOOLEAN_TYPE) >>>> return false; >>> So you're ensuring that one of the two is a boolean... Note that >>> previously we ensured that the rhs was a boolean and the lhs was an >>> integral type (which I believe is true for booleans). >>> >>> Thus if we had >>> bool x; >>> int y; >>> >>> x = (bool) y; >>> >>> The old code would have rejected that case. But I think it gets through >>> now, right? >>> >>> I think once that issue is addressed, this will be good for the trunk. >>> >> >> Thanks for the review. How about: >> >> - if (!INTEGRAL_TYPE_P (TREE_TYPE (lhs)) >> - || TREE_CODE (rhs) != SSA_NAME >> - || TREE_CODE (TREE_TYPE (rhs)) != BOOLEAN_TYPE) >> + if (gimple_assign_cast_p (stmt) >> + && (!INTEGRAL_TYPE_P (TREE_TYPE (lhs)) >> + || TREE_CODE (rhs) != SSA_NAME >> + || TREE_CODE (TREE_TYPE (rhs)) != BOOLEAN_TYPE)) > But then I think you need to verify that for the _234 = a_2(D) == 2; > case that type of the RHS is a boolean. > > ie, each case has requirements for the types. I don't think they can be > reasonably unified. So something like this: > > if (gimple_assign_cast_p (stmt) > && ! (correct types for cast) > return false; > > if (!gimple_assign_cast_p (stmt) > && ! (correct types for tcc_comparison case)) > return false; > > > This works because we've already verified that it's either a type > conversion or a comparison on the RHS. > I thought that when !gimple_assign_cast_p (stmt), RHS will always boolean. I have now added this check in the attached patch. I also noticed that in maybe_optimize_range_tests, GIMPLE_COND can have non compatible types when new_op is updated (boolean types coming from tcc_compare results) and hence need to be converted. Changed that as well. Bootstrapped and regression tested on x86-64-none-linux-gnu with no new regressions. Is this OK for trunk? Thanks, Kugan diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index efb813c..cc215b6 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -2707,18 +2707,32 @@ optimize_range_tests (enum tree_code opcode, # _345 = PHI <_123(N), 1(...), 1(...)> where _234 has bool type, _123 has single use and bb N has a single successor M. This is commonly used in - the last block of a range test. */ + the last block of a range test. + + Also Return true if STMT is tcc_compare like: + : + ... + _234 = a_2(D) == 2; + : + # _345 = PHI <_234(N), 1(...), 1(...)> + _346 = (int) _345; + where _234 has booltype, single use and + bb N has a single successor M. This is commonly used in + the last block of a range test. */ static bool final_range_test_p (gimple stmt) { - basic_block bb, rhs_bb; + basic_block bb, rhs_bb, lhs_bb; edge e; tree lhs, rhs; use_operand_p use_p; gimple use_stmt; - if (!gimple_assign_cast_p (stmt)) + if (!gimple_assign_cast_p (stmt) + && (!is_gimple_assign (stmt) + || (TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) + != tcc_comparison))) return false; bb = gimple_bb (stmt); if (!single_succ_p (bb)) @@ -2729,11 +2743,16 @@ final_range_test_p (gimple stmt) lhs = gimple_assign_lhs (stmt); rhs = gimple_assign_rhs1 (stmt); - if (!INTEGRAL_TYPE_P (TREE_TYPE (lhs)) - || TREE_CODE (rhs) != SSA_NAME - || TREE_CODE (TREE_TYPE (rhs)) != BOOLEAN_TYPE) + if (gimple_assign_cast_p (stmt) + && (!INTEGRAL_TYPE_P (TREE_TYPE (lhs)) + || TREE_CODE (rhs) != SSA_NAME + || TREE_CODE (TREE_TYPE (rhs)) != BOOLEAN_TYPE)) return false; + if (!gimple_assign_cast_p (stmt) + && (TREE_CODE (TREE_TYPE (lhs)) != BOOLEAN_TYPE)) + return false; + /* Test whether lhs is consumed only by a PHI in the only successor bb. */ if (!single_imm_use (lhs, &use_p, &use_stmt)) return false; @@ -2743,10 +2762,20 @@ final_range_test_p (gimple stmt) return false; /* And that the rhs is defined in the same loop. */ - rhs_bb = gimple_bb (SSA_NAME_DEF_STMT (rhs)); - if (rhs_bb == NULL - || !flow_bb_inside_loop_p (loop_containing_stmt (stmt), rhs_bb)) - return false; + if (gimple_assign_cast_p (stmt)) + { + if (TREE_CODE (rhs) != SSA_NAME + || !(rhs_bb = gimple_bb (SSA_NAME_DEF_STMT (rhs))) + || !flow_bb_inside_loop_p (loop_containing_stmt (stmt), rhs_bb)) + return false; + } + else + { + if (TREE_CODE (lhs) != SSA_NAME + || !(lhs_bb = gimple_bb (SSA_NAME_DEF_STMT (lhs))) + || !flow_bb_inside_loop_p (loop_containing_stmt (stmt), lhs_bb)) + return false; + } return true; } @@ -3132,6 +3161,8 @@ maybe_optimize_range_tests (gimple stmt) /* stmt is _123 = (int) _234; + OR + _234 = a_2(D) == 2; followed by: : @@ -3161,6 +3192,8 @@ maybe_optimize_range_tests (gimple stmt) of the bitwise or resp. and, recursively. */ if (!get_ops (rhs, code, &ops, loop_containing_stmt (stmt)) + && (TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) + != tcc_comparison) && has_single_use (rhs)) { /* Otherwise, push the _234 range test itself. */ @@ -3173,6 +3206,23 @@ maybe_optimize_range_tests (gimple stmt) ops.safe_push (oe); bb_ent.last_idx++; } + else if (!get_ops (lhs, code, &ops, + loop_containing_stmt (stmt)) + && TREE_CODE (lhs) == SSA_NAME + && INTEGRAL_TYPE_P (TREE_TYPE (lhs)) + && is_gimple_assign (stmt) + && (TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) + == tcc_comparison) + && has_single_use (lhs)) + { + operand_entry_t oe = operand_entry_pool.allocate (); + oe->op = lhs; + oe->rank = code; + oe->id = 0; + oe->count = 1; + ops.safe_push (oe); + bb_ent.last_idx++; + } else bb_ent.last_idx = ops.length (); bb_ent.op = rhs; @@ -3258,16 +3308,46 @@ maybe_optimize_range_tests (gimple stmt) gimple use_stmt, cast_stmt = NULL; FOR_EACH_IMM_USE_STMT (use_stmt, iter, bbinfo[idx].op) - if (is_gimple_debug (use_stmt)) + if (is_gimple_debug (use_stmt) + || (TREE_CODE (new_op) == SSA_NAME + && !reassoc_stmt_dominates_stmt_p + (SSA_NAME_DEF_STMT (new_op), use_stmt))) continue; - else if (gimple_code (use_stmt) == GIMPLE_COND - || gimple_code (use_stmt) == GIMPLE_PHI) - FOR_EACH_IMM_USE_ON_STMT (use_p, iter) - SET_USE (use_p, new_op); + else if (gimple_code (use_stmt) == GIMPLE_PHI) + FOR_EACH_IMM_USE_ON_STMT (use_p, iter) + SET_USE (use_p, new_op); + else if (gimple_code (use_stmt) == GIMPLE_COND) + { + tree new_type, new_lhs; + gassign *g; + gcond *cond_stmt = as_a (use_stmt); + new_type = TREE_TYPE (gimple_cond_lhs (cond_stmt)); + if (!types_compatible_p (new_type, TREE_TYPE (new_op))) + { + new_lhs = make_ssa_name (new_type); + if (is_gimple_min_invariant (new_op)) + { + new_op = fold_convert (new_type, new_op); + g = gimple_build_assign (new_lhs, new_op); + } + else + g = gimple_build_assign (new_lhs, + CONVERT_EXPR, new_op); + gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt); + gimple_set_uid (g, gimple_uid (use_stmt)); + gimple_set_visited (g, true); + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + } + else + new_lhs = new_op; + FOR_EACH_IMM_USE_ON_STMT (use_p, iter) + SET_USE (use_p, new_lhs); + } else if (gimple_assign_cast_p (use_stmt)) cast_stmt = use_stmt; else - gcc_unreachable (); + cast_stmt = NULL; + if (cast_stmt) { gcc_assert (bb == last_bb); @@ -3291,7 +3371,8 @@ maybe_optimize_range_tests (gimple stmt) if (is_gimple_debug (use_stmt)) continue; else if (gimple_code (use_stmt) == GIMPLE_COND - || gimple_code (use_stmt) == GIMPLE_PHI) + || gimple_code (use_stmt) == GIMPLE_PHI + || is_gimple_assign (use_stmt)) FOR_EACH_IMM_USE_ON_STMT (use_p, iter) SET_USE (use_p, new_lhs); else