From patchwork Tue Dec 5 08:05:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 173779 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3276747vqy; Tue, 5 Dec 2023 00:05:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDNKXWauTjrZy2QkORVVLQjk9F5xzZ1hOxV3lmft6b6oyIXUyjSggfUfpsOWLqtO/gut/t X-Received: by 2002:a05:6830:34a5:b0:6d8:74e2:5d11 with SMTP id c37-20020a05683034a500b006d874e25d11mr6451051otu.58.1701763549003; Tue, 05 Dec 2023 00:05:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701763548; cv=pass; d=google.com; s=arc-20160816; b=Iu6K3NAaqE0F8PSxeTv4NcJJx8LHBmgH+SeyQrGrJ6bSgb67CQDb7WbORPigScM+S7 Ek/Dh/QhGLakbEpWAyEgSCSrFixJJovVvKBeeAlQOKGDptr+f6ezkwJwfd9CYoqlbdBR LU8Y2SBlVHRgHqy/rZBpc+gzKrOzxIUfTZXYwFkMZtjc8pwcmuCK2hoB0VkPNakeD+41 9O2e3uPjwrScDfn7yZLtdh68b6BcKGEUdA/r8eDULfHD/u6x+Fwl8adeRiq6MsJqdBQI l3kFcbrevm+ncZRNQHz2HPDIi2IxogQV5OwXrxjyDrmLAppjaftK1dVJFyj5WA//RKnu 4Rng== 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:in-reply-to :mime-version:references:message-id:subject:to:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=dl8cCRF6CV0Q6SmxP+oVHRY/kCtIyWs8/x9slsZVzes=; fh=NddY3a+Zsie4gitnEUAcFQhPVfLSkd4TkpLAvPheAmA=; b=iZ2U28IAVFDMjRrL4jVzCnr8xwO47X7mnN5sa2tBGuOp+/WjcA9/HvFhcb9+1EcUqv V9+FV2d3qsdWfVZgVDSvtqMh6fMd17z9m9WIUXcWqTRAI/uS6Y9mVedmtqr488vMke2/ aKDCzBQ1WCtZYHsZT5RXrHdeNRHctFzJY5jgH6BLh4viflOx4uHnS2FGWecM/WgzGQ6r kUG1R7yc/joIYeCTlayKpZT84Udi5KxftCdkimQUgSNRDbfmwQYd7nu0ucYcE58iUtuv TMTPr8wedlTSwKYh9rbrNPP4d3g1mv9nf58RHLI/UQCe+0JI/FpQrNbnocb5d98n0JV7 vZ3A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B6HnqSRU; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f7-20020a05622a114700b004255002b8bfsi5303692qty.457.2023.12.05.00.05.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 00:05:48 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=B6HnqSRU; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 BE29C38582B6 for ; Tue, 5 Dec 2023 08:05:48 +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 1AD6F3858D33 for ; Tue, 5 Dec 2023 08:05:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1AD6F3858D33 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 1AD6F3858D33 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=1701763523; cv=none; b=uwWbUCnj3rJbP0FUP33W6iJnuiF6lc4o0a5Jm9TsEO7NMxqmO0wtNq86wB3bj2Vxr7SohP0UWwmXTneWveJBVorThdsuZMETMMuiL6Q0MuV4EtptDI5uDsY4RoaxQ9RIRNo572J3aIjTL0mHGw+Q3oENVruyuH72ktVE1ZJk+AA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701763523; c=relaxed/simple; bh=gWnUkpLcHAvHQtEiZ1TSP62lBVdduQrK4e+yfs0yucc=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=X74UJELp1orIewzqivm0XQo8PV9WtG2gg/WzZFl7LisnsyPxDd6nnyrcJogdYQFoYDQCEp/YMtka9dpkM12BOwl2M+Jk1JtrMC5jyVkMk+z/U2FocG/K/2vN0TX+7yrMD59vtYEXl6dMTWn0UJASUScj5lD6LmUTDpxlybTAIdg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701763513; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=dl8cCRF6CV0Q6SmxP+oVHRY/kCtIyWs8/x9slsZVzes=; b=B6HnqSRUnTh1y3/k33s6k3O6MDkjS8+pPH9/IJE2y9sRJD9bfIyPDgW7K+ccoloOfmvup8 39/zBj5OZgJAZ1qK+EnN/WlQ7hkpLrBIsEB2CVQzjomKd9siEBJUXsKDyoerYrRO6CVm0G 6qjJjAXj2QkIKNfiJlzehGvwsfZ19IQ= 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-125-qazqfDJvOjmIcgLX_d4iTQ-1; Tue, 05 Dec 2023 03:05:12 -0500 X-MC-Unique: qazqfDJvOjmIcgLX_d4iTQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 D1FED28AC1E8; Tue, 5 Dec 2023 08:05:11 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 93D142026D66; Tue, 5 Dec 2023 08:05:11 +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 3B5859WF706493 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 5 Dec 2023 09:05:09 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B5857bA706492; Tue, 5 Dec 2023 09:05:07 +0100 Date: Tue, 5 Dec 2023 09:05:07 +0100 From: Jakub Jelinek To: Richard Biener , gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint, v2: Make temporarily wrong IL less wrong [PR112843] Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 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: 1784428414832256483 X-GMAIL-MSGID: 1784428414832256483 On Tue, Dec 05, 2023 at 08:21:15AM +0100, Jakub Jelinek wrote: > The reason I tweaked the lhs first is that it then just uses gimple_op and > iterates over all ops, if that is done before lhs it would need to special > case which op to skip because it is lhs (I'm using gimple_get_lhs for the > lhs, but this isn't done for GIMPLE_CALL nor GIMPLE_PHI, so GIMPLE_ASSIGN > or say GIMPLE_GOTO etc. are the only options, so I could just start with > op 1 rather than 0 for is_gimple_assign). Here is a variant which adjusts the inputs first before set_lhs, then addition of cast after it and finally update_stmt. So far tested with make check-gcc check-g++ -j32 -k GCC_TEST_RUN_EXPENSIVE=1 RUNTESTFLAGS="GCC_TEST_RUN_EXPENSIVE=1 dg.exp='*bitint* pr112673.c builtin-stdc-bit-*.c pr112566-2.c pr112511.c' dg-torture.exp=*bitint* dfp.exp=*bitint*" 2023-12-05 Jakub Jelinek PR tree-optimization/112843 * gimple-lower-bitint.cc (gimple_lower_bitint): Change lhs of stmt to lhs2 before building and inserting lhs = (cast) lhs2; assignment. Adjust stmt operands before adjusting lhs. * gcc.dg/bitint-47.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2023-12-03 17:53:55.604855552 +0100 +++ gcc/gimple-lower-bitint.cc 2023-12-05 08:53:13.424763429 +0100 @@ -6329,27 +6329,9 @@ gimple_lower_bitint (void) tree type = NULL_TREE; /* Middle _BitInt(N) is rewritten to casts to INTEGER_TYPEs with the same precision and back. */ - if (tree lhs = gimple_get_lhs (stmt)) - if (TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE - && (bitint_precision_kind (TREE_TYPE (lhs)) - == bitint_prec_middle)) - { - int prec = TYPE_PRECISION (TREE_TYPE (lhs)); - int uns = TYPE_UNSIGNED (TREE_TYPE (lhs)); - type = build_nonstandard_integer_type (prec, uns); - tree lhs2 = make_ssa_name (type); - gimple *g = gimple_build_assign (lhs, NOP_EXPR, lhs2); - if (stmt_ends_bb_p (stmt)) - { - edge e = find_fallthru_edge (gsi_bb (gsi)->succs); - gsi_insert_on_edge_immediate (e, g); - } - else - gsi_insert_after (&gsi, g, GSI_SAME_STMT); - gimple_set_lhs (stmt, lhs2); - } unsigned int nops = gimple_num_ops (stmt); - for (unsigned int i = 0; i < nops; ++i) + for (unsigned int i = is_gimple_assign (stmt) ? 1 : 0; + i < nops; ++i) if (tree op = gimple_op (stmt, i)) { tree nop = maybe_cast_middle_bitint (&gsi, op, type); @@ -6376,6 +6358,25 @@ gimple_lower_bitint (void) type); } } + if (tree lhs = gimple_get_lhs (stmt)) + if (TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE + && (bitint_precision_kind (TREE_TYPE (lhs)) + == bitint_prec_middle)) + { + int prec = TYPE_PRECISION (TREE_TYPE (lhs)); + int uns = TYPE_UNSIGNED (TREE_TYPE (lhs)); + type = build_nonstandard_integer_type (prec, uns); + tree lhs2 = make_ssa_name (type); + gimple_set_lhs (stmt, lhs2); + gimple *g = gimple_build_assign (lhs, NOP_EXPR, lhs2); + if (stmt_ends_bb_p (stmt)) + { + edge e = find_fallthru_edge (gsi_bb (gsi)->succs); + gsi_insert_on_edge_immediate (e, g); + } + else + gsi_insert_after (&gsi, g, GSI_SAME_STMT); + } update_stmt (stmt); continue; } --- gcc/testsuite/gcc.dg/bitint-47.c.jj 2023-12-04 14:53:19.784200724 +0100 +++ gcc/testsuite/gcc.dg/bitint-47.c 2023-12-04 14:42:07.251699994 +0100 @@ -0,0 +1,13 @@ +/* PR tree-optimization/112843 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2" } */ + +#if __BITINT_MAXWIDTH__ >= 256 +_BitInt (256) +foo (_BitInt (128) x, _BitInt (256) y) +{ + return x * 5 * y; +} +#else +int x; +#endif