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: 202950 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1138072dyc; Sun, 18 Feb 2024 23:59:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWSuos6oifzmtZU+m/DJAjzj5byXtoHWUBXcq+sc8omXMIy8I71AS1WqlBg+t/qm50VciwdjSOcM5DdbUTwkTFVzZ3DCA== X-Google-Smtp-Source: AGHT+IEz+jLszkBKAmdy/p2l0M+Wvqje5ovWvtNOHIvHyYxyjTE7BItxQRgHn4/DdfBL8xCL0ib6 X-Received: by 2002:a0c:e34e:0:b0:68f:3169:ab0e with SMTP id a14-20020a0ce34e000000b0068f3169ab0emr9345694qvm.9.1708329561332; Sun, 18 Feb 2024 23:59:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708329561; cv=pass; d=google.com; s=arc-20160816; b=AHomQT3SlceF//UGZhsQ2pLEfmUHRcaxPKUWlNUbUw+OCduW9qgHm0FFSbijq0aAGM ASVZqwfSNAS2A216Q1mTaBzKlTPlVuJ1DtDEzKnZSGJvbgO1/mMZOjBcMB5tZHZD4IRZ 3jx9ciSnWb7GnjsrAuX0wPuzduQSs3cO/i5pTN582bvbvP5gQH12BAoJ/bnHzzn4spoa EKPI4XZ27R2IAA/rPmjKR/i2lARTy3DAskIMqhJLb1A6WiQQpXIYJfLfJaUPvN0+sJcR kfBdd+j6744pjeHWdoZ3Az5eli2W897uCmk4sDa7ht6GP2Hdp1ivXWy45JB+cfy7Am8l OLCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=ltarWyATcNYXAmLx5aJKWVc9RraHlLAIPe1yxk4mX9U=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=pY091jaSpBAQ4D1ABFTk7juZrwXtYd3RF4fw6O8MjXWQYUGVnKKFTwtJJSnYmNNQ8u 3ovwZ7e8tgtCmnobfKsAY6Cir+05aEQUPKj9QZIW9cpPuqzDcaTtdFFH49D6YkrxWJBN jCdGSf957FHEUxThh6UwxX/PI63fwE5zGFASjufv4wdXLps9yST8lRLmW9nX7cfXx+V8 n3OZ+VRK0DjNjnsMPYzvOTbqVVoWxFIrSQw70tXaOW8buxLK9khBwe3S8jXxhKbciNp1 IpyXogd//tAqnZPEArHXIrCPkaPAqdBhGZFpl//DV8SEPe+oLMw8fff1b/GzhP2H82Qf aKGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UI81HTWR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id jz8-20020a0562140e6800b0068cb950df8asi5656299qvb.5.2024.02.18.23.59.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 23:59:21 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UI81HTWR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 143143861863 for ; Mon, 19 Feb 2024 07:59:21 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791313378368530170 X-GMAIL-MSGID: 1791313378368530170 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; +}