From patchwork Thu Oct 31 07:57:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 99895 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 88C073857BA2 for ; Thu, 31 Oct 2024 07:58:37 +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.133.124]) by sourceware.org (Postfix) with ESMTP id F09A93858D33 for ; Thu, 31 Oct 2024 07:58:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F09A93858D33 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 F09A93858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730361486; cv=none; b=KYYtJ40d/pxVGEzqc6xSHhbGFrNz7bZoKYI0dANZWbnvEpd3tR2gqHm+dbExcK8N7qo4+PYPBQ/yfiG3M8j7+UOoV5hG/aMutdXAJaSxcSRY2nx2Fxg4AbisC2pw9uw680Fd9qzBV7fabZnvJNH4gtenNGeEOIWM4waupoKzhGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730361486; c=relaxed/simple; bh=pQk3eOMBwyJGPC3/mryhpBEtD1FShqcnHDoJorYsfnk=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=t6nRb857A/8ozAQiBG57tPuwL5ZoW4+JZs9Z5FpSZCsQ7lXYja+PoBRr4FOfeR90IqdTrGyzwfxv+/yJ88BjhYuhARE48oHLezel4lfIxxb5iBQ9H2rECRt6zprUtvc458JHtlN9OaShxzllvV0NGVEhLtJJyM2IKzhkyC/0vf8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730361483; 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=E8uVaFwp+b4oo7KBI3pDlTdmE/6kVbuwnRjeXnIm9zo=; b=GnihCRUajRmATbvtfmGok2yLJMpcBL6/bs5ouw7AKyFX2VTWx89sX9zEvCSGrxm4dwj1jz v5ownJLYReh5L38Jev5UxU+mjtJ0PdTVTecmnG6Agv/f8sOn3GOUplzn8q2k5taYJjV8yl fmOf+BdT5rgtKKSiD32W5XcqNVh5g0M= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-604-yQpklUFFPiu1OHrJbB0Wgg-1; Thu, 31 Oct 2024 03:58:01 -0400 X-MC-Unique: yQpklUFFPiu1OHrJbB0Wgg-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D8BA919560B7; Thu, 31 Oct 2024 07:58:00 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.16]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 84BE41956054; Thu, 31 Oct 2024 07:57:59 +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 49V7vu6E765561 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 31 Oct 2024 08:57:56 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 49V7vuJe765560; Thu, 31 Oct 2024 08:57:56 +0100 Date: Thu, 31 Oct 2024 08:57:56 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] expand: Fix up expansion of VIEW_CONVERT_EXPR to BITINT_TYPE [PR117354] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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 when trying to expand the VIEW_CONVERT_EXPR operand which is SSA_NAME defined to V32QI or V4DI MEM_REF which is aligned just to 8 bytes we force it as unaligned into a register, but then try to call extract_bit_field from the V32QI or V4DI register to BLKmode. extract_bit_field doesn't obviously support BLKmode extraction and so ICEs. The second hunk fixes the ICE by not calling extract_bit_field when it can't handle it, the last if will handle it properly by storing it to memory and using BLKmode access to the copy. The first hunk is an optimization, if mode is BLKmode, by setting inner_reference_p argument to expand_expr_real we avoid the expand_misaligned_mem_ref calls which load it from memory into a register. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-10-31 Jakub Jelinek PR middle-end/117354 * expr.cc (expand_expr_real_1) : Pass true as inner_reference_p argument to expand_expr_real if mode is BLKmode. Don't call extract_bit_field if mode is BLKmode. * gcc.dg/bitint-113.c: New test. Jakub --- gcc/expr.cc.jj 2024-10-25 10:00:29.450768114 +0200 +++ gcc/expr.cc 2024-10-30 14:16:58.624455194 +0100 @@ -12468,7 +12468,7 @@ expand_expr_real_1 (tree exp, rtx target if (!op0) op0 = expand_expr_real (treeop0, NULL_RTX, VOIDmode, modifier, - NULL, inner_reference_p); + NULL, inner_reference_p || mode == BLKmode); /* If the input and output modes are both the same, we are done. */ if (mode == GET_MODE (op0)) @@ -12505,7 +12505,7 @@ expand_expr_real_1 (tree exp, rtx target op0 = convert_modes (mode, GET_MODE (op0), op0, TYPE_UNSIGNED (TREE_TYPE (treeop0))); /* If the output type is a bit-field type, do an extraction. */ - else if (reduce_bit_field) + else if (reduce_bit_field && mode != BLKmode) return extract_bit_field (op0, TYPE_PRECISION (type), 0, TYPE_UNSIGNED (type), NULL_RTX, mode, mode, false, NULL); --- gcc/testsuite/gcc.dg/bitint-113.c.jj 2024-10-30 14:32:39.153442458 +0100 +++ gcc/testsuite/gcc.dg/bitint-113.c 2024-10-30 14:34:41.036768474 +0100 @@ -0,0 +1,40 @@ +/* PR middle-end/117354 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2" } */ +/* { dg-additional-options "-mavx2" { target x86_64-*-* i?86-*-* } } */ + +#if __BITINT_MAXWIDTH__ >= 256 +#define N 256 +#else +#define N 64 +#endif + +struct S { + unsigned char y; + _BitInt(N) x; +} s; + +__attribute__((noipa)) static void +foo (const char *, _BitInt(N)) +{ +} + +__attribute__((noipa)) static void +bar (_BitInt(N)) +{ +} + +static void +baz (void *p) +{ + foo ("bazbazbazb", s.x); + __builtin_memcpy (p, &s.x, sizeof s.x); +} + +int +main () +{ + void *ptr = &s.x; + baz (&s.x); + bar (*(_BitInt(N) *) ptr); +}