From patchwork Mon Jul 29 09:10:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1138255 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-505748-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="xK+GHnHN"; 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 45xv7L681tz9s7T for ; Mon, 29 Jul 2019 19:11:08 +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:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=GodHMBYMmu5aGdvOZAlRbrHwx+bPUoy0AX8aX6dEpbtzmVk0CwnjN 3H/0+r9XZjC1wVW3+qO8tLd0eIyU1Bj6Bk/8XpmG8d0qj04VWBIglGRgCoxMp7ki CG0qAEUtobt/lPEUOYPiMnzRkAiwNX6vY9jJ593+Zh4vJr6Kp2e4tg= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=fJal6b2fA22JAbR6ZVn/nrAZfPY=; b=xK+GHnHNS+wcSKXWwb28 N7aZS2tjZq/AXE67M2278Imugf8J1vrG07cVM46u1WMQBrwuhqfZ8cOKYAjyeB+i G2yOgqSG6ZGyks36Hr/AggRL2qZS4GRTcTwgJQoTwdKUXShhGbsNj2AeJgnht0q7 XtAqy1HhtcuYPhP1PGH0oIU= Received: (qmail 38013 invoked by alias); 29 Jul 2019 09:11:00 -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 38005 invoked by uid 89); 29 Jul 2019 09:11:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy=interior X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 29 Jul 2019 09:10:59 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 810D4337 for ; Mon, 29 Jul 2019 02:10:57 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.39]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 292C73F694 for ; Mon, 29 Jul 2019 02:10:57 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Fix inchash handling of wide_ints (PR91242) Date: Mon, 29 Jul 2019 10:10:56 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes inchash::hash::add_wide_int operated directly on the raw encoding of the wide_int, including any redundant upper bits. The problem with that is that the upper bits are only defined for some wide-int storage types (including wide_int itself). wi::to_wide(tree) instead returns a value that is extended according to the signedness of the type (so that wi::to_widest can use the same encoding) while rtxes have the awkward special case of BI, which can be zero-extended rather than sign-extended. In the PR, we computed a hash for a "normal" sign-extended wide_int while the existing entries hashed wi::to_wide(tree). This gives different results for unsigned types that have the top bit set. The patch fixes that by hashing the canonical sign-extended form even if the raw encoding happens to be different. Tested on aarch64-linux-gnu (with and without SVE), armeb-eabi and x86_64-linux-gnu. OK to install? Richard 2019-07-29 Richard Sandiford gcc/ * wide-int.h (generic_wide_int::sext_elt): New function. * inchash.h (hash::add_wide_int): Use it instead of elt. Index: gcc/wide-int.h =================================================================== --- gcc/wide-int.h 2019-07-10 19:41:26.391898059 +0100 +++ gcc/wide-int.h 2019-07-29 10:08:12.048610030 +0100 @@ -730,6 +730,7 @@ class GTY(()) generic_wide_int : public /* Public accessors for the interior of a wide int. */ HOST_WIDE_INT sign_mask () const; HOST_WIDE_INT elt (unsigned int) const; + HOST_WIDE_INT sext_elt (unsigned int) const; unsigned HOST_WIDE_INT ulow () const; unsigned HOST_WIDE_INT uhigh () const; HOST_WIDE_INT slow () const; @@ -909,6 +910,23 @@ generic_wide_int ::elt (unsigne return this->get_val ()[i]; } +/* Like elt, but sign-extend beyond the upper bit, instead of returning + the raw encoding. */ +template +inline HOST_WIDE_INT +generic_wide_int ::sext_elt (unsigned int i) const +{ + HOST_WIDE_INT elt_i = elt (i); + if (!is_sign_extended) + { + unsigned int precision = this->get_precision (); + unsigned int lsb = i * HOST_BITS_PER_WIDE_INT; + if (precision - lsb < HOST_BITS_PER_WIDE_INT) + elt_i = sext_hwi (elt_i, precision - lsb); + } + return elt_i; +} + template template inline generic_wide_int & Index: gcc/inchash.h =================================================================== --- gcc/inchash.h 2019-03-08 18:15:36.704740334 +0000 +++ gcc/inchash.h 2019-07-29 10:08:12.048610030 +0100 @@ -85,7 +85,7 @@ hashval_t iterative_hash_hashval_t (hash { add_int (x.get_len ()); for (unsigned i = 0; i < x.get_len (); i++) - add_hwi (x.elt (i)); + add_hwi (x.sext_elt (i)); } /* Hash in pointer PTR. */