From patchwork Fri Dec 1 08:10:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 81080 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 A8FC8385B530 for ; Fri, 1 Dec 2023 08:10:47 +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 ESMTPS id CB0293858C62 for ; Fri, 1 Dec 2023 08:10:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB0293858C62 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 CB0293858C62 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=1701418230; cv=none; b=gclmGKMcsKAfNIm1J+10qFJ8+Eu6nYhtRdevR1Ta+CpBL5kWIn5KsfarQI0ZmSxbyv+IEhzHba5sv4djD5zefGEkNTr268kmm/6d6N6ZOp5JR/lps7kDVZoKua0/yEztM2PKwDTzWkaAOPUZI6C3kq42ierxQC4LgkzvQShPbFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701418230; c=relaxed/simple; bh=Zwq0QhtM5xCnmyRMX8/v0g+MhYkrgzkWuNb/cbntX50=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=TNDUhjCLKVoNVK5v3O+HJFpCkKqNLXZdnRtRRk0IEmG9FGhhRtcdu9Nkb57N7qFFqQGZ92x912cY7L6bleh8hiU1toDUZtVUWaaWPoVN6RWJtdhUHKalD1k7xa5RMVfpRX2n4EIh+6Rd326wftRK2QSc6RG8u4sMAqonUGYyXSc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701418225; 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=TXkYcO+7G40o8VoHPH28dKAQohahcGftqXTw/pZ0k2w=; b=Abtcc7NC8r6uQ6au4vAQfv+lbD5NBgnHHL/LT/ScL75/YA9Ik3zXnXvDB4llfviOB6LX4b ElDyj1R07MHi75mTsGkBoB0K26FaNK5qLh9F46pOIy/AGJxuKqIHJqDknjENciHxmhslXc JnO7AS9v9zBlzBFB/m1odVBFNvBeyQU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-140-sPqvZhjgMg20gbdl7ds5fw-1; Fri, 01 Dec 2023 03:10:21 -0500 X-MC-Unique: sPqvZhjgMg20gbdl7ds5fw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 A53DF185A782; Fri, 1 Dec 2023 08:10:19 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6908110E46; Fri, 1 Dec 2023 08:10:19 +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 3B18AGov540292 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 1 Dec 2023 09:10:17 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B18AG6v540291; Fri, 1 Dec 2023 09:10:16 +0100 Date: Fri, 1 Dec 2023 09:10:15 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Fix lowering of middle sized _BitInt operations which can throw [PR112770] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 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, 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 middle kind _BitInt lowering is mostly done by casting the BITINT_TYPE operands (if any) to a signed/unsigned integer type which has larger/equal precision, using such integer type also for the lhs (if BITINT_TYPE) and and adding a cast after the statement from that new lhs to the old (BITINT_TYPE) lhs. Note, for middle kind this isn't done for GIMPLE_CALLs. Most of the time that works nicely, the exception as the following testcase shows is -fnon-call-exceptions and some operations which can trap. Because inserting the cast to a new lhs after the statement results in a trapping statement in the middle of a basic block. The following patch fixes that by emitting the cast on the fallthru edge instead. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-01 Jakub Jelinek PR middle-end/112770 * gimple-lower-bitint.cc (gimple_lower_bitint): When adjusting lhs of middle _BitInt setter which ends bb, insert cast on the fallthru edge rather than after stmt. * gcc.dg/bitint-45.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2023-11-30 17:42:07.172487347 +0100 +++ gcc/gimple-lower-bitint.cc 2023-11-30 19:04:08.004372919 +0100 @@ -6336,7 +6336,13 @@ gimple_lower_bitint (void) type = build_nonstandard_integer_type (prec, uns); tree lhs2 = make_ssa_name (type); gimple *g = gimple_build_assign (lhs, NOP_EXPR, lhs2); - gsi_insert_after (&gsi, g, GSI_SAME_STMT); + 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); --- gcc/testsuite/gcc.dg/bitint-45.c.jj 2023-11-30 19:17:43.923888015 +0100 +++ gcc/testsuite/gcc.dg/bitint-45.c 2023-11-30 19:17:35.502006495 +0100 @@ -0,0 +1,11 @@ +/* PR middle-end/112770 */ +/* { dg-do compile { target bitint128 } } */ +/* { dg-options "-std=c23 -fnon-call-exceptions" } */ + +void +foo (void) +{ + _BitInt(128) a = 0; + a /= 0; /* { dg-warning "division by zero" } */ + &a; +}