From patchwork Wed Jul 15 07:09:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 51122 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 97C1722A24 for ; Wed, 15 Jul 2015 07:10:24 +0000 (UTC) Received: by lagw2 with SMTP id w2sf8293534lag.3 for ; Wed, 15 Jul 2015 00:10:23 -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=amdiNAe4yMabIe9ogwPtpyKerN0HJbdw/rP/EZDNo/E=; b=JQO9W6hkSbJreJpFYUcWfh/hv/QkqoLmTwGCBZUkh6o32hWuvrHCb2L6Fof9wV1xx3 eEgn2EQPa2H38od/PBA6ojjBbTqaRUUGXyKGkaEP2B/AZavtezk0xp30/Vm+mSv+vxCc uB5sgmql2QAw02saAbTWPBxvbb2Dgo9S7AkCkHQSF2NM1W3rHDBoP1PK/6ypYyfksw4f pr4SN5LyCol4uvpfpY1K+ZZDo30oHtdX6ewZYBFDy8jSP2S7FrTQrRkwyHVbqVIAtBT7 0qYN/C+16CZccHsxtBroaboVNT1BA0lm1N5q8snAOY6O9xofXyUNJArrkynkESh9I/3U YPWg== X-Gm-Message-State: ALoCoQm4wWSNhadMqxxGt+8o6Asy3C8LJRqof0NT1F3GoKNZstGJvAO5sObWD1BFBrGkzrFth235 X-Received: by 10.152.237.36 with SMTP id uz4mr1374415lac.1.1436944223391; Wed, 15 Jul 2015 00:10:23 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.146 with SMTP id j18ls148462laa.44.gmail; Wed, 15 Jul 2015 00:10:23 -0700 (PDT) X-Received: by 10.112.50.148 with SMTP id c20mr2541261lbo.27.1436944223115; Wed, 15 Jul 2015 00:10:23 -0700 (PDT) Received: from mail-la0-x22e.google.com (mail-la0-x22e.google.com. [2a00:1450:4010:c03::22e]) by mx.google.com with ESMTPS id ks11si3163900lac.78.2015.07.15.00.10.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jul 2015 00:10:23 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22e as permitted sender) client-ip=2a00:1450:4010:c03::22e; Received: by lagx9 with SMTP id x9so19073537lag.1 for ; Wed, 15 Jul 2015 00:10:23 -0700 (PDT) X-Received: by 10.112.125.34 with SMTP id mn2mr2385235lbb.76.1436944222979; Wed, 15 Jul 2015 00:10:22 -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.108.230 with SMTP id hn6csp2875277lbb; Wed, 15 Jul 2015 00:10:21 -0700 (PDT) X-Received: by 10.66.119.136 with SMTP id ku8mr5165634pab.26.1436944220570; Wed, 15 Jul 2015 00:10:20 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id uj9si5973659pbc.34.2015.07.15.00.10.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jul 2015 00:10:20 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-402970-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 116976 invoked by alias); 15 Jul 2015 07:10:04 -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 116961 invoked by uid 89); 15 Jul 2015 07:10:03 -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-f43.google.com Received: from mail-pa0-f43.google.com (HELO mail-pa0-f43.google.com) (209.85.220.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 15 Jul 2015 07:10:02 +0000 Received: by pactm7 with SMTP id tm7so19283359pac.2 for ; Wed, 15 Jul 2015 00:10:00 -0700 (PDT) X-Received: by 10.68.125.234 with SMTP id mt10mr5097978pbb.107.1436944200236; Wed, 15 Jul 2015 00:10:00 -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 z4sm3470221pdo.88.2015.07.15.00.09.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jul 2015 00:09:58 -0700 (PDT) Message-ID: <55A6073D.1020800@linaro.org> Date: Wed, 15 Jul 2015 17:09:49 +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> In-Reply-To: <55A24E7D.4080609@linaro.org> 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::22e 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 Here is a patch to fix to teach tree-ssa-reassoc the sinking the cast. Bootstrapped and regression tested on x86-64-none-linux-gnu with no new regressions. Also regression tested on qemu arm. I also verified the issue Andreas Schwab raised is fixed on arm cortex-a5 where the same issue was present. Does this make sense? Thanks, Kugan gcc/ChangeLog: 2015-07-15 Kugan Vivekanandarajah PR middle-end/66726 * tree-ssa-reassoc.c (optimize_range_tests): Handle sinking the cast after PHI. (final_range_test_p): Detect sinking the cast after PHI. (maybe_optimize_range_tests): Handle sinking the cast after PHI. 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 @@ -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,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; /* Test whether lhs is consumed only by a PHI in the only successor bb. */ @@ -2743,10 +2756,21 @@ 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 (!INTEGRAL_TYPE_P (TREE_TYPE (lhs)) + || 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 +3156,8 @@ maybe_optimize_range_tests (gimple stmt) /* stmt is _123 = (int) _234; + OR + _234 = a_2(D) == 2; followed by: : @@ -3161,6 +3187,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 +3201,22 @@ 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)) + && is_gimple_assign (stmt) + && (TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) + == tcc_comparison) + && has_single_use (lhs)) + { + /* Push the _234 range test itself. */ + 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; @@ -3267,7 +3311,8 @@ maybe_optimize_range_tests (gimple stmt) 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);