From patchwork Wed Jun 1 10:46:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 69017 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp19032qge; Wed, 1 Jun 2016 03:46:40 -0700 (PDT) X-Received: by 10.107.168.194 with SMTP id e63mr4298654ioj.61.1464778000640; Wed, 01 Jun 2016 03:46:40 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id ke8si11287448pad.150.2016.06.01.03.46.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Jun 2016 03:46:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-428755-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; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-428755-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-428755-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.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 :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=cuhfPU0gvmAD7gMwa90hOTokb3wQL7b0Vv3O9RHSgHACGCD/pu iN4rJgPncznt4q+RuuzTpmaD7MykPVo44/YtcHvS/hgvKYUVrpijRw255nLEMOm1 VRmBOAf2V92UzSZee5hZUBLYIQTwUYt/bvbTpSY21/9xBd2ZGAR1vXGJg= 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 :from:subject:message-id:date:mime-version:content-type; s= default; bh=jfNGoCMkr2UBeVWtIkIqmbbwhEE=; b=OHCG9f1qL4Z5QT3iu8FN Xo6H/yq7AACDwuIg9tHIjb6tXJhElOjspxExWo7pkp+wEqYGmFfLBRfk1NDL1UpY 3i/QjNKwU5VsoWWsUUu/PqJgbitQORy/xxfD+CMX3kAqj61xM9kxAYWX+mOG11Gz XGTvXk9qYOpE4bkdJ/m0p/0= Received: (qmail 78576 invoked by alias); 1 Jun 2016 10:46:28 -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 78561 invoked by uid 89); 1 Jun 2016 10:46:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=rank, H*r:10.1.1, commonly, HX-Received:10.98.20.5 X-HELO: mail-pf0-f176.google.com Received: from mail-pf0-f176.google.com (HELO mail-pf0-f176.google.com) (209.85.192.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 01 Jun 2016 10:46:16 +0000 Received: by mail-pf0-f176.google.com with SMTP id b124so13133657pfb.0 for ; Wed, 01 Jun 2016 03:46:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version; bh=KrwRscOvb7/A45MdNk87YGKUjrE8VMQAKj0K8662TZA=; b=b7tptW/N4BcAoelwVqr+7DKCdZ5hmZnpmZ1kxw12QhyyoChMBPXxux5vuWwqJvANu6 pd4P9gBnDYv4sOUyj4spcYhhYMBKpEhK+RJyo9FwNi5fmLeEKNDw+UWU9xt6yu63F1Mf fbstquw99P0cceb3E5d6XyN/mHSlYfOx7/yFFJyDtXVTnUCvf55UBrWQqtOKcrW5kGYI l8mZbxjcEBokxUgeVVosetZeHOWiHzmNF0X0JkpUVvfZvXKOwG/T4k0zlSt0JPbZVMbb KyXlF+eUz7eHaBAwWd6r5VAI3JcV+KygILA5xWTfLbKsFjhrKnjSROT1sVpU60wDNi3G L7PQ== X-Gm-Message-State: ALyK8tIHeIEEQYmIOhpoHV2m21KcQmCBsdLRANIMLpcE4pcZzE1S3ozsLuHyKJy30snMMSwy X-Received: by 10.98.20.5 with SMTP id 5mr7429151pfu.144.1464777974520; Wed, 01 Jun 2016 03:46:14 -0700 (PDT) Received: from [10.1.1.13] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.gmail.com with ESMTPSA id g82sm47147234pfj.22.2016.06.01.03.46.12 for (version=TLSv1/SSLv3 cipher=OTHER); Wed, 01 Jun 2016 03:46:13 -0700 (PDT) To: "gcc-patches@gcc.gnu.org" From: kugan Subject: [PR66726] Fix regression caused by Factor conversion out of COND_EXPR Message-ID: <574EBCEC.70805@linaro.org> Date: Wed, 1 Jun 2016 20:46:04 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi All, Factoring out CONVERT_EXPR introduced a regression for (PR66726). I had to revert my previous patch due to some regressions. This is a much simplified version compared to the one I reverted. There is a test-case (pr46309.c) in the test-suite which is valid for targets that has branch cost greater than 1. 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. With the patch m68k-linux-gnu-gcc -O2 -S pr46309.c -fdump-tree-reassoc-details grep -e "Optimizing range tests" -e into pr46309.c.*.reassoc1pr46309.c.114t.reassoc1:Optimizing range tests a_6(D) -[1, 1] and -[2, 2] and -[3, 3] and -[4, 4] pr46309.c.114t.reassoc1: into (unsigned int) a_6(D) + 4294967295 > 3 pr46309.c.114t.reassoc1: into _10 = _13; pr46309.c.114t.reassoc1:Optimizing range tests a_6(D) -[1, 1] and -[2, 2] and -[3, 3] and -[4, 4] pr46309.c.114t.reassoc1: into (unsigned int) a_6(D) + 4294967295 > 3 pr46309.c.114t.reassoc1: into _10 = _13; pr46309.c.114t.reassoc1:Optimizing range tests a_4(D) -[1, 1] and -[3, 3] pr46309.c.114t.reassoc1: into (a_4(D) & -3) != 1 pr46309.c.114t.reassoc1: into _6 = _8; pr46309.c.114t.reassoc1:Optimizing range tests a_4(D) -[1, 1] and -[2, 2] pr46309.c.114t.reassoc1: into (unsigned int) a_4(D) + 4294967295 > 1 pr46309.c.114t.reassoc1: into _6 = _9; pr46309.c.114t.reassoc1:Optimizing range tests a_5(D) -[0, 31] and -[64, 95] pr46309.c.114t.reassoc1: into (a_5(D) & 4294967231) > 31 pr46309.c.114t.reassoc1: into _7 = _9; pr46309.c.114t.reassoc1:Optimizing range tests a_9(D) -[0, 31] and -[64, 95] pr46309.c.114t.reassoc1: into (a_9(D) & 4294967231) > 31 pr46309.c.114t.reassoc1:Optimizing range tests a_9(D) -[128, 159] and -[192, 223] pr46309.c.114t.reassoc1: into (a_9(D) & 4294967231) + 4294967168 > 31 pr46309.c.114t.reassoc1: into _13 = _18 | _15; pr46309.c.116t.reassoc1:Optimizing range tests a_2(D) -[1, 1] and -[2, 2] and -[3, 3] and -[4, 4] pr46309.c.116t.reassoc1: into (unsigned int) a_2(D) + 4294967295 > 3 pr46309.c.116t.reassoc1:Optimizing range tests a_2(D) -[1, 1] and -[2, 2] and -[3, 3] and -[4, 4] pr46309.c.116t.reassoc1: into (unsigned int) a_2(D) + 4294967295 > 3 pr46309.c.116t.reassoc1:Optimizing range tests a_3(D) -[0, 31] and -[64, 95] pr46309.c.116t.reassoc1: into (a_3(D) & 4294967231) > 31 pr46309.c.116t.reassoc1:Optimizing range tests a_5(D) -[0, 31] and -[64, 95] pr46309.c.116t.reassoc1: into (a_5(D) & 4294967231) > 31 pr46309.c.116t.reassoc1:Optimizing range tests a_5(D) -[128, 159] and -[192, 223] pr46309.c.116t.reassoc1: into (a_5(D) & 4294967231) + 4294967168 > 31 Bootstrapped and regression testing on x86-64-linux-gnu and ppc64le-linux-gnu doesn't have any new regressions. Also did regression testing arm variants which has branch cost greater than 1 Is this OK for trunk. Thanks, Kugan gcc/ChangeLog: 2016-06-01 Kugan Vivekanandarajah PR middle-end/66726 * tree-ssa-reassoc.c (optimize_vec_cond_expr): Handle tcc_compare stmt whose result is used in PHI (final_range_test_p): Likewise. (maybe_optimize_range_tests): Likewise. diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 430bcc8..851ae6d 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -3007,18 +3007,33 @@ optimize_vec_cond_expr (tree_code opcode, vec *ops) # _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)) @@ -3029,11 +3044,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; @@ -3043,10 +3063,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; } @@ -3440,6 +3470,8 @@ maybe_optimize_range_tests (gimple *stmt) /* stmt is _123 = (int) _234; + OR + _234 = a_2(D) == 2; followed by: : @@ -3469,6 +3501,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. */ @@ -3481,10 +3515,36 @@ maybe_optimize_range_tests (gimple *stmt) oe->stmt_to_insert = NULL; ops.safe_push (oe); bb_ent.last_idx++; + bb_ent.op = rhs; + } + else if (is_gimple_assign (stmt) + && (TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) + == tcc_comparison)) + { + if (!get_ops (lhs, code, &ops, + loop_containing_stmt (stmt)) + && has_single_use (rhs)) + { + 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++; + bb_ent.op = lhs; + } + else + { + bb_ent.last_idx = ops.length (); + bb_ent.op = rhs; + } } else - bb_ent.last_idx = ops.length (); - bb_ent.op = rhs; + { + bb_ent.last_idx = ops.length (); + bb_ent.op = rhs; + } bbinfo.safe_push (bb_ent); continue; } @@ -3566,7 +3626,7 @@ 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)) @@ -3575,17 +3635,25 @@ maybe_optimize_range_tests (gimple *stmt) || gimple_code (use_stmt) == GIMPLE_PHI) FOR_EACH_IMM_USE_ON_STMT (use_p, iter) SET_USE (use_p, new_op); + 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; + cast_or_tcc_cmp_stmt = use_stmt; else gcc_unreachable (); - if (cast_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)) { @@ -3594,8 +3662,9 @@ 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); FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)