From patchwork Thu Jul 13 08:47:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 107611 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1931648qge; Thu, 13 Jul 2017 01:49:10 -0700 (PDT) X-Received: by 10.99.47.66 with SMTP id v63mr8215763pgv.4.1499935750902; Thu, 13 Jul 2017 01:49:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499935750; cv=none; d=google.com; s=arc-20160816; b=SKp0xh+8dHO/zt1wTiS1+vaJwJQz1Lj5fiBt1R+znlDFR8P2Hd0sGVvPIWwn3R80C8 XUPxsxzObpULVxwXQ/GH/1j8vffygKD0UV+hf2sLL6RSEZjkz9p2NvuJIktWmxf98FVU KyEbAJxmqezfhhAQybqbM79vZT1fKhlxOasaHT5zK2igPznp6Po07Do9TlywaTC/DDlv xCgr6eYrpFlNxAfWmh3blmSOIGOGOPteT2Zgct1fvJjsjLX8U4Y2eCvmwY+Ns/jPsaAk OovmSKz7IlKBFxz31/E0kZR6cxxDqxU//kSgx2Qa31JfwhLc8W4XTWk4lPp/jH9xwEJN p8Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:mail-followup-to:to:from:delivered-to:sender:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=0iUeesH2B9YbapzsY1LTWCXB6dcptKqRH1EJ6wzYXYM=; b=NntZ8FRmzSCi2oUCFGolwEHa9tH5MArhMqDNKpshqOF7Kn/Z/zn/5ytRqbu1249956 Uqj8jAG2GF8ZqoUu+5znRIHFuJ92C4ohDjpUERZPE18wUKgViDv8MYU/l9nvpUpRdQq3 /6+hdAdcfmw3oTt9gLdX3k+/3QEjjqn9OIU/8h0H63o4z3PvHNji2OHaW4mZXN1HYl5c BR0Q6+zvK3nrauBV5QNpnr9On7z6ltgipd8D2Rxa1XqOIP7qRhyjY/BwSY0IqQWDm3Hy G3KvXIVZla+2pf13wBj80W49VtwzXgQjXE30rKpZUdAVKwKoSyhfKqmRyZRyxH+qehYx rQkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=v4XlFDrP; spf=pass (google.com: domain of gcc-patches-return-458016-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458016-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id j191si3696040pgd.195.2017.07.13.01.49.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 01:49:10 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-458016-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=v4XlFDrP; spf=pass (google.com: domain of gcc-patches-return-458016-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458016-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=W4muyCOgRnDIEsFvVBIlH+tLGElPv Q6mgLpFktvQFVH36TY1NF0owTsemD8eW01hI+7SR2E/OvXx/4YaEEw2zZPtEAecx IfWj8PIFJCbFMgBGqMNGX6z2VDK2ir30oKBb/1s1f1H0TnV09yNaavKafihRppXV 8b3/AME1yupBTw= 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:references:date:in-reply-to:message-id:mime-version :content-type; s=default; bh=IVHAYFHKTFZFjGQCngoccgHUk/w=; b=v4X lFDrPTFOqmH5LYgfrJi9ZpPgvsY4p5K5yd7t1Jf47gbIc/UG8AHmnoP5sDWB3OMP XYhMK4L7HZj6Dq2y1Ep0usZkPLfhVB3e366Nus6TSeSjsnm0euqIwadaYc13gJ7F 64Emvlmqej4P9fLXjuCYKR+l5gC5uW5meTakW0GM= Received: (qmail 90860 invoked by alias); 13 Jul 2017 08:48: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 90599 invoked by uid 89); 13 Jul 2017 08:47:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=OTHER, POS X-HELO: mail-wr0-f181.google.com Received: from mail-wr0-f181.google.com (HELO mail-wr0-f181.google.com) (209.85.128.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Jul 2017 08:47:54 +0000 Received: by mail-wr0-f181.google.com with SMTP id c11so49382828wrc.3 for ; Thu, 13 Jul 2017 01:47:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=0iUeesH2B9YbapzsY1LTWCXB6dcptKqRH1EJ6wzYXYM=; b=cvywRx1dd5lmkBxjdEL6WeA8s/oI3XDGT1W2fM2TaK5myRtsQ5PdHekhClBM33y4RA YcfPvlR57NTcb1g7X+UqBZNFU2KKlXLoBQq8Gygib3vZJSHBivI46fchQE4gb6bkjPVW gLx/Sr0Vp2rif6eLD9nmOTJGA3ubfCns9KlQ7Np3tG9AXHTtr8p/dbVmQAB90P/VQczH kPhTM7ieFdCJQ4rPG0Od9+mNTlK/LXPCCoo72MwvH8RsNCPdx/omizqXwSqg7RdOfkAs YfdKdd9D67nkGq9kDWehhjlUrfjZVLf+j0EALSV2MDEmTBXm1U15DurOqQT7iFUWlW0B LIqQ== X-Gm-Message-State: AIVw11329I56r8EaAOvAXVhEOT1pnNwdOtmcxczfpOIA4HO+g8J7MbmS BYNNOK3zf65AOjtON3VtsA== X-Received: by 10.223.170.219 with SMTP id i27mr898531wrc.49.1499935671865; Thu, 13 Jul 2017 01:47:51 -0700 (PDT) Received: from localhost (92.40.249.184.threembb.co.uk. [92.40.249.184]) by smtp.gmail.com with ESMTPSA id o197sm6449232wmd.9.2017.07.13.01.47.50 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jul 2017 01:47:51 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [25/77] Use is_a for bitmask optimisations References: <8760ewohsv.fsf@linaro.org> Date: Thu, 13 Jul 2017 09:47:49 +0100 In-Reply-To: <8760ewohsv.fsf@linaro.org> (Richard Sandiford's message of "Thu, 13 Jul 2017 09:35:44 +0100") Message-ID: <8760ewk9je.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Explicitly check for scalar_int_mode in code that maps arithmetic to full-mode bit operations. These operations wouldn't work correctly for vector modes, for example. In many cases this is enforced also by checking whether an operand is CONST_INT_P, but there were other cases where the condition is more indirect. 2017-07-13 Richard Sandiford Alan Hayward David Sherwood gcc/ * combine.c (combine_simplify_rtx): Add checks for is_a . (simplify_if_then_else): Likewise. (make_field_assignment): Likewise. (simplify_comparison): Likewise. * ifcvt.c (noce_try_bitop): Likewise. * loop-invariant.c (canonicalize_address_mult): Likewise. * simplify-rtx.c (simplify_unary_operation_1): Likewise. Index: gcc/combine.c =================================================================== --- gcc/combine.c 2017-07-13 09:18:33.652251177 +0100 +++ gcc/combine.c 2017-07-13 09:18:34.533172436 +0100 @@ -5850,13 +5850,14 @@ combine_simplify_rtx (rtx x, machine_mod if (!REG_P (temp) && ! (GET_CODE (temp) == SUBREG && REG_P (SUBREG_REG (temp))) - && (i = exact_log2 (nonzero_bits (temp, mode))) >= 0) + && is_a (mode, &int_mode) + && (i = exact_log2 (nonzero_bits (temp, int_mode))) >= 0) { rtx temp1 = simplify_shift_const - (NULL_RTX, ASHIFTRT, mode, - simplify_shift_const (NULL_RTX, ASHIFT, mode, temp, - GET_MODE_PRECISION (mode) - 1 - i), - GET_MODE_PRECISION (mode) - 1 - i); + (NULL_RTX, ASHIFTRT, int_mode, + simplify_shift_const (NULL_RTX, ASHIFT, int_mode, temp, + GET_MODE_PRECISION (int_mode) - 1 - i), + GET_MODE_PRECISION (int_mode) - 1 - i); /* If all we did was surround TEMP with the two shifts, we haven't improved anything, so don't use it. Otherwise, @@ -5947,12 +5948,15 @@ combine_simplify_rtx (rtx x, machine_mod && !REG_P (XEXP (x, 0)) && ! (GET_CODE (XEXP (x, 0)) == SUBREG && REG_P (SUBREG_REG (XEXP (x, 0)))) - && nonzero_bits (XEXP (x, 0), mode) == 1) - return simplify_shift_const (NULL_RTX, ASHIFTRT, mode, - simplify_shift_const (NULL_RTX, ASHIFT, mode, - gen_rtx_XOR (mode, XEXP (x, 0), const1_rtx), - GET_MODE_PRECISION (mode) - 1), - GET_MODE_PRECISION (mode) - 1); + && is_a (mode, &int_mode) + && nonzero_bits (XEXP (x, 0), int_mode) == 1) + return simplify_shift_const + (NULL_RTX, ASHIFTRT, int_mode, + simplify_shift_const (NULL_RTX, ASHIFT, int_mode, + gen_rtx_XOR (int_mode, XEXP (x, 0), + const1_rtx), + GET_MODE_PRECISION (int_mode) - 1), + GET_MODE_PRECISION (int_mode) - 1); /* If we are adding two things that have no bits in common, convert the addition into an IOR. This will often be further simplified, @@ -5990,11 +5994,12 @@ combine_simplify_rtx (rtx x, machine_mod case MINUS: /* (minus (and (const_int -pow2))) becomes (and (const_int pow2-1)) */ - if (GET_CODE (XEXP (x, 1)) == AND + if (is_a (mode, &int_mode) + && GET_CODE (XEXP (x, 1)) == AND && CONST_INT_P (XEXP (XEXP (x, 1), 1)) && pow2p_hwi (-UINTVAL (XEXP (XEXP (x, 1), 1))) && rtx_equal_p (XEXP (XEXP (x, 1), 0), XEXP (x, 0))) - return simplify_and_const_int (NULL_RTX, mode, XEXP (x, 0), + return simplify_and_const_int (NULL_RTX, int_mode, XEXP (x, 0), -INTVAL (XEXP (XEXP (x, 1), 1)) - 1); break; @@ -6025,14 +6030,16 @@ combine_simplify_rtx (rtx x, machine_mod case UDIV: /* If this is a divide by a power of two, treat it as a shift if its first operand is a shift. */ - if (CONST_INT_P (XEXP (x, 1)) + if (is_a (mode, &int_mode) + && CONST_INT_P (XEXP (x, 1)) && (i = exact_log2 (UINTVAL (XEXP (x, 1)))) >= 0 && (GET_CODE (XEXP (x, 0)) == ASHIFT || GET_CODE (XEXP (x, 0)) == LSHIFTRT || GET_CODE (XEXP (x, 0)) == ASHIFTRT || GET_CODE (XEXP (x, 0)) == ROTATE || GET_CODE (XEXP (x, 0)) == ROTATERT)) - return simplify_shift_const (NULL_RTX, LSHIFTRT, mode, XEXP (x, 0), i); + return simplify_shift_const (NULL_RTX, LSHIFTRT, int_mode, + XEXP (x, 0), i); break; case EQ: case NE: @@ -6316,22 +6323,28 @@ simplify_if_then_else (rtx x) std::swap (true_rtx, false_rtx); } - /* If we are comparing against zero and the expression being tested has - only a single bit that might be nonzero, that is its value when it is - not equal to zero. Similarly if it is known to be -1 or 0. */ - - if (true_code == EQ && true_val == const0_rtx - && pow2p_hwi (nzb = nonzero_bits (from, GET_MODE (from)))) - { - false_code = EQ; - false_val = gen_int_mode (nzb, GET_MODE (from)); - } - else if (true_code == EQ && true_val == const0_rtx - && (num_sign_bit_copies (from, GET_MODE (from)) - == GET_MODE_PRECISION (GET_MODE (from)))) + scalar_int_mode from_mode; + if (is_a (GET_MODE (from), &from_mode)) { - false_code = EQ; - false_val = constm1_rtx; + /* If we are comparing against zero and the expression being + tested has only a single bit that might be nonzero, that is + its value when it is not equal to zero. Similarly if it is + known to be -1 or 0. */ + if (true_code == EQ + && true_val == const0_rtx + && pow2p_hwi (nzb = nonzero_bits (from, from_mode))) + { + false_code = EQ; + false_val = gen_int_mode (nzb, from_mode); + } + else if (true_code == EQ + && true_val == const0_rtx + && (num_sign_bit_copies (from, from_mode) + == GET_MODE_PRECISION (from_mode))) + { + false_code = EQ; + false_val = constm1_rtx; + } } /* Now simplify an arm if we know the value of the register in the @@ -6581,16 +6594,19 @@ simplify_if_then_else (rtx x) negation of a single bit, we can convert this operation to a shift. We can actually do this more generally, but it doesn't seem worth it. */ - if (true_code == NE && XEXP (cond, 1) == const0_rtx - && false_rtx == const0_rtx && CONST_INT_P (true_rtx) - && ((1 == nonzero_bits (XEXP (cond, 0), mode) + if (true_code == NE + && is_a (mode, &int_mode) + && XEXP (cond, 1) == const0_rtx + && false_rtx == const0_rtx + && CONST_INT_P (true_rtx) + && ((1 == nonzero_bits (XEXP (cond, 0), int_mode) && (i = exact_log2 (UINTVAL (true_rtx))) >= 0) - || ((num_sign_bit_copies (XEXP (cond, 0), mode) - == GET_MODE_PRECISION (mode)) + || ((num_sign_bit_copies (XEXP (cond, 0), int_mode) + == GET_MODE_PRECISION (int_mode)) && (i = exact_log2 (-UINTVAL (true_rtx))) >= 0))) return - simplify_shift_const (NULL_RTX, ASHIFT, mode, - gen_lowpart (mode, XEXP (cond, 0)), i); + simplify_shift_const (NULL_RTX, ASHIFT, int_mode, + gen_lowpart (int_mode, XEXP (cond, 0)), i); /* (IF_THEN_ELSE (NE A 0) C1 0) is A or a zero-extend of A if the only non-zero bit in A is C1. */ @@ -9483,7 +9499,11 @@ make_field_assignment (rtx x) HOST_WIDE_INT pos; unsigned HOST_WIDE_INT len; rtx other; - machine_mode mode; + + /* All the rules in this function are specific to scalar integers. */ + scalar_int_mode mode; + if (!is_a (GET_MODE (dest), &mode)) + return x; /* If SRC was (and (not (ashift (const_int 1) POS)) DEST), this is a clear of a one-bit field. We will have changed it to @@ -9556,7 +9576,6 @@ make_field_assignment (rtx x) /* Partial overlap. We can reduce the source AND. */ if ((and_mask & ze_mask) != and_mask) { - mode = GET_MODE (src); src = gen_rtx_AND (mode, XEXP (src, 0), gen_int_mode (and_mask & ze_mask, mode)); return gen_rtx_SET (dest, src); @@ -9575,7 +9594,10 @@ make_field_assignment (rtx x) assignment. The first one we are likely to encounter is an outer narrowing SUBREG, which we can just strip for the purposes of identifying the constant-field assignment. */ - if (GET_CODE (src) == SUBREG && subreg_lowpart_p (src)) + scalar_int_mode src_mode = mode; + if (GET_CODE (src) == SUBREG + && subreg_lowpart_p (src) + && is_a (GET_MODE (SUBREG_REG (src)), &src_mode)) src = SUBREG_REG (src); if (GET_CODE (src) != IOR && GET_CODE (src) != XOR) @@ -9621,10 +9643,11 @@ make_field_assignment (rtx x) else return x; - pos = get_pos_from_mask ((~c1) & GET_MODE_MASK (GET_MODE (dest)), &len); - if (pos < 0 || pos + len > GET_MODE_PRECISION (GET_MODE (dest)) - || GET_MODE_PRECISION (GET_MODE (dest)) > HOST_BITS_PER_WIDE_INT - || (c1 & nonzero_bits (other, GET_MODE (dest))) != 0) + pos = get_pos_from_mask ((~c1) & GET_MODE_MASK (mode), &len); + if (pos < 0 + || pos + len > GET_MODE_PRECISION (mode) + || GET_MODE_PRECISION (mode) > HOST_BITS_PER_WIDE_INT + || (c1 & nonzero_bits (other, mode)) != 0) return x; assign = make_extraction (VOIDmode, dest, pos, NULL_RTX, len, 1, 1, 0); @@ -9633,17 +9656,16 @@ make_field_assignment (rtx x) /* The mode to use for the source is the mode of the assignment, or of what is inside a possible STRICT_LOW_PART. */ - mode = (GET_CODE (assign) == STRICT_LOW_PART - ? GET_MODE (XEXP (assign, 0)) : GET_MODE (assign)); + machine_mode new_mode = (GET_CODE (assign) == STRICT_LOW_PART + ? GET_MODE (XEXP (assign, 0)) : GET_MODE (assign)); /* Shift OTHER right POS places and make it the source, restricting it to the proper length and mode. */ src = canon_reg_for_combine (simplify_shift_const (NULL_RTX, LSHIFTRT, - GET_MODE (src), - other, pos), + src_mode, other, pos), dest); - src = force_to_mode (src, mode, + src = force_to_mode (src, new_mode, len >= HOST_BITS_PER_WIDE_INT ? HOST_WIDE_INT_M1U : (HOST_WIDE_INT_1U << len) - 1, @@ -11767,16 +11789,17 @@ simplify_comparison (enum rtx_code code, && GET_CODE (XEXP (op1, 0)) == ASHIFT && GET_CODE (XEXP (XEXP (op0, 0), 0)) == SUBREG && GET_CODE (XEXP (XEXP (op1, 0), 0)) == SUBREG - && (GET_MODE (SUBREG_REG (XEXP (XEXP (op0, 0), 0))) - == GET_MODE (SUBREG_REG (XEXP (XEXP (op1, 0), 0)))) + && is_a (GET_MODE (op0), &mode) + && (is_a + (GET_MODE (SUBREG_REG (XEXP (XEXP (op0, 0), 0))), &inner_mode)) + && inner_mode == GET_MODE (SUBREG_REG (XEXP (XEXP (op1, 0), 0))) && CONST_INT_P (XEXP (op0, 1)) && XEXP (op0, 1) == XEXP (op1, 1) && XEXP (op0, 1) == XEXP (XEXP (op0, 0), 1) && XEXP (op0, 1) == XEXP (XEXP (op1, 0), 1) && (INTVAL (XEXP (op0, 1)) - == (GET_MODE_PRECISION (GET_MODE (op0)) - - (GET_MODE_PRECISION - (GET_MODE (SUBREG_REG (XEXP (XEXP (op0, 0), 0)))))))) + == (GET_MODE_PRECISION (mode) + - GET_MODE_PRECISION (inner_mode)))) { op0 = SUBREG_REG (XEXP (XEXP (op0, 0), 0)); op1 = SUBREG_REG (XEXP (XEXP (op1, 0), 0)); Index: gcc/ifcvt.c =================================================================== --- gcc/ifcvt.c 2017-06-30 12:50:38.245662583 +0100 +++ gcc/ifcvt.c 2017-07-13 09:18:34.533172436 +0100 @@ -2808,7 +2808,7 @@ noce_try_bitop (struct noce_if_info *if_ { rtx cond, x, a, result; rtx_insn *seq; - machine_mode mode; + scalar_int_mode mode; enum rtx_code code; int bitnum; @@ -2816,6 +2816,10 @@ noce_try_bitop (struct noce_if_info *if_ cond = if_info->cond; code = GET_CODE (cond); + /* Check for an integer operation. */ + if (!is_a (GET_MODE (x), &mode)) + return FALSE; + if (!noce_simple_bbs (if_info)) return FALSE; @@ -2838,7 +2842,6 @@ noce_try_bitop (struct noce_if_info *if_ || ! rtx_equal_p (x, XEXP (cond, 0))) return FALSE; bitnum = INTVAL (XEXP (cond, 2)); - mode = GET_MODE (x); if (BITS_BIG_ENDIAN) bitnum = GET_MODE_BITSIZE (mode) - 1 - bitnum; if (bitnum < 0 || bitnum >= HOST_BITS_PER_WIDE_INT) Index: gcc/loop-invariant.c =================================================================== --- gcc/loop-invariant.c 2017-05-18 07:51:11.897799636 +0100 +++ gcc/loop-invariant.c 2017-07-13 09:18:34.534172347 +0100 @@ -774,16 +774,16 @@ canonicalize_address_mult (rtx x) FOR_EACH_SUBRTX_VAR (iter, array, x, NONCONST) { rtx sub = *iter; - - if (GET_CODE (sub) == ASHIFT + scalar_int_mode sub_mode; + if (is_a (GET_MODE (sub), &sub_mode) + && GET_CODE (sub) == ASHIFT && CONST_INT_P (XEXP (sub, 1)) - && INTVAL (XEXP (sub, 1)) < GET_MODE_BITSIZE (GET_MODE (sub)) + && INTVAL (XEXP (sub, 1)) < GET_MODE_BITSIZE (sub_mode) && INTVAL (XEXP (sub, 1)) >= 0) { HOST_WIDE_INT shift = INTVAL (XEXP (sub, 1)); PUT_CODE (sub, MULT); - XEXP (sub, 1) = gen_int_mode (HOST_WIDE_INT_1 << shift, - GET_MODE (sub)); + XEXP (sub, 1) = gen_int_mode (HOST_WIDE_INT_1 << shift, sub_mode); iter.skip_subrtxes (); } } Index: gcc/simplify-rtx.c =================================================================== --- gcc/simplify-rtx.c 2017-07-13 09:18:33.655250907 +0100 +++ gcc/simplify-rtx.c 2017-07-13 09:18:34.534172347 +0100 @@ -916,7 +916,7 @@ simplify_unary_operation_1 (enum rtx_cod { enum rtx_code reversed; rtx temp; - scalar_int_mode inner; + scalar_int_mode inner, int_mode; switch (code) { @@ -977,10 +977,11 @@ simplify_unary_operation_1 (enum rtx_cod minus 1 is (ge foo (const_int 0)) if STORE_FLAG_VALUE is -1, so we can perform the above simplification. */ if (STORE_FLAG_VALUE == -1 + && is_a (mode, &int_mode) && GET_CODE (op) == ASHIFTRT && CONST_INT_P (XEXP (op, 1)) - && INTVAL (XEXP (op, 1)) == GET_MODE_PRECISION (mode) - 1) - return simplify_gen_relational (GE, mode, VOIDmode, + && INTVAL (XEXP (op, 1)) == GET_MODE_PRECISION (int_mode) - 1) + return simplify_gen_relational (GE, int_mode, VOIDmode, XEXP (op, 0), const0_rtx); @@ -1330,8 +1331,10 @@ simplify_unary_operation_1 (enum rtx_cod return op; /* If operand is known to be only -1 or 0, convert ABS to NEG. */ - if (num_sign_bit_copies (op, mode) == GET_MODE_PRECISION (mode)) - return gen_rtx_NEG (mode, op); + if (is_a (mode, &int_mode) + && (num_sign_bit_copies (op, int_mode) + == GET_MODE_PRECISION (int_mode))) + return gen_rtx_NEG (int_mode, op); break; @@ -1485,12 +1488,13 @@ simplify_unary_operation_1 (enum rtx_cod is similarly (zero_extend:M (subreg:O )). */ if ((GET_CODE (op) == ASHIFTRT || GET_CODE (op) == LSHIFTRT) && GET_CODE (XEXP (op, 0)) == ASHIFT + && is_a (mode, &int_mode) && CONST_INT_P (XEXP (op, 1)) && XEXP (XEXP (op, 0), 1) == XEXP (op, 1) && GET_MODE_BITSIZE (GET_MODE (op)) > INTVAL (XEXP (op, 1))) { scalar_int_mode tmode; - gcc_assert (GET_MODE_BITSIZE (mode) + gcc_assert (GET_MODE_BITSIZE (int_mode) > GET_MODE_BITSIZE (GET_MODE (op))); if (int_mode_for_size (GET_MODE_BITSIZE (GET_MODE (op)) - INTVAL (XEXP (op, 1)), 1).exists (&tmode)) @@ -1500,7 +1504,7 @@ simplify_unary_operation_1 (enum rtx_cod if (inner) return simplify_gen_unary (GET_CODE (op) == ASHIFTRT ? SIGN_EXTEND : ZERO_EXTEND, - mode, inner, tmode); + int_mode, inner, tmode); } } @@ -1601,6 +1605,7 @@ simplify_unary_operation_1 (enum rtx_cod GET_MODE_PRECISION (N) - I bits. */ if (GET_CODE (op) == LSHIFTRT && GET_CODE (XEXP (op, 0)) == ASHIFT + && is_a (mode, &int_mode) && CONST_INT_P (XEXP (op, 1)) && XEXP (XEXP (op, 0), 1) == XEXP (op, 1) && GET_MODE_PRECISION (GET_MODE (op)) > INTVAL (XEXP (op, 1))) @@ -1612,7 +1617,8 @@ simplify_unary_operation_1 (enum rtx_cod rtx inner = rtl_hooks.gen_lowpart_no_emit (tmode, XEXP (XEXP (op, 0), 0)); if (inner) - return simplify_gen_unary (ZERO_EXTEND, mode, inner, tmode); + return simplify_gen_unary (ZERO_EXTEND, int_mode, + inner, tmode); } }