From patchwork Fri Jan 12 09:56:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 187657 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp67767dyc; Fri, 12 Jan 2024 01:57:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEHvsVnTtKzDmVIdOGoX5PFyFOvDi2Z99t6d/ZuLSW7Uc2qY1ohIqu/XHKV5Zc7zHnb4QXH X-Received: by 2002:a05:620a:c46:b0:783:3388:172c with SMTP id u6-20020a05620a0c4600b007833388172cmr1383986qki.12.1705053458970; Fri, 12 Jan 2024 01:57:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705053458; cv=pass; d=google.com; s=arc-20160816; b=SkmTur7tWETAwI9z/lZL85rkC0OSbYZkLwb1lr18fyn3U8PWlNkWV9X29YvWtjuSh5 HJtudTND7+45BP7o3e2oYwtFg03PEfhG3JE9/n1fC3mmFzqkFtRqI/OOXsEvjgqL616q +Z09Y2KK9cJyO/shuLOE059VeG8Qypslq8edA6Np2xKvYukSLj2rfMV58oyHVly8uhm3 c/ngiZVqaMTKAoIrbPHC7vCT7w4QCzHpfQOLF8iwtKpJZT0ELlo76JCZC9w+Gbk6/4qj tt6SHrMcPOSZP+VulMvcu+8q01PKQebtv8QrUXLgssbQ1E3VfyBsbMX5FcE+1kxESZKy YOGg== 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=sbAIED0Ho9OLQ6e7UtsF03mhZqHxoMGepzqNU5cBtLM=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=mSQr81VI2yXGPlTkdsWDUC14dM/ThIRFz0RCJxlNXM+Ua8hU1jS1Ipg63gIrdwwoM9 MsgCRqUFrePxVCWG/U7RDAPsYQrI824Kp9JE4CxsVTCFTrua10QlhMl+vFHFglNzymzL GGly/41jWbDuIWw79PGevZRbhI45Uy6KlOtAFmrEUYHMvSCgi3QcxUS1CY1OLdXWxVBk 28tDrHmZ67mlntQLCny2z6hTNyrLf1LGxXeBdXzpz1VWMu4eAHz1FBw7GHN0EizLUfKN wDK+Bv753VuMfWyPwmwNX+cX7PwkP6CuVZcX4KaBTu5UxvU0Cx+1wCoKlA0HZUDUjs8t XblQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Rrx0MIGA; 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 m16-20020a05620a221000b0078335c370e5si2588693qkh.327.2024.01.12.01.57.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 01:57:38 -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=Rrx0MIGA; 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 AB69D384CBBC for ; Fri, 12 Jan 2024 09:57:38 +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 E54343865C29 for ; Fri, 12 Jan 2024 09:56:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E54343865C29 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 E54343865C29 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=1705053390; cv=none; b=slzJTCJaUOpA4Oq9+Gvpmn5KaUeBwY6h0QyVa59UWYGTMmzcAwBIxVRqYIguFH7pRJciSewQM3eXvJZn9HfGy3QWSOx7k+mP5tuG8EHGuUZHWjIg1RZ9x2oIQb25PI4WJEsUBdMMyhVT1XNeMm10R1peiGXXYV2XDbdzCLLQMAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705053390; c=relaxed/simple; bh=0ZxkTZjWttoXgb7f44N3q2gvpleLserIWHIXoVHiaY4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=hj5FELekPziCtoVA+zkgCWHy4Q1oWeZ8SmRvmkCsiKktDMlOvR4vdKnRpBAFLB93Z5Wq5VdXn0BrovVOvDJJz9oeBUepDlhYorbBUDCzdHVfZQEY4OG2Cuim704z7nDasYcyVrge971zA9eJStxmAYd4lyUmrGsl1tKKWSXmYMs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705053387; 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=sbAIED0Ho9OLQ6e7UtsF03mhZqHxoMGepzqNU5cBtLM=; b=Rrx0MIGA1C/0EVq28J2HdytV1Fd4crDdP/mjUUYs3zolOBNQ12RG6KwWJ7ng7dSxvKzVZ+ iQLknuqtKkk4vT6PvsN5pIEM7VVmo7CHcXOWD4QneZuy5PzpcmrnMNXrqddxN3TbzxUDD6 h84ymF5kPFjgZ7FZfaxp/ivlta3NegE= 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-362-mR2JmlNeNouK8GzI4hQEJQ-1; Fri, 12 Jan 2024 04:56:24 -0500 X-MC-Unique: mR2JmlNeNouK8GzI4hQEJQ-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 BB640185A784; Fri, 12 Jan 2024 09:56:23 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7F6163C25; Fri, 12 Jan 2024 09:56:23 +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 40C9uKmH3307350 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 12 Jan 2024 10:56:21 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40C9uKC73307349; Fri, 12 Jan 2024 10:56:20 +0100 Date: Fri, 12 Jan 2024 10:56:19 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Fix up handling of unsigned INTEGER_CSTs operands with lots of 1s in the upper bits [PR113334] 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.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_LOTSOFHASH, 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: 1787878136058842819 X-GMAIL-MSGID: 1787878136058842819 Hi! For INTEGER_CST operands, the code decides if it should emit the whole INTEGER_CST into memory, or if there are enough upper bits either all 0s or all 1s to warrant an optimization, where we use memory for lower limbs or even just an INTEGER_CST for least significant limb and fill in the rest of limbs with 0s or 1s. Unfortunately when not using bitint_min_cst_precision, the code was using tree_int_cst_sgn (op) < 0 to determine whether to fill in the upper bits with 1s or 0s. That is incorrect for TYPE_UNSIGNED INTEGER_CSTs which have higher limbs full of ones, we really want to check here whether the most significant bit is set or clear. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-01-12 Jakub Jelinek PR tree-optimization/113334 * gimple-lower-bitint.cc (bitint_large_huge::handle_operand): Use wi::neg_p (wi::to_wide (op)) instead of tree_int_cst_sgn (op) < 0 to determine if number should be extended by all ones rather than zero extended. * gcc.dg/torture/bitint-46.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-01-11 14:27:26.000000000 +0100 +++ gcc/gimple-lower-bitint.cc 2024-01-11 17:35:07.484557476 +0100 @@ -997,7 +997,7 @@ bitint_large_huge::handle_operand (tree { unsigned int prec = TYPE_PRECISION (TREE_TYPE (op)); unsigned rem = prec % (2 * limb_prec); - int ext = tree_int_cst_sgn (op) < 0 ? -1 : 0; + int ext = wi::neg_p (wi::to_wide (op)) ? -1 : 0; tree c = m_data[m_data_cnt]; unsigned min_prec = TYPE_PRECISION (TREE_TYPE (c)); g = gimple_build_cond (LT_EXPR, idx, --- gcc/testsuite/gcc.dg/torture/bitint-46.c.jj 2024-01-11 17:44:42.360409112 +0100 +++ gcc/testsuite/gcc.dg/torture/bitint-46.c 2024-01-11 17:44:31.471564635 +0100 @@ -0,0 +1,32 @@ +/* PR tree-optimization/113334 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c23 -pedantic-errors" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 384 +__attribute__((noipa)) _BitInt(384) +foo (int s) +{ + _BitInt(384) z = (-(unsigned _BitInt(384)) 4) >> s; + return z; +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 384 + if (foo (59) != 0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwb) + __builtin_abort (); + if (foo (0) != -4wb) + __builtin_abort (); + if (foo (1) != 0x7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffewb) + __builtin_abort (); + if (foo (11) != 0x001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwb) + __builtin_abort (); + if (foo (123) != 0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwb) + __builtin_abort (); +#endif + return 0; +}