From patchwork Fri Jan 19 08:51:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 189444 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp877515dyb; Fri, 19 Jan 2024 00:55:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGAnxWZA23YFYY7UgTN3XFfvu7mtjgLlHn56A4D0V2gQLkjFk1210SId/Ig08rxIwON5pf+ X-Received: by 2002:a05:6214:2503:b0:681:7086:1f53 with SMTP id gf3-20020a056214250300b0068170861f53mr2441124qvb.77.1705654521657; Fri, 19 Jan 2024 00:55:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705654521; cv=pass; d=google.com; s=arc-20160816; b=ZjoSKulLB6h282bbp+eZqYh5vDCrJQo67ZbsQybMhHT6XaC3d2txFflddQSs1xxgAd VGlo8WmOBsC04ePWtW5t1/aB6pxMkzFs4Zdx8JVfdPjvxD8fwmaDdunreRbpMtJkPTAt T0bBTZgrUTns80bIEV6+qNnVbW3jZejFTf54QxIoplBDyEv7H4dYYjCwd0XPLV8gYR3+ vZAgxGV2MvRR6IF8X94gL0sGBdrAGhneZlBWz1P4sotAm1S5POSQ5cO13OCdRIAHsrnz HbKg1pRxuj31Q1uAg+uJO3BVdw8/DFiInuTz4ggf0cMbeSvuFEj87wStt9p0IqYzjiA+ 2Mvw== 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=jHUJmd80DYIxIvx35a6EkOKglhTTQtcmtAphjTymOq0=; fh=OitT9p6YzAYnzQG1GM6oocakGJB9G2lF/75SDe33HZI=; b=Dg/QZnMnGsXEF26VrzBtN9pis9TaBX0gCq0BvD2hk+SN7N1o5MF6r+JsVJtHfsHfID wai+z++yU9NqCfd2tFwWwPWg99QrcGxdyd+IPExTdbgs9za4FuCk6Q4pvJCFdGtKM+H9 WqZZossC0wF5XFojdaL839PA13kr5kcDqGw3uS1oTJSW7oqPhh9SSwS8eTQQCPC5utB0 HVEMSNrMj+6wfFf/o4xI/yvPB4NzNTyz4uAtgDBRQq7A4innizfZwZ315X1KOmlRb2Vg Y4+ZAwaixLZXRVrot96p3tfxiWo9+d0k7v+XKfbuh63KpqJusfYzjnCaFhSi70eIO9gD LFIg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=f6raVFBY; 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 f22-20020a0caa96000000b00681969a0b0bsi2513782qvb.223.2024.01.19.00.55.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 00:55: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=f6raVFBY; 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 6125D385842C for ; Fri, 19 Jan 2024 08:55: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 CFFE23858C56 for ; Fri, 19 Jan 2024 08:51:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CFFE23858C56 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 CFFE23858C56 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=1705654289; cv=none; b=Aq+b89Poor+2oXc3AOJoXWkvWVPs/UUh0a+dQPgMm1PbKy28+9vpmLgrda1ASHKa9LBqJNP5sUgm4IFWRe4oZclZnNh2TlvsU9soRT/Z69lZmxKz/ORG3uMhxrZgnsW4M6AFgxzGJaJ/GrFR23dmtoGVCn1I4MwHDN1IIk2wagU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705654289; c=relaxed/simple; bh=wSwVbnPDtNmWblMp9d+sFGLojU74lQxURegIto+dhGU=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=jJHyUhOo3LWJdivc9McLwQS3Rf3Qw3V+cBH6q76NmYCpKD4HFGlfILx0D6kjV8/uqOxYPcYQUcdUU09tMjuvhYmr6J/Fj+5oUBjr0Czt6r37Ulkka/UWShyZGeKGCDciTCuOEZ2ERsXtoKT7Nr1fhI9u11/03evDH5u679xz47A= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705654280; 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=jHUJmd80DYIxIvx35a6EkOKglhTTQtcmtAphjTymOq0=; b=f6raVFBYbg6XA/J7BzUzXhEn8hp0eo7ptt67sEHaFj1AAlTX2STNb7GYNtg7g+AHR24vG7 bgnXsq0BegnGt5od9DAMnSXCpCRBjlva2+RirNsqgHS+QS0CdI1EO/jNmQQUkG/iIWO9VD f8YWjmyr7/jI/6fIBZd67woPitiIEIk= 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-507-Juia7jYmM_yUxPv-2IhYQg-1; Fri, 19 Jan 2024 03:51:15 -0500 X-MC-Unique: Juia7jYmM_yUxPv-2IhYQg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 6D2121C07F59; Fri, 19 Jan 2024 08:51:15 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 315DD2BA; Fri, 19 Jan 2024 08:51:15 +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 40J8pCQu1212709 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 09:51:12 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40J8pBZZ1212707; Fri, 19 Jan 2024 09:51:11 +0100 Date: Fri, 19 Jan 2024 09:51:11 +0100 From: Jakub Jelinek To: Richard Biener , Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] gimple-ssa-warn-restrict: Only use type range from NOP_EXPR for non-narrowing conversions [PR113463] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.9 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_H4, RCVD_IN_MSPIKE_WL, 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: 1788508395762720100 X-GMAIL-MSGID: 1788508395762720100 Hi! builtin_memref::extend_offset_range when it sees a NOP_EXPR from INTEGRAL_TYPE (to INTEGRAL_TYPE of sizetype/ptrdifftype precision given the callers) uses wi::to_offset on TYPE_{MIN,MAX}_VALUE of the rhs1 type. This ICEs with large BITINT_TYPEs - to_offset is only supported for precisions up to the offset_int precision - but it even doesn't make any sense to do such thing for narrowing conversions, their range means the whole sizetype/ptrdifftype range and so the normal handling done later on (largest sized supported object) is the way to go in that case. So, the following patch just restrict this to non-narrowing conversions. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-01-19 Jakub Jelinek PR tree-optimization/113463 * gimple-ssa-warn-restrict.cc (builtin_memref::extend_offset_range): Only look through NOP_EXPRs if rhs1 doesn't have wider type than lhs. * gcc.dg/bitint-74.c: New test. Jakub --- gcc/gimple-ssa-warn-restrict.cc.jj 2024-01-03 11:51:27.705784291 +0100 +++ gcc/gimple-ssa-warn-restrict.cc 2024-01-18 16:00:02.519483821 +0100 @@ -391,7 +391,8 @@ builtin_memref::extend_offset_range (tre tree type; if (is_gimple_assign (stmt) && (type = TREE_TYPE (gimple_assign_rhs1 (stmt))) - && INTEGRAL_TYPE_P (type)) + && INTEGRAL_TYPE_P (type) + && TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (offset))) { tree_code code = gimple_assign_rhs_code (stmt); if (code == NOP_EXPR) --- gcc/testsuite/gcc.dg/bitint-74.c.jj 2024-01-18 16:14:05.523599054 +0100 +++ gcc/testsuite/gcc.dg/bitint-74.c 2024-01-18 16:13:30.150099638 +0100 @@ -0,0 +1,16 @@ +/* PR tree-optimization/113463 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c23 -O2" } */ + +extern char *a, *b; +#if __BITINT_MAXWIDTH__ >= 129 +_BitInt(129) o; +#else +_BitInt(63) o; +#endif + +void +foo (void) +{ + __builtin_memcpy (a + o, b, 4); +}