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: 495459 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CEE3D1402B1 for ; Wed, 15 Jul 2015 17:10:13 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=PuloNdLi; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=ACcbS9+lWDaAm8zcL wrpz4G4016+g5dv4QLd/JzZoGab3MM4VUo6xj1XZi6PVgaIXNrtylnuyznKXmlnA WrCDu58DRxTTAIYuuB0uU5Mvnd/8aL6OL/Ma2Jaj4UpV3yZz95sVZs1hcL9i2Zvt DE+grBq8ANqCs9jXrYIUgaVV/o= 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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=jr0r4CsHaza1WdIGbki9Gq9 WhHA=; b=PuloNdLinKUKQIeo+l9Itl00tF9mQjIkq3t2ohXQOE+abrlPsNAieh6 Eoobs6XZTBCpyHsCHg0vW9DK7ScwUxsP8IXznEmbcmUbcIrnSm/2cOoh0rDYNhmO RPFQ7cdIjRpWM4RnC9YdI5LLM18NFakEsMnZHqUzylgABT6OzzLU= Received: (qmail 116976 invoked by alias); 15 Jul 2015 07:10:04 -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 116961 invoked by uid 89); 15 Jul 2015 07:10:03 -0000 Authentication-Results: sourceware.org; auth=none 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-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type; bh=Pn8mUhnUHPNK3VjhgLVdY1FdB/oz9Y+Ox/tG+hDh1vQ=; b=RiUyHBft7JPIgzkNljW7ncJvBsl6cLsXy0FfXxPuh3mWceRcv6lMXg3g4/zxv9PZNi a/3qYUHAVL/GYOt/ntgfDJQzpRkocZKh/femMhZmwgyEil7BxTpoFmKkQd1be0RIuwdz RgBvrsYpiTJgsmPcUf8tZgS+3Ab/JzIZ03l5Te5kCTC1/74ULwdpB2fyDKEouEn/Gys3 dzEFOzuHbeUXU4TR+/HgFFntGO1+aMWM90hlglQa/caFuGGEvUF0/eLlHAyBRiyJbfom pX9pRdCJzbVwxdtEBFx5XWA0w7773UF12vxRFT4R5bg8IOaTVrr8pmZrWTnpXNpIALTj fquQ== X-Gm-Message-State: ALoCoQl7PqnSZu009LEl8uxPd8OxLcG1UpXbww0s5mr5qLmn8Vu4+iMptPG5dMGZ7x9RPNqJ/xX4 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 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);