From patchwork Thu Jul 16 05:52:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 51137 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0A01322A28 for ; Thu, 16 Jul 2015 05:52:49 +0000 (UTC) Received: by wgfk9 with SMTP id k9sf16032701wgf.1 for ; Wed, 15 Jul 2015 22:52:48 -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=FlHXeAou35qkNYbGdJI5tK0JxeIqsQjG01KHQrLVQ0g=; b=G+2GTBYlfBDjT+EZtFN22a/qenMV1riL+aEoycLKgo5TXkrTSlKzYSA54gp7O9vK5y IHbrr6zKGnGAUxSawQPoUlb0Nhmk0bKCX1QB2SAGfwvC/j3fVj/6EITE35N3g2gg2OQU fAzmP+dcIFg3kD3z+9mKo3ayvDufH2nHNtZ+Ih0Rx2maM2+fdpF6mYL1FMrc4KVxVGFQ h4isbJYjeYL/6bS8Kun50B/zZAYuOdIIKsmHytrZdiVSL3NKU0uBeEUCfWiUS9GlHosz pbe32NF0jHjc06u33sUJVSumKFop5HvFSF5/vL/Ir7iAtxBDu9dHpARh8zrvc2WIfUZA X1Hg== X-Gm-Message-State: ALoCoQlfsTVAs15BQUnOoyQVACRask3fFa96QmLo0Vn7m5KVVWXHYFHOrOv3V8/cBWoKziKSBZft X-Received: by 10.194.184.6 with SMTP id eq6mr4016259wjc.4.1437025968365; Wed, 15 Jul 2015 22:52:48 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.219.4 with SMTP id pk4ls322991lac.90.gmail; Wed, 15 Jul 2015 22:52:48 -0700 (PDT) X-Received: by 10.152.27.197 with SMTP id v5mr7687497lag.64.1437025968188; Wed, 15 Jul 2015 22:52:48 -0700 (PDT) Received: from mail-lb0-x22f.google.com (mail-lb0-x22f.google.com. [2a00:1450:4010:c04::22f]) by mx.google.com with ESMTPS id kz1si6014549lab.19.2015.07.15.22.52.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jul 2015 22:52:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::22f as permitted sender) client-ip=2a00:1450:4010:c04::22f; Received: by lbbzr7 with SMTP id zr7so37397631lbb.1 for ; Wed, 15 Jul 2015 22:52:48 -0700 (PDT) X-Received: by 10.112.55.207 with SMTP id u15mr7672619lbp.88.1437025967935; Wed, 15 Jul 2015 22:52:47 -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 hn6csp26620lbb; Wed, 15 Jul 2015 22:52:46 -0700 (PDT) X-Received: by 10.66.66.65 with SMTP id d1mr15344496pat.22.1437025965603; Wed, 15 Jul 2015 22:52:45 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id cf11si11206293pdb.97.2015.07.15.22.52.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jul 2015 22:52:45 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-403082-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 37533 invoked by alias); 16 Jul 2015 05:52:32 -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 37520 invoked by uid 89); 16 Jul 2015 05:52:31 -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-pd0-f175.google.com Received: from mail-pd0-f175.google.com (HELO mail-pd0-f175.google.com) (209.85.192.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 16 Jul 2015 05:52:30 +0000 Received: by pdjr16 with SMTP id r16so38305693pdj.3 for ; Wed, 15 Jul 2015 22:52:28 -0700 (PDT) X-Received: by 10.70.128.34 with SMTP id nl2mr15272548pdb.43.1437025948050; Wed, 15 Jul 2015 22:52:28 -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 pc5sm6540084pbc.15.2015.07.15.22.52.24 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Jul 2015 22:52:26 -0700 (PDT) Message-ID: <55A74691.3050303@linaro.org> Date: Thu, 16 Jul 2015 15:52:17 +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> In-Reply-To: <55A6AA4D.1030106@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:c04::22f 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 >> >> 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)) Thanks, Kugan gcc/ChangeLog: 2015-07-16 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 932c83a..78c80d6 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,10 @@ 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; /* Test whether lhs is consumed only by a PHI in the only successor bb. */ @@ -2743,10 +2758,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 +3157,8 @@ maybe_optimize_range_tests (gimple stmt) /* stmt is _123 = (int) _234; + OR + _234 = a_2(D) == 2; followed by: : @@ -3161,6 +3188,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 +3202,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 +3312,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);