From patchwork Sun Dec 23 16:48:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 207988 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]) by ozlabs.org (Postfix) with SMTP id C79C02C0085 for ; Mon, 24 Dec 2012 03:49:21 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1356886162; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: From:To:Mail-Followup-To:Subject:Date:Message-ID:User-Agent: MIME-Version:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=QhEgFgdl4F+Ac+WV5PcqJkZ52o0=; b=SuIksgN330hBpeY /UalJRGPsVj06yOqqiI0RE6j2TRkvdEUbt4YfM/R5fof+koIeXwOmhXWseaaXI8g f3JdV/it28w2QZPORW+ikw0yAqrpqF2asXjW0ZhdIRTg86VXbc/GXJKxiuQfEucl cm5zl50K+4NN8WhmHiBhy09/M4rI= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Received:Received:From:To:Mail-Followup-To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Eiy+ly+BcNsfrkRthKHD0ySzZYoJXXTTE+idX5vQ1MTvI2kv6ED6udtWtZfG17 acuCJHTejixpdKhTJVpYyL2LqAkfeyyCfe/Fc27YcWB8hHMsie6gHyAeFqyId8ic T2AQEzRNIWm7ZX1KXiznv1swov0JuksRK2/qdKaOoXZ04=; Received: (qmail 1803 invoked by alias); 23 Dec 2012 16:49:13 -0000 Received: (qmail 1786 invoked by uid 22791); 23 Dec 2012 16:49:10 -0000 X-SWARE-Spam-Status: No, hits=-3.2 required=5.0 tests=AWL, BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, KHOP_RCVD_TRUST, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-wg0-f46.google.com (HELO mail-wg0-f46.google.com) (74.125.82.46) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 23 Dec 2012 16:49:07 +0000 Received: by mail-wg0-f46.google.com with SMTP id dr13so2864457wgb.25 for ; Sun, 23 Dec 2012 08:49:03 -0800 (PST) X-Received: by 10.180.81.39 with SMTP id w7mr31664483wix.15.1356281343338; Sun, 23 Dec 2012 08:49:03 -0800 (PST) Received: from localhost ([2.28.234.219]) by mx.google.com with ESMTPS id fv2sm39268482wib.4.2012.12.23.08.49.01 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 23 Dec 2012 08:49:02 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, rdsandiford@googlemail.com Subject: RFA: Fix uint128_t range checking in VRP Date: Sun, 23 Dec 2012 16:48:59 +0000 Message-ID: <87d2y0vhms.fsf@talisman.default> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 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 The minimum uint128_t value is an all-zeros double_int and the maximum value is an all-ones double_int. Truncating these values to int and then sign-extending them gives the same all-zeros and all-ones values, so tree-vrp.c:range_fits_type_p concludes that uint128_t fits in an int. This showed up as a miscompilation of __fractutasf on mips64-linux-gnu, which in turn showed up in convert-float-4.c. There was already code to handle this problem when changing the sign and keeping the precision, but I think the rule applies regardless of precision. Tested on x86_64-linux-gnu and mips64-linux-gnu. OK to install? Richard gcc/ * tree-vrp.c (range_fits_type_p): Require the MSB of the double_int to be clear for sign changes. gcc/testsuite/ * gcc.dg/torture/fp-int-convert-2.c: New test. Index: gcc/tree-vrp.c =================================================================== --- gcc/tree-vrp.c 2012-12-23 11:50:39.046419271 +0000 +++ gcc/tree-vrp.c 2012-12-23 11:51:17.814677008 +0000 @@ -8766,9 +8766,11 @@ range_fits_type_p (value_range_t *vr, un || TREE_CODE (vr->max) != INTEGER_CST) return false; - /* For precision-preserving sign-changes the MSB of the double-int - has to be clear. */ - if (src_precision == precision + /* For sign changes, the MSB of the double_int has to be clear. + An unsigned value with its MSB set cannot be represented by + a signed double_int, while a negative value cannot be represented + by an unsigned double_int. */ + if (TYPE_UNSIGNED (src_type) != unsigned_p && (TREE_INT_CST_HIGH (vr->min) | TREE_INT_CST_HIGH (vr->max)) < 0) return false; Index: gcc/testsuite/gcc.dg/torture/fp-int-convert-2.c =================================================================== --- /dev/null 2012-12-03 19:06:31.446621561 +0000 +++ gcc/testsuite/gcc.dg/torture/fp-int-convert-2.c 2012-12-23 13:46:35.449077882 +0000 @@ -0,0 +1,18 @@ +/* { dg-do run } */ +/* { dg-require-effective-target int128 } */ + +extern void abort (void); + +float __attribute__((noinline)) +f (__uint128_t x) +{ + return x + 1; +} + +int +main (void) +{ + if (f (0xffffffffu) == 0) + abort (); + return 0; +}