From patchwork Tue Jan 19 03:52:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 59954 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2342027lbb; Mon, 18 Jan 2016 19:52:53 -0800 (PST) X-Received: by 10.98.80.149 with SMTP id g21mr41164675pfj.127.1453175573618; Mon, 18 Jan 2016 19:52:53 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id g15si44295552pfg.147.2016.01.18.19.52.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jan 2016 19:52:53 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-419420-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-return-419420-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-419420-patch=linaro.org@gcc.gnu.org; dkim=pass header.i=@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=q90OdVF2W7w9NZW2JOuod8rG5YGETc4bd/5O2D3gVaezHcVzpr kSsLArfDCv93e2vvBDz9ctbHFVd93CpBbZOfl2sYMUhiJ3Dqy6LRvbypirQ8+o5V fy2FHYfx6v3jd1n70Vb1yO5dMSunjYjXdHNFmW3yzhDz95kh3v48lss3Y= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=iw6VNaXWKY7JWEkB4BsgkZjS1rc=; b=ihzWE43J/AwH839n85TZ OnBec88NwWDfF/75HBfYJGhWs0ygpWUUkyZX1gnq1W529dvyLh5qbwotwDwqhsgk +I/JWVliRqotfW8U48KLQceLuNnPuxb3+e6GNnYybs5DhavN6hMUfGjsmPapMtWC uysJEk8kE+c2BGofyLuvXXs= Received: (qmail 85425 invoked by alias); 19 Jan 2016 03:52:39 -0000 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 Received: (qmail 85414 invoked by uid 89); 19 Jan 2016 03:52:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=fold_convert, fixe, Fixe, sk:SSA_NAM X-HELO: mail-pa0-f48.google.com Received: from mail-pa0-f48.google.com (HELO mail-pa0-f48.google.com) (209.85.220.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 19 Jan 2016 03:52:35 +0000 Received: by mail-pa0-f48.google.com with SMTP id yy13so351271776pab.3 for ; Mon, 18 Jan 2016 19:52:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-type; bh=fpmgxPHhOHv/Mxd70Mlaxqdyi2Pp7MBEguYtzhgB/nY=; b=R5iWbdp3wyk7JHzyw4c7crkqvAsWHY11wwU4Qg+uQZsY1yz1DG6I2IT2UOcjmgupg/ KYfFVIn8XLMWWC0kSrnQxeu/Dfe9/laoSBOYCO5Xc1gUCGW315YCjhZsgDPJeijdfgSU VYnSIQAYiKZL1OoqtAXERK/AfIv7Pa0h30Av4U3O57JCC7q5lLs4EQWr/4lCs1oGK9bD fKIwJcf1BLmywRxuFO2BMy+j/hOP/aE3n10OnXNUP6jd5e6Ls3Aca9KDNKhBIiHKUfTp F1l89++dqwWxEx25kLjaDcFeLLGrC+iAtlOOibISwa/IZloHIfqLpLCj6TZQpX78oAJN 6kxg== X-Gm-Message-State: ALoCoQkObRCEpkfmD0hg7qzUGLPjuJ0XZezQLwFng+XX8VKVkLqtUTNhvs6Ja2U5QQFYIcpnoSwxSQ4t6h9bXhXQPNTJDH2h4A== X-Received: by 10.66.190.66 with SMTP id go2mr41962672pac.114.1453175553405; Mon, 18 Jan 2016 19:52:33 -0800 (PST) Received: from [10.1.1.3] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.googlemail.com with ESMTPSA id o4sm37153238pfa.85.2016.01.18.19.52.30 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 18 Jan 2016 19:52:32 -0800 (PST) To: "gcc-patches@gcc.gnu.org" Cc: Jeff Law , Jakub Jelinek From: Kugan Subject: [PR66726] Fixe regression caused by Factor conversion out of COND_EXPR Message-ID: <569DB2F9.30506@linaro.org> Date: Tue, 19 Jan 2016 14:52:25 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, This is an updated version of https://gcc.gnu.org/ml/gcc-patches/2015-07/msg02196.html. Patch to fix PR66726 missed optimization, factor conversion out of COND_EXPR caused a regression for targets with branch cost greater than i.e., testcase gcc.dg/pr46309.c failed for these targets. I posted a patch for this which had some issues. Please find an updated version of this patch that now passes regression. This patch makes optimize_range_tests understand the factored out COND_EXPR. i.e., Updated the final_range_test_p to look for the new pattern. Changed the maybe_optimize_range_tests (which does the inter basic block range test optimization) accordingly. Bootstrapped and regression tested on x86_64-none-linux-gnu with no new regressions. And also regression tested on arm-none-linux-gnu and aarch64-none-linux-gnu with no new regressions. Is this Ok for trunk? Thanks, Kugan gcc/ChangeLog: 2016-01-19 Kugan Vivekanandarajah PR middle-end/66726 * tree-ssa-reassoc.c (optimize_range_tests): Handle tcc_compare stmt whose result is used in PHI. (maybe_optimize_range_tests): Likewise. (final_range_test_p): Lokweise. diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index e53cc56..d0a5cee 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -2687,18 +2687,33 @@ 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. + + 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)) @@ -2709,11 +2724,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; @@ -2723,10 +2743,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; } @@ -3119,6 +3149,8 @@ maybe_optimize_range_tests (gimple *stmt) /* stmt is _123 = (int) _234; + OR + _234 = a_2(D) == 2; followed by: : @@ -3148,6 +3180,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. */ @@ -3160,6 +3194,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 *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; @@ -3243,26 +3294,60 @@ maybe_optimize_range_tests (gimple *stmt) { imm_use_iterator iter; use_operand_p use_p; - gimple *use_stmt, *cast_stmt = NULL; + gimple *use_stmt, *cast_or_tcc_cmp_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 ((is_gimple_assign (use_stmt) + && (TREE_CODE_CLASS (gimple_assign_rhs_code (use_stmt)) == tcc_comparison))) + { + cast_or_tcc_cmp_stmt = use_stmt; + } else if (gimple_assign_cast_p (use_stmt)) - cast_stmt = use_stmt; - else - gcc_unreachable (); - if (cast_stmt) + cast_or_tcc_cmp_stmt = use_stmt; + + if (cast_or_tcc_cmp_stmt) { gcc_assert (bb == last_bb); - tree lhs = gimple_assign_lhs (cast_stmt); + tree lhs = gimple_assign_lhs (cast_or_tcc_cmp_stmt); tree new_lhs = make_ssa_name (TREE_TYPE (lhs)); enum tree_code rhs_code - = gimple_assign_rhs_code (cast_stmt); + = gimple_assign_cast_p (cast_or_tcc_cmp_stmt) ? + gimple_assign_rhs_code (cast_or_tcc_cmp_stmt) : CONVERT_EXPR; gassign *g; if (is_gimple_min_invariant (new_op)) { @@ -3271,13 +3356,14 @@ maybe_optimize_range_tests (gimple *stmt) } else g = gimple_build_assign (new_lhs, rhs_code, new_op); - gimple_stmt_iterator gsi = gsi_for_stmt (cast_stmt); - gimple_set_uid (g, gimple_uid (cast_stmt)); + gimple_stmt_iterator gsi = gsi_for_stmt (cast_or_tcc_cmp_stmt); + gimple_set_uid (g, gimple_uid (cast_or_tcc_cmp_stmt)); gimple_set_visited (g, true); - gsi_insert_before (&gsi, g, GSI_SAME_STMT); + gsi_insert_after (&gsi, g, GSI_SAME_STMT); FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs) if (is_gimple_debug (use_stmt)) continue; + else if (is_gimple_assign (use_stmt)); else if (gimple_code (use_stmt) == GIMPLE_COND || gimple_code (use_stmt) == GIMPLE_PHI) FOR_EACH_IMM_USE_ON_STMT (use_p, iter)