Message ID | ZW+hoNiyGaXIYKV8@tucnak |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3739312vqy; Tue, 5 Dec 2023 14:18:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IELhU+ZbO7JK6TKujS1dlaeI7SUMtJVz+oV3YKG6eESQimD0+WIte/LGfujTKZJvAYfq22x X-Received: by 2002:a05:6870:356:b0:1fb:75a:c42c with SMTP id n22-20020a056870035600b001fb075ac42cmr6635055oaf.85.1701814728715; Tue, 05 Dec 2023 14:18:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701814728; cv=pass; d=google.com; s=arc-20160816; b=x+xg7QNPF5ezEgeB+iudsD+iVJrHedoeA6T9lRTQl1oX66QU198VknZNWOQxRjklc5 wSLGa2uzEW0Ed34C90VfRYeutzc/xzkUQ6lQXpD5X5n1kUFAreyblb1XoI0QCgrRtCKQ zmvIFFPup88pf19vQd+OVx2xtbJchl0VS2vF3HIclQH/Uf+b62o3sL3AiaXP0y4LEsmB 3g1gOnwaFb/LK5D5HyoiNEsE7Hc9V7YUG4pz6W5MRHKLVVVQUOEB062oqXkCyjV/kQYd Kc36o7EMNue3PNidCLBVaXTRV4A+yqcIg0XUeEQsXt8B2mSiWLzcK39Q5jsloxVDhS7S Q37w== 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=NxXeEHE9UyeHr4vpbD8Q72BJRECipHOOnbX9jUP14is=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=O0AZbR2f4Of0qF9y9u1/YoLmptNiBPMaO63Fn4AospoM8aUzdTll1j1rQ9LxL46VLH +lTp+cweTOFjG4OXMuxLdac89TMfReMFS5kMRgUEgyjG+gpPGkpJ3aS/0OOhpKuKeElA Td8xwja6mmmHqJtjXErNR+9C7NSOlAPAu4qizKMp33HIu/C1mzOUYCXesdBeejQikR70 O6Krs26Jt8AhtSmtYSsbmkZ2xdQHYGy151iOHn3tvEFMbZHRgwaSVR4b0emvXOv0w9XG 5ZuzYVvL1BEF+x64XkuTDkG3IueFSb82PpXBCrURiTKzoDkVItG/vfvxGfhcnLjF2F42 kSpA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TWb89j40; 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 bn36-20020a05620a2ae400b0076eed2a7335si12435430qkb.57.2023.12.05.14.18.48 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 14:18: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=TWb89j40; 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 79DF63858423 for <ouuuleilei@gmail.com>; Tue, 5 Dec 2023 22:18: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.133.124]) by sourceware.org (Postfix) with ESMTPS id 98C793858D37 for <gcc-patches@gcc.gnu.org>; Tue, 5 Dec 2023 22:18:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 98C793858D37 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 98C793858D37 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=1701814703; cv=none; b=wqM6vL/irjPgn3R3sOzFqsLNEb3sCm5grHLWF7dYzo4TJ2xHa0rdJfLN968RAwB4WiWkXSqN2kLsSxDFBucM0gUN1VQDh1MtA3ic+d7nvet4IWcfWWJ98JLLsYqBIHKrOiSyS/AbGl/njpS/Nf/GfZmRfZYwpmPaY6pY/nFsauA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701814703; c=relaxed/simple; bh=G89mBtq8ZbglB1fVBGaUsSuugm3JIkwDng3O4lRHuT4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=GUZW9vwbxglAXcgjiV5Vu5f8EmcU1iEs1W4bdXfAomnd8O/BM487hcC0WTzzHGTK71nwBl7qFt/Ol++fiClJWxEyu5vF0LejU/AkrRP+uZlPOZExliDU4yVY8wYuHEj1TAE7a1H8KLlPyLckUH4LQT5iYqyNlZZ2DUPzYgao7dQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701814694; 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=NxXeEHE9UyeHr4vpbD8Q72BJRECipHOOnbX9jUP14is=; b=TWb89j40HG3wDCbEjwIedKVm2yjWV+M9v7s6kdsADe4EqdnqJnEhcPFfwifKBj8dw0PJfM aSDjO0FRQFsOeawHOnJQqcLKhkd3dMUqnM6Cu2BUMzFdj/NW58fr90ydEBnGvG8kDBhFJW bCtepuRDt+iSmFAfFO3j1GWVYTwkW58= 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-570--wZVinZPNY-VUACBfSw3sA-1; Tue, 05 Dec 2023 17:18:12 -0500 X-MC-Unique: -wZVinZPNY-VUACBfSw3sA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 7468985A58F; Tue, 5 Dec 2023 22:18:12 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 374A9492BC6; Tue, 5 Dec 2023 22:18:12 +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 3B5MI9PL1483427 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 5 Dec 2023 23:18:09 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B5MI8c01483426; Tue, 5 Dec 2023 23:18:08 +0100 Date: Tue, 5 Dec 2023 23:18:08 +0100 From: Jakub Jelinek <jakub@redhat.com> To: Richard Biener <rguenther@suse.de> Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Fix arithmetics followed by extension by many bits [PR112809] Message-ID: <ZW+hoNiyGaXIYKV8@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Reply-To: Jakub Jelinek <jakub@redhat.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784482080643591907 X-GMAIL-MSGID: 1784482080643591907 |
Series |
lower-bitint: Fix arithmetics followed by extension by many bits [PR112809]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Jakub Jelinek
Dec. 5, 2023, 10:18 p.m. UTC
Hi! A zero or sign extension from result of some upwards_2limb operation is implemented in lower_mergeable_stmt as an extra loop which fills in the extra bits with 0s or 1s. If the delta of extended vs. unextended bit count is small, the code doesn't use a loop and emits up to a couple of stores to constant indexes, but if the delta is large, it uses cnt = (bo_bit != 0) + 1 + (rem != 0); statements. bo_bit is non-zero for bit-field loads and is done in that case as straight line, the unconditional 1 in there is for a loop which handles most of the limbs in the delta and finally (rem != 0) is for the case when the extended precision is not a multiple of limb_prec and is again done in straight line code (after the loop). The testcase ICEs because the decision what idx to use was incorrect for kind == bitint_prec_huge (i.e. when the precision delta is very large) and rem == 0 (i.e. the extended precision is multiple of limb_prec). In that case cnt is either 1 (if bo_bit == 0) or 2, and idx should be either first size_int (start) and then result of create_loop (for bo_bit != 0) or just result of create_loop, but by mistake the last case was size_int (end), which means when precision is multiple of limb_prec storing above the precision (which ICEs; but also not emitting the loop which is needed). Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-05 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/112809 * gimple-lower-bitint.cc (bitint_large_huge::lower_mergeable_stmt): For separate_ext in kind == bitint_prec_huge mode if rem == 0, create for i == cnt - 1 the loop rather than using size_int (end). * gcc.dg/bitint-48.c: New test. Jakub
Comments
On Tue, 5 Dec 2023, Jakub Jelinek wrote: > Hi! > > A zero or sign extension from result of some upwards_2limb operation > is implemented in lower_mergeable_stmt as an extra loop which fills in > the extra bits with 0s or 1s. > If the delta of extended vs. unextended bit count is small, the code > doesn't use a loop and emits up to a couple of stores to constant indexes, > but if the delta is large, it uses > cnt = (bo_bit != 0) + 1 + (rem != 0); > statements. bo_bit is non-zero for bit-field loads and is done in that > case as straight line, the unconditional 1 in there is for a loop which > handles most of the limbs in the delta and finally (rem != 0) is for the > case when the extended precision is not a multiple of limb_prec and is > again done in straight line code (after the loop). > The testcase ICEs because the decision what idx to use was incorrect > for kind == bitint_prec_huge (i.e. when the precision delta is very large) > and rem == 0 (i.e. the extended precision is multiple of limb_prec). > In that case cnt is either 1 (if bo_bit == 0) or 2, and idx should > be either first size_int (start) and then result of create_loop (for bo_bit > != 0) or just result of create_loop, but by mistake the last case > was size_int (end), which means when precision is multiple of limb_prec > storing above the precision (which ICEs; but also not emitting the loop > which is needed). > > Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok > for trunk? OK. > 2023-12-05 Jakub Jelinek <jakub@redhat.com> > > PR tree-optimization/112809 > * gimple-lower-bitint.cc (bitint_large_huge::lower_mergeable_stmt): For > separate_ext in kind == bitint_prec_huge mode if rem == 0, create for > i == cnt - 1 the loop rather than using size_int (end). > > * gcc.dg/bitint-48.c: New test. > > --- gcc/gimple-lower-bitint.cc.jj 2023-12-05 09:48:14.000000000 +0100 > +++ gcc/gimple-lower-bitint.cc 2023-12-05 18:55:58.996323144 +0100 > @@ -2624,7 +2624,7 @@ bitint_large_huge::lower_mergeable_stmt > { > if (kind == bitint_prec_large || (i == 0 && bo_bit != 0)) > idx = size_int (start + i); > - else if (i == cnt - 1) > + else if (i == cnt - 1 && (rem != 0)) > idx = size_int (end); > else if (i == (bo_bit != 0)) > idx = create_loop (size_int (start + i), &idx_next); > --- gcc/testsuite/gcc.dg/bitint-48.c.jj 2023-12-05 19:00:19.593664966 +0100 > +++ gcc/testsuite/gcc.dg/bitint-48.c 2023-12-05 19:00:14.599735086 +0100 > @@ -0,0 +1,23 @@ > +/* PR tree-optimization/112809 */ > +/* { dg-do compile { target bitint } } */ > +/* { dg-options "-O2" } */ > + > +#if __BITINT_MAXWIDTH__ >= 512 > +_BitInt (512) a; > +_BitInt (256) b; > +_BitInt (256) c; > + > +int > +foo (void) > +{ > + return a == (b | c); > +} > + > +void > +bar (void) > +{ > + a /= b - 2; > +} > +#else > +int i; > +#endif > > Jakub > >
--- gcc/gimple-lower-bitint.cc.jj 2023-12-05 09:48:14.000000000 +0100 +++ gcc/gimple-lower-bitint.cc 2023-12-05 18:55:58.996323144 +0100 @@ -2624,7 +2624,7 @@ bitint_large_huge::lower_mergeable_stmt { if (kind == bitint_prec_large || (i == 0 && bo_bit != 0)) idx = size_int (start + i); - else if (i == cnt - 1) + else if (i == cnt - 1 && (rem != 0)) idx = size_int (end); else if (i == (bo_bit != 0)) idx = create_loop (size_int (start + i), &idx_next); --- gcc/testsuite/gcc.dg/bitint-48.c.jj 2023-12-05 19:00:19.593664966 +0100 +++ gcc/testsuite/gcc.dg/bitint-48.c 2023-12-05 19:00:14.599735086 +0100 @@ -0,0 +1,23 @@ +/* PR tree-optimization/112809 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2" } */ + +#if __BITINT_MAXWIDTH__ >= 512 +_BitInt (512) a; +_BitInt (256) b; +_BitInt (256) c; + +int +foo (void) +{ + return a == (b | c); +} + +void +bar (void) +{ + a /= b - 2; +} +#else +int i; +#endif