From patchwork Tue Sep 11 10:09:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 968485 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-485426-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="kM5/ZrDT"; dkim-atps=neutral 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 428gcq6c4Kz9s4s for ; Tue, 11 Sep 2018 20:09:30 +1000 (AEST) 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=DyqKIzCaN2bYDdoGn1SxaPq4JXeJKscYJqP7cZR2FqReKlESgW hEBMZ/hqWm62YI/6qQrqAXdT8MEI4QMTAQFrdaFu1C9vSgdnUHfV0Id0dAVjXMjX rjAtKwmgoMswco4QQMR6kdeytpLZL9OfejgGFHLH00zx7DoyUrJxzCDFE= 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=hEzGs9Vp9OL5xtSLiIWh53l6PUA=; b=kM5/ZrDTG1I9StgDCKuI nc8peIq5cDuGF3rmv4+x6Ut9nbZWVNuHhBlZmbOxv64jSL3i2nYOx3xX2QyA58H/ daL6X5k8CnVvLkeYK38NKIh8clF4iF7/JOM6sNUzNWMixc5kpoO/8Ew34Kul6Te/ ERfhpeU9RpE0Sqh9aEMtpxM= Received: (qmail 36022 invoked by alias); 11 Sep 2018 10:09:23 -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 36000 invoked by uid 89); 11 Sep 2018 10:09:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=CODE, hernandez, brain, HX-Received:sk:d5-v6mr X-HELO: mail-wr1-f46.google.com Received: from mail-wr1-f46.google.com (HELO mail-wr1-f46.google.com) (209.85.221.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Sep 2018 10:09:20 +0000 Received: by mail-wr1-f46.google.com with SMTP id k5-v6so25255703wre.10 for ; Tue, 11 Sep 2018 03:09:20 -0700 (PDT) Received: from abulafia.quesejoda.com ([62.252.144.58]) by smtp.gmail.com with ESMTPSA id m8-v6sm12579264wrn.72.2018.09.11.03.09.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 03:09:17 -0700 (PDT) To: gcc-patches From: Aldy Hernandez Subject: VRP: undefined shifting calculation should not need sign bit Message-ID: <1ab7411f-d602-5aa6-4b4a-02c066d693a3@redhat.com> Date: Tue, 11 Sep 2018 06:09:16 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 X-IsSubscribed: yes We can calculate wide_int_range_shift_undefined_p() without having to pass down the sign bit of the operand. Also, vrp_shift_undefined_p is a brain dead wrapper so I'm removing it. OK for trunk? commit 9aeb62d4c33b50bc007b07ec5097e8f3edd4b31b Author: Aldy Hernandez Date: Mon Sep 10 17:46:10 2018 +0200 * tree-vrp.c (vrp_shift_undefined_p): Remove. (extract_range_from_binary_expr_1: Call wide_int_range_shift_undefined_p instead of vrp_shift_undefined_p. * wide-int-range.h (wide_int_range_shift_undefined_p): Do not depend on sign. diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 653e45b50a4..1adb919a6df 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -1018,17 +1018,6 @@ extract_range_into_wide_ints (const value_range *vr, } } -/* Value range wrapper for wide_int_range_shift_undefined_p. */ - -static inline bool -vrp_shift_undefined_p (const value_range &shifter, unsigned prec) -{ - tree type = TREE_TYPE (shifter.min); - return wide_int_range_shift_undefined_p (TYPE_SIGN (type), prec, - wi::to_wide (shifter.min), - wi::to_wide (shifter.max)); -} - /* Value range wrapper for wide_int_range_multiplicative_op: *VR = *VR0 .CODE. *VR1. */ @@ -1565,7 +1554,9 @@ extract_range_from_binary_expr_1 (value_range *vr, || code == LSHIFT_EXPR) { if (range_int_cst_p (&vr1) - && !vrp_shift_undefined_p (vr1, prec)) + && !wide_int_range_shift_undefined_p (prec, + wi::to_wide (vr1.min), + wi::to_wide (vr1.max))) { if (code == RSHIFT_EXPR) { diff --git a/gcc/wide-int-range.h b/gcc/wide-int-range.h index 589fdea4df6..e9ee418e5b2 100644 --- a/gcc/wide-int-range.h +++ b/gcc/wide-int-range.h @@ -131,7 +131,7 @@ extern bool wide_int_range_div (wide_int &wmin, wide_int &wmax, /* Return TRUE if shifting by range [MIN, MAX] is undefined behavior. */ inline bool -wide_int_range_shift_undefined_p (signop sign, unsigned prec, +wide_int_range_shift_undefined_p (unsigned prec, const wide_int &min, const wide_int &max) { /* ?? Note: The original comment said this only applied to @@ -142,7 +142,7 @@ wide_int_range_shift_undefined_p (signop sign, unsigned prec, behavior from the shift operation. We cannot even trust SHIFT_COUNT_TRUNCATED at this stage, because that applies to rtl shifts, and the operation at the tree level may be widened. */ - return wi::lt_p (min, 0, sign) || wi::ge_p (max, prec, sign); + return wi::sign_mask (min) || wi::ge_p (max, prec, UNSIGNED); } /* Calculate MIN/MAX_EXPR of two ranges and store the result in [MIN, MAX]. */