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: 172311 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp958386vqy; Fri, 1 Dec 2023 00:10:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGHGSSL+/88jk5Ds7A9GMdUHYP5hJa4tjYGUWFpr8+hApBmXtJxNKZHrhkrPitG+vgd3r+ X-Received: by 2002:a67:f4d0:0:b0:45b:6d6b:1857 with SMTP id s16-20020a67f4d0000000b0045b6d6b1857mr19560883vsn.7.1701418255638; Fri, 01 Dec 2023 00:10:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701418255; cv=pass; d=google.com; s=arc-20160816; b=Ay5difQOolQirbz6RshwKCz8S1eqoXrLampH5rDiMvdxgt/f2Ow+TySmIc6WG0WGQf E6UQPDJ/Z1Trz+8w7kPG5N7aSrKfTk+q8dzmRcNrampEt8Y7R2+T1h1EtJc9KsKZqcp0 pz38uM0cHxI2wh3ctUNDXytS/YENefYqGOiCiv8zP8c4o4VgonDeqUvnrHzaxZ/s4lfb qwU4EAXeHY6j/LxCpgilV69JKg7mKy8wN0hjz4qqR4uaDSZaDxS+9UV8SEj++bGP/RXn /GNx6naqXN+cwI5QQ0XTjUQe1gAvX7R6VHTFzBfNb5YzxLvAsTKGervtyzN+B7/PLsNU qvoQ== 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=TXkYcO+7G40o8VoHPH28dKAQohahcGftqXTw/pZ0k2w=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=ZeWx6rZk6pMkv5Kg7DUXe5z9uYEeuteWw255BeDkA9F2icbQcAl75vahZY6dTieEnm L06mkF82E1javcpsBANGqe34ZQZntlmuMY+otTEIRGcEujPjpHjXqtbYxe5xXcgKHMTJ EiiNFesmSx9twqUx+8Bv4t3ukIlcmRGRUmkrqaT3hHRS8yhu9ItktBFS4j7TZ71D7Uhk OrP3sBxGTGR3ohWZbU20oVE0RUry/48zDe/9dzZoSBy82IwyHbNFzJ/JHmSrkgicc14R D1XxQG+MxtS+9RJuzeVt3rsiDXFsC7aJcBA3HKul0y6xYYo+xChT3WU4HQfSB0aa6/b7 ZoUQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Abtcc7NC; 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 d8-20020a0cf6c8000000b0067a97f4f39fsi848942qvo.518.2023.12.01.00.10.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 00:10:55 -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=Abtcc7NC; 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 65AD5385C318 for ; Fri, 1 Dec 2023 08:10:55 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784066348948592493 X-GMAIL-MSGID: 1784066348948592493 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; +}