From patchwork Mon Feb 19 07:58:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 85950 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 150CB3861877 for ; Mon, 19 Feb 2024 07:59:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 2554F3861826 for ; Mon, 19 Feb 2024 07:58:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2554F3861826 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2554F3861826 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708329520; cv=none; b=J0BVqKdep2HIhLigsxG24XiRhOv9TawzjTMJLk94KkpADW3Ir3N5qaGjEYgOWdsvCi58/ViYJ7/fmG58tSDeocFsO+4cAth+JF2tq8keuT8R8oaRCn5SivqfC36rwJFXAVy3Dg9ELY+4H0qDinSxufB0LGuCc/dIJGOree0vqms= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708329520; c=relaxed/simple; bh=K8Ng7In/4ketvcQrZ+/IfXzd1SKptg/3r2krEysMI8s=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=g9Q1FUBX1n+99BM893DzkK8vzN3NQj4RGQJR0nfNns1EtE1I3BqnvmoelS0rjhVdbwS15aaY3VWNedMgU/KXwu/2SfGGWzDmdo4/ciCJliyRFZiUm5IKxwUMNqJLjp6bbHexpepVhNSrlWxbDyvb0ShpSStINT5muYjX2E6PJe4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708329518; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=ltarWyATcNYXAmLx5aJKWVc9RraHlLAIPe1yxk4mX9U=; b=UI81HTWRd+lqRRqOL25WVRR/AWTMDsaMf6HgrSjvRVPFLCj1reEnkrKo+jsOL8nyEqJWvh hMzmo5PsKpi+jO9zt4zGExYZMrf8V0wj3Y81XsC3nkkZ5YAODL6/23vDGaXzd5wiS9dhtW ugFLKKvCb51fd0UBuvCbQo+VVRcYSmU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-185-eJg76YxaNgWwQiWRNV94qQ-1; Mon, 19 Feb 2024 02:58:37 -0500 X-MC-Unique: eJg76YxaNgWwQiWRNV94qQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BEEF01C0512E; Mon, 19 Feb 2024 07:58:36 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 834091121312; Mon, 19 Feb 2024 07:58:36 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 41J7wYEF1789683 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 19 Feb 2024 08:58:34 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 41J7wXZ11789682; Mon, 19 Feb 2024 08:58:33 +0100 Date: Mon, 19 Feb 2024 08:58:33 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] match.pd: Fix ICE on BIT_INSERT_EXPR of BIT_FIELD_REF folding [PR113967] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Hi! The following testcase ICEs, because BIT_FIELD_REF's position is not multiple of the vector element's bit size and the code uses exact_div to divide those 2 values. For BIT_INSERT_EXPR, the tree-cfg.cc verification verifies the position is a multiple of the inserted bit size when inserting into vectors, but for BIT_FIELD_REF the position can be arbitrary if within the range. The following patch fixes that, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-02-19 Jakub Jelinek PR tree-optimization/113967 * match.pd (bit_insert @0 (BIT_FIELD_REF @1 ..) ..): Require in condition that @rpos is multiple of vector element size. * gcc.dg/pr113967.c: New test. Jakub --- gcc/match.pd.jj 2024-02-01 09:14:16.541550659 +0100 +++ gcc/match.pd 2024-02-17 11:58:19.822913858 +0100 @@ -8586,7 +8586,9 @@ (define_operator_list SYNC_FETCH_AND_AND || optimize_vectors_before_lowering_p ()) && types_match (@0, @1) && types_match (TREE_TYPE (TREE_TYPE (@0)), TREE_TYPE (@2)) - && TYPE_VECTOR_SUBPARTS (type).is_constant ()) + && TYPE_VECTOR_SUBPARTS (type).is_constant () + && multiple_p (wi::to_poly_offset (@rpos), + wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (type))))) (with { unsigned HOST_WIDE_INT elsz --- gcc/testsuite/gcc.dg/pr113967.c.jj 2024-02-17 12:01:06.784623682 +0100 +++ gcc/testsuite/gcc.dg/pr113967.c 2024-02-17 12:00:19.384273862 +0100 @@ -0,0 +1,14 @@ +/* PR tree-optimization/113967 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +typedef unsigned short W __attribute__((vector_size (4 * sizeof (short)))); + +void +foo (W *p) +{ + W x = *p; + W y = {}; + __builtin_memcpy (&y, 1 + (char *) &x, sizeof (short)); + *p = y; +}