From patchwork Mon Jan 28 08:11:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1031737 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-494815-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="YPvBr5pj"; 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 43p2RH62bKz9s3q for ; Mon, 28 Jan 2019 19:12:10 +1100 (AEDT) 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=rDVHKbmLWJBitv+bD8g5v+vWVmRMK72QVH4rHjUOZFPb0kOkqmO4P Ys84hSkMYkgLFlFKDt/+//+eS9gCVaic5WKUPqyl5p5+FpLAbi8CZOzk3BCzGn9b 76EWKzLdxNsaQOTOYmFGBkvkFEekJdw64e4b7ggL/28cnPp758/44c= 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=xEai/2aZblGb2GjQZpsYbo9/Dfo=; b=YPvBr5pjiCK+NQTtG/8/ YsN1PPGoDTc3D215s2lSr/qMB8eEcJ1a5AJBBtI8Bf7L7GWiizV0vqoH/M/Z8Vjb WVW7VI21y2DgawiTVLtWKla3DWrNe1pieVl/bCkOmdXVdRre1HuCKNAch7yPApXb vlecrx+70ZfG5unw0rGR7cY= Received: (qmail 11591 invoked by alias); 28 Jan 2019 08:12:02 -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 9438 invoked by uid 89); 28 Jan 2019 08:11:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.2 spammy=integral X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 28 Jan 2019 08:11:55 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5DD0CAEC7 for ; Mon, 28 Jan 2019 08:11:53 +0000 (UTC) Date: Mon, 28 Jan 2019 09:11:53 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR88739 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 This restricts BIT_FIELD_REFs we create to ones operating on mode-precision entities (iff INTEGRAL_TYPE_P). This avoids issues with endianess when expanding them. No testcase, BE folks have to come up with sth suitable for the testsuite. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk, queued for backporting (w/o the checking hunks). Richard. 2019-01-28 Richard Biener PR tree-optimization/88739 * tree-cfg.c (verify_types_in_gimple_reference): Verify BIT_FIELD_REFs only are applied to mode-precision operands when they are integral. (verify_gimple_assign_ternary): Likewise for BIT_INSERT_EXPR. * tree-ssa-sccvn.c (vn_reference_lookup_3): Avoid generating BIT_FIELD_REFs of non-mode-precision integral operands. Index: gcc/tree-cfg.c =================================================================== --- gcc/tree-cfg.c (revision 268257) +++ gcc/tree-cfg.c (working copy) @@ -3118,6 +3118,12 @@ verify_types_in_gimple_reference (tree e "match field size of BIT_FIELD_REF"); return true; } + if (INTEGRAL_TYPE_P (TREE_TYPE (op)) + && !type_has_mode_precision_p (TREE_TYPE (op))) + { + error ("BIT_FIELD_REF of non-mode-precision operand"); + return true; + } if (!AGGREGATE_TYPE_P (TREE_TYPE (op)) && maybe_gt (size + bitpos, tree_to_poly_uint64 (TYPE_SIZE (TREE_TYPE (op))))) @@ -4319,6 +4325,12 @@ verify_gimple_assign_ternary (gassign *s error ("invalid position or size in BIT_INSERT_EXPR"); return true; } + if (INTEGRAL_TYPE_P (rhs1_type) + && !type_has_mode_precision_p (rhs1_type)) + { + error ("BIT_INSERT_EXPR into non-mode-precision operand"); + return true; + } if (INTEGRAL_TYPE_P (rhs1_type)) { unsigned HOST_WIDE_INT bitpos = tree_to_uhwi (rhs3); Index: gcc/tree-ssa-sccvn.c =================================================================== --- gcc/tree-ssa-sccvn.c (revision 268257) +++ gcc/tree-ssa-sccvn.c (working copy) @@ -2298,6 +2298,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree base2 = get_ref_base_and_extent (gimple_assign_lhs (def_stmt), &offset2, &size2, &maxsize2, &reverse); + tree def_rhs = gimple_assign_rhs1 (def_stmt); if (!reverse && known_size_p (maxsize2) && known_eq (maxsize2, size2) @@ -2309,11 +2310,13 @@ vn_reference_lookup_3 (ao_ref *ref, tree according to endianness. */ && (! INTEGRAL_TYPE_P (vr->type) || known_eq (ref->size, TYPE_PRECISION (vr->type))) - && multiple_p (ref->size, BITS_PER_UNIT)) + && multiple_p (ref->size, BITS_PER_UNIT) + && (! INTEGRAL_TYPE_P (TREE_TYPE (def_rhs)) + || type_has_mode_precision_p (TREE_TYPE (def_rhs)))) { gimple_match_op op (gimple_match_cond::UNCOND, BIT_FIELD_REF, vr->type, - vn_valueize (gimple_assign_rhs1 (def_stmt)), + vn_valueize (def_rhs), bitsize_int (ref->size), bitsize_int (offset - offset2)); tree val = vn_nary_build_or_lookup (&op);