From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15747 invoked by alias); 19 Nov 2013 12:00:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 15735 invoked by uid 89); 19 Nov 2013 12:00:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.5 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,RDNS_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mail-ea0-f173.google.com Received: from Unknown (HELO mail-ea0-f173.google.com) (209.85.215.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 19 Nov 2013 12:00:46 +0000 Received: by mail-ea0-f173.google.com with SMTP id g15so2337207eak.32 for ; Tue, 19 Nov 2013 04:00:36 -0800 (PST) X-Received: by 10.14.69.200 with SMTP id n48mr2809488eed.54.1384862436216; Tue, 19 Nov 2013 04:00:36 -0800 (PST) Received: from localhost ([2.28.235.51]) by mx.google.com with ESMTPSA id w6sm48039348eeo.12.2013.11.19.04.00.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Nov 2013 04:00:35 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, rdsandiford@googlemail.com Subject: [2/4] Use tree_to_uhwi when folding (x >> c) << c References: <871u2cpq4u.fsf@talisman.default> Date: Tue, 19 Nov 2013 12:51:00 -0000 In-Reply-To: <871u2cpq4u.fsf@talisman.default> (Richard Sandiford's message of "Tue, 19 Nov 2013 11:50:09 +0000") Message-ID: <87pppwob30.fsf@talisman.default> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-11/txt/msg02271.txt.bz2 The (x >> c) << c folding has: && tree_fits_shwi_p (arg1) && TREE_INT_CST_LOW (arg1) < prec && tree_fits_shwi_p (TREE_OPERAND (arg0, 1)) && TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)) < prec) At first glance the use of tree_fits_shwi_p rather than tree_fits_uhwi_p made me think this allows negative shift counts, but of course TREE_INT_CST_LOW is unsigned. I think it'd be clearer to use tree_fits_uhwi_p instead. Thanks, Richard gcc/ * fold-const.c (fold_binary_loc): Use unsigned rather than signed HOST_WIDE_INTs when folding (x >> c) << c. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c 2013-11-19 10:53:54.965643984 +0000 +++ gcc/fold-const.c 2013-11-19 11:59:33.611252297 +0000 @@ -12676,13 +12676,13 @@ fold_binary_loc (location_t loc, if (((code == LSHIFT_EXPR && TREE_CODE (arg0) == RSHIFT_EXPR) || (TYPE_UNSIGNED (type) && code == RSHIFT_EXPR && TREE_CODE (arg0) == LSHIFT_EXPR)) - && tree_fits_shwi_p (arg1) - && TREE_INT_CST_LOW (arg1) < prec - && tree_fits_shwi_p (TREE_OPERAND (arg0, 1)) - && TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)) < prec) + && tree_fits_uhwi_p (arg1) + && tree_to_uhwi (arg1) < prec + && tree_fits_uhwi_p (TREE_OPERAND (arg0, 1)) + && tree_to_uhwi (TREE_OPERAND (arg0, 1)) < prec) { - HOST_WIDE_INT low0 = TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)); - HOST_WIDE_INT low1 = TREE_INT_CST_LOW (arg1); + HOST_WIDE_INT low0 = tree_to_uhwi (TREE_OPERAND (arg0, 1)); + HOST_WIDE_INT low1 = tree_to_uhwi (arg1); tree lshift; tree arg00;