From patchwork Thu May 23 19:47:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 246019 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 8D9052C0040 for ; Fri, 24 May 2013 05:48:04 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=k0qixGUfFBQ7B696P7Rl/tBE+JIqWKSZeW0PyVTuWcfi2AVqscgm/ HDqpgfRxTFyxl0S1LNbFbKwGLzc+4qaceyPWY0x/sAuyx23bwV7qNYoJtlG4kaA7 6EIZHta2sVj2ZtKncSxAfAPl5JUBWJh/L2f0vAn8XkDoR5Oql1WJLw= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=PpGg7/HvMHncdQfiP+yrhnjkGcE=; b=yh+3WF2AQzDFXXhOchb1 OBaoIb4mrsMmmpjOL1wCd+wKMZ8GXWJWr6dB6v1CMM5aazbK9sjqeURnERr6IKza dI68y1CGFTOVKydxMIfRJ7bM9IgVB7i4SJ8stGevx2d6yzEb1pEi5/63GJIPUYw3 3KNUFVS1PILSTK89yfzwx/k= Received: (qmail 17449 invoked by alias); 23 May 2013 19:47:58 -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 17439 invoked by uid 89); 23 May 2013 19:47:58 -0000 X-Spam-SWARE-Status: No, score=-5.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from mail3-relais-sop.national.inria.fr (HELO mail3-relais-sop.national.inria.fr) (192.134.164.104) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 23 May 2013 19:47:56 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 23 May 2013 21:47:53 +0200 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1UfbUP-0006z2-2Z for gcc-patches@gcc.gnu.org; Thu, 23 May 2013 21:47:53 +0200 Date: Thu, 23 May 2013 21:47:53 +0200 (CEST) From: Marc Glisse To: gcc-patches@gcc.gnu.org Subject: Use unsigned(-1) for lshift Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-Virus-Found: No Hello, this is a simple patch to reduce a bit the noise in PR57324 (undefined behavior flagged by clang). I only handled some of the most obvious ones. Passes bootstrap+testsuite on x86_64-linux-gnu. 2013-05-24 Marc Glisse PR other/57324 * expmed.c (expand_smod_pow2): Use an unsigned -1 for lshift. * fold-const.c (fold_unary_loc): Likewise. * double-int.c (rshift_double, lshift_double): Likewise. * cse.c (cse_insn): Likewise. * tree.c (integer_pow2p, tree_log2, tree_floor_log2): Likewise. * tree-ssa-structalias.c (UNKNOWN_OFFSET): Shift 1 instead of -1. Index: gcc/double-int.c =================================================================== --- gcc/double-int.c (revision 199256) +++ gcc/double-int.c (working copy) @@ -264,21 +264,22 @@ rshift_double (unsigned HOST_WIDE_INT l1 if (count >= prec) { *hv = signmask; *lv = signmask; } else if ((prec - count) >= HOST_BITS_PER_DOUBLE_INT) ; else if ((prec - count) >= HOST_BITS_PER_WIDE_INT) { - *hv &= ~((HOST_WIDE_INT) (-1) << (prec - count - HOST_BITS_PER_WIDE_INT)); + *hv &= ~((unsigned HOST_WIDE_INT) (-1) + << (prec - count - HOST_BITS_PER_WIDE_INT)); *hv |= signmask << (prec - count - HOST_BITS_PER_WIDE_INT); } else { *hv = signmask; *lv &= ~((unsigned HOST_WIDE_INT) (-1) << (prec - count)); *lv |= signmask << (prec - count); } } @@ -321,21 +322,21 @@ lshift_double (unsigned HOST_WIDE_INT l1 signmask = -((prec > HOST_BITS_PER_WIDE_INT ? ((unsigned HOST_WIDE_INT) *hv >> (prec - HOST_BITS_PER_WIDE_INT - 1)) : (*lv >> (prec - 1))) & 1); if (prec >= HOST_BITS_PER_DOUBLE_INT) ; else if (prec >= HOST_BITS_PER_WIDE_INT) { - *hv &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); + *hv &= ~((unsigned HOST_WIDE_INT) -1 << (prec - HOST_BITS_PER_WIDE_INT)); *hv |= signmask << (prec - HOST_BITS_PER_WIDE_INT); } else { *hv = signmask; *lv &= ~((unsigned HOST_WIDE_INT) (-1) << prec); *lv |= signmask << prec; } } Index: gcc/tree-ssa-structalias.c =================================================================== --- gcc/tree-ssa-structalias.c (revision 199256) +++ gcc/tree-ssa-structalias.c (working copy) @@ -475,21 +475,21 @@ struct constraint_expr /* Offset, in bits, of this constraint from the beginning of variables it ends up referring to. IOW, in a deref constraint, we would deref, get the result set, then add OFFSET to each member. */ HOST_WIDE_INT offset; }; /* Use 0x8000... as special unknown offset. */ -#define UNKNOWN_OFFSET ((HOST_WIDE_INT)-1 << (HOST_BITS_PER_WIDE_INT-1)) +#define UNKNOWN_OFFSET ((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT-1)) typedef struct constraint_expr ce_s; static void get_constraint_for_1 (tree, vec *, bool, bool); static void get_constraint_for (tree, vec *); static void get_constraint_for_rhs (tree, vec *); static void do_deref (vec *); /* Our set constraints are made up of two constraint expressions, one LHS, and one RHS. Index: gcc/cse.c =================================================================== --- gcc/cse.c (revision 199256) +++ gcc/cse.c (working copy) @@ -5374,21 +5374,21 @@ cse_insn (rtx insn) may not equal what was stored, due to truncation. */ if (GET_CODE (SET_DEST (sets[i].rtl)) == ZERO_EXTRACT) { rtx width = XEXP (SET_DEST (sets[i].rtl), 1); if (src_const != 0 && CONST_INT_P (src_const) && CONST_INT_P (width) && INTVAL (width) < HOST_BITS_PER_WIDE_INT && ! (INTVAL (src_const) - & ((HOST_WIDE_INT) (-1) << INTVAL (width)))) + & ((unsigned HOST_WIDE_INT) (-1) << INTVAL (width)))) /* Exception: if the value is constant, and it won't be truncated, record it. */ ; else { /* This is chosen so that the destination will be invalidated but no new value will be recorded. We must invalidate because sometimes constant values can be recorded for bitfields. */ sets[i].src_elt = 0; Index: gcc/expmed.c =================================================================== --- gcc/expmed.c (revision 199256) +++ gcc/expmed.c (working copy) @@ -3688,39 +3688,39 @@ expand_smod_pow2 (enum machine_mode mode } /* Mask contains the mode's signbit and the significant bits of the modulus. By including the signbit in the operation, many targets can avoid an explicit compare operation in the following comparison against zero. */ masklow = ((HOST_WIDE_INT) 1 << logd) - 1; if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) { - masklow |= (HOST_WIDE_INT) -1 << (GET_MODE_BITSIZE (mode) - 1); + masklow |= (unsigned HOST_WIDE_INT) -1 << (GET_MODE_BITSIZE (mode) - 1); maskhigh = -1; } else - maskhigh = (HOST_WIDE_INT) -1 + maskhigh = (unsigned HOST_WIDE_INT) -1 << (GET_MODE_BITSIZE (mode) - HOST_BITS_PER_WIDE_INT - 1); temp = expand_binop (mode, and_optab, op0, immed_double_const (masklow, maskhigh, mode), result, 1, OPTAB_LIB_WIDEN); if (temp != result) emit_move_insn (result, temp); label = gen_label_rtx (); do_cmp_and_jump (result, const0_rtx, GE, mode, label); temp = expand_binop (mode, sub_optab, result, const1_rtx, result, 0, OPTAB_LIB_WIDEN); - masklow = (HOST_WIDE_INT) -1 << logd; + masklow = (unsigned HOST_WIDE_INT) -1 << logd; maskhigh = -1; temp = expand_binop (mode, ior_optab, temp, immed_double_const (masklow, maskhigh, mode), result, 1, OPTAB_LIB_WIDEN); temp = expand_binop (mode, add_optab, temp, const1_rtx, result, 0, OPTAB_LIB_WIDEN); if (temp != result) emit_move_insn (result, temp); emit_label (label); return result; Index: gcc/tree.c =================================================================== --- gcc/tree.c (revision 199256) +++ gcc/tree.c (working copy) @@ -1935,26 +1935,26 @@ integer_pow2p (const_tree expr) prec = TYPE_PRECISION (TREE_TYPE (expr)); high = TREE_INT_CST_HIGH (expr); low = TREE_INT_CST_LOW (expr); /* First clear all bits that are beyond the type's precision in case we've been sign extended. */ if (prec == HOST_BITS_PER_DOUBLE_INT) ; else if (prec > HOST_BITS_PER_WIDE_INT) - high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); + high &= ~((unsigned HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); else { high = 0; if (prec < HOST_BITS_PER_WIDE_INT) - low &= ~((HOST_WIDE_INT) (-1) << prec); + low &= ~((unsigned HOST_WIDE_INT) (-1) << prec); } if (high == 0 && low == 0) return 0; return ((high == 0 && (low & (low - 1)) == 0) || (low == 0 && (high & (high - 1)) == 0)); } /* Return 1 if EXPR is an integer constant other than zero or a @@ -1999,26 +1999,26 @@ tree_log2 (const_tree expr) prec = TYPE_PRECISION (TREE_TYPE (expr)); high = TREE_INT_CST_HIGH (expr); low = TREE_INT_CST_LOW (expr); /* First clear all bits that are beyond the type's precision in case we've been sign extended. */ if (prec == HOST_BITS_PER_DOUBLE_INT) ; else if (prec > HOST_BITS_PER_WIDE_INT) - high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); + high &= ~((unsigned HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); else { high = 0; if (prec < HOST_BITS_PER_WIDE_INT) - low &= ~((HOST_WIDE_INT) (-1) << prec); + low &= ~((unsigned HOST_WIDE_INT) (-1) << prec); } return (high != 0 ? HOST_BITS_PER_WIDE_INT + exact_log2 (high) : exact_log2 (low)); } /* Similar, but return the largest integer Y such that 2 ** Y is less than or equal to EXPR. */ int @@ -2036,26 +2036,26 @@ tree_floor_log2 (const_tree expr) high = TREE_INT_CST_HIGH (expr); low = TREE_INT_CST_LOW (expr); /* First clear all bits that are beyond the type's precision in case we've been sign extended. Ignore if type's precision hasn't been set since what we are doing is setting it. */ if (prec == HOST_BITS_PER_DOUBLE_INT || prec == 0) ; else if (prec > HOST_BITS_PER_WIDE_INT) - high &= ~((HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); + high &= ~((unsigned HOST_WIDE_INT) (-1) << (prec - HOST_BITS_PER_WIDE_INT)); else { high = 0; if (prec < HOST_BITS_PER_WIDE_INT) - low &= ~((HOST_WIDE_INT) (-1) << prec); + low &= ~((unsigned HOST_WIDE_INT) (-1) << prec); } return (high != 0 ? HOST_BITS_PER_WIDE_INT + floor_log2 (high) : floor_log2 (low)); } /* Return 1 if EXPR is the real constant zero. Trailing zeroes matter for decimal float constants, so don't return 1 for them. */ int Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 199256) +++ gcc/fold-const.c (working copy) @@ -8049,21 +8049,21 @@ fold_unary_loc (location_t loc, enum tre || (TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (and_expr)))) change = 1; else if (TYPE_PRECISION (TREE_TYPE (and1)) <= HOST_BITS_PER_WIDE_INT && host_integerp (and1, 1)) { unsigned HOST_WIDE_INT cst; cst = tree_low_cst (and1, 1); - cst &= (HOST_WIDE_INT) -1 + cst &= (unsigned HOST_WIDE_INT) -1 << (TYPE_PRECISION (TREE_TYPE (and1)) - 1); change = (cst == 0); #ifdef LOAD_EXTEND_OP if (change && !flag_syntax_only && (LOAD_EXTEND_OP (TYPE_MODE (TREE_TYPE (and0))) == ZERO_EXTEND)) { tree uns = unsigned_type_for (TREE_TYPE (and0)); and0 = fold_convert_loc (loc, uns, and0);