From patchwork Mon Aug 10 21:48:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 505797 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 3AEA8140187 for ; Tue, 11 Aug 2015 07:48:41 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=UEy8GJSp; 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:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=hgY1ZZB6IEq7DlGXedfxjJEbSPCp0aqhelo3rrf/YPrACMWEai yNT7pCewqXaj6LLJFmoJsgRccDneeIdJvR07ET3mwxPWAAgrmLGuRwW0v082Dvz5 +6wOxcY1eFy3j6qfer3LFDuumsPjxXZJgB2oxK81Lr05JbHN4mhlxNIpY= 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=6jBCY3TUO0MtMhW2rzQeC8kxPfY=; b=UEy8GJSp9b4hSirbuojJ +ZoKg93HRnhLtoAXDzDFOQ2IC6GW1cg/KABBwN4dinaLJp3BJ5tRDEgYqmYPM8Wr vI1mFemd6Zd4jVz5mAQ2353PfiFDRLVBasVUttMS9s5UaL0d8VM0kRSW34BQlVoD Er/+gAAHfX+peX5rKt1ZCLQ= Received: (qmail 5276 invoked by alias); 10 Aug 2015 21:48:35 -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 5262 invoked by uid 89); 10 Aug 2015 21:48:34 -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, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qk0-f174.google.com Received: from mail-qk0-f174.google.com (HELO mail-qk0-f174.google.com) (209.85.220.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 10 Aug 2015 21:48:34 +0000 Received: by qkfj126 with SMTP id j126so11893400qkf.0 for ; Mon, 10 Aug 2015 14:48:31 -0700 (PDT) X-Received: by 10.55.20.70 with SMTP id e67mr2313922qkh.36.1439243311769; Mon, 10 Aug 2015 14:48:31 -0700 (PDT) Received: from ?IPv6:2601:181:c000:c497:a2a8:cdff:fe3e:b48? ([2601:181:c000:c497:a2a8:cdff:fe3e:b48]) by smtp.googlemail.com with ESMTPSA id a8sm1280625qka.33.2015.08.10.14.48.30 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Aug 2015 14:48:30 -0700 (PDT) To: Richard Guenther Cc: GCC Patches From: Nathan Sidwell Subject: [optimize 2/3] Simplify vrp abs conversion Message-ID: <55C91C2D.7040407@acm.org> Date: Mon, 10 Aug 2015 17:48:29 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 Richard, in looking at how simplify_abs_using_ranges was doing its thing as a guide to a min/max vrp optimization, I noticed it was doing more work than necessary. Firstly, it wasn't taking advantage of the range comparison functions only returning TRUE or FALSE nodes when there's a definite answer, and NULL otherwise. Thus if we get a node, we don't have to (a) check if it's either true or false and (b) we only need to check for one of those values to determine which specific answer was given. Also, it was checking for 'NOT (A >= B)' by inverting the result of a '>=' check, rather than simply doing a '<' check. (we're dealing with integer ranges, so that's all well defined) Finally, there's a useless check for UNSIGNED_TYPE, which ends up doing nothing. AFAICT 'ABS (unsigned)' gets folded out very early on. booted and tested with the phi-min-max fix I just posted and the new VRP-min-max optimization I'm about to. ok? nathan 2015-08-10 Nathan Sidwell * tree-vrp.c (simplify_abs_using_ranges): Simplify. Index: tree-vrp.c =================================================================== --- tree-vrp.c (revision 226749) +++ tree-vrp.c (working copy) @@ -9152,37 +9215,25 @@ simplify_div_or_mod_using_ranges (gimple static bool simplify_abs_using_ranges (gimple stmt) { - tree val = NULL; tree op = gimple_assign_rhs1 (stmt); - tree type = TREE_TYPE (op); value_range_t *vr = get_value_range (op); - if (TYPE_UNSIGNED (type)) - { - val = integer_zero_node; - } - else if (vr) + if (vr) { + tree val = NULL; bool sop = false; val = compare_range_with_value (LE_EXPR, vr, integer_zero_node, &sop); if (!val) { + /* The range is neither <= 0 nor > 0. Now see if it is + either < 0 or >= 0. */ sop = false; - val = compare_range_with_value (GE_EXPR, vr, integer_zero_node, + val = compare_range_with_value (LT_EXPR, vr, integer_zero_node, &sop); - - if (val) - { - if (integer_zerop (val)) - val = integer_one_node; - else if (integer_onep (val)) - val = integer_zero_node; - } } - if (val - && (integer_onep (val) || integer_zerop (val))) + if (val) { if (sop && issue_strict_overflow_warning (WARN_STRICT_OVERFLOW_MISC)) { @@ -9198,10 +9249,10 @@ simplify_abs_using_ranges (gimple stmt) } gimple_assign_set_rhs1 (stmt, op); - if (integer_onep (val)) - gimple_assign_set_rhs_code (stmt, NEGATE_EXPR); - else + if (integer_zerop (val)) gimple_assign_set_rhs_code (stmt, SSA_NAME); + else + gimple_assign_set_rhs_code (stmt, NEGATE_EXPR); update_stmt (stmt); return true; }