From patchwork Wed Nov 29 08:28:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 171153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp196079vqn; Wed, 29 Nov 2023 00:29:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFni/MFDh40eka3Z+ufENFdOnJmsJNclA4HYvcjhgQO87d9JWec2rsPVdQL3Ip+VYo27sir X-Received: by 2002:a0c:ec0f:0:b0:67a:225f:7722 with SMTP id y15-20020a0cec0f000000b0067a225f7722mr16140215qvo.51.1701246575166; Wed, 29 Nov 2023 00:29:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701246575; cv=pass; d=google.com; s=arc-20160816; b=vz23V//aKPNDPJIP7MDoezDjg5b/yWasRKcze6EjKyugpox0GM5uk28SNkIbyVju05 UJdBNQ91r4zQfGzqTZvsSnOeFzLijXqNmHIHCUQH3YyiihtckvXd4J7gLhjZSs7Fzxhw FISwP+Bo1BxzSDONavGGpGZOYKsa6dGYOmA7lacjnIxyqj4j5Vx2aFNcfUwFWbNnN5nr Uq9JuV3Yd2ikUdNXMqsnr4ooX8FXSGafc5++s4PSDiN5MLIVGa4aF6EXdA8VMwrFhfj7 t2mh9Q421RdTT5lrjwgTKpcMEBPb217Gxucvtde3cdl/4lzIr/yu2dhFnaJk0k+uVhFV c6TQ== 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=aIgyEq9TYWUa4ZtQ6avCfx7LxsH4hWp2wUIZUjqcbm4=; fh=eM2nYbNDZ6Theupq9WaNJQV2QgkrsvQk+3X75erbI8c=; b=BlXfoefg1CWDOKcdBTy14etfHgpfePJ33UCAbL2TdQgLDhg6s0TfTUw2ydhN9jp0u6 euo97VLnPwZ+9GxSnzQbtTR7OZFYoLl81liFT3Uep8ZDDtC9O3FGtDYTDoSEJOrH+YeB t86KiRH/n91lpR/zoAS0E7XsSjf6r1qJLn0Zz5JGr6EsSFt/zRmTG7HgyOUGMv0IWAtw o6OBGvWdi3S98QKeCUNkuF2N3RuYGsCnPUAf2tcc63pAnlEcKD0m0W6VqYZXi+BOOV9i tYIQilR54qjOqjvxoiOlfuIwNQsEj5G5mPz2/cW/TON1juEU7fQKPGZGfurAoMpSx4mA AJ1A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e8vTr0Tn; 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 b9-20020ad45189000000b0067a4aa74474si4928517qvp.563.2023.11.29.00.29.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 00:29:35 -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=e8vTr0Tn; 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 AFC72385AC35 for ; Wed, 29 Nov 2023 08:29:34 +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 11B2A3858C56 for ; Wed, 29 Nov 2023 08:29:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11B2A3858C56 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 11B2A3858C56 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=1701246543; cv=none; b=xCTaUXo9EvlI6CQZ3u04CzZbWAlJCDN7aaVT3ODHp0rzMJwhPHpk7Xh6eEo2stpIFJh8iM+U7AjKog6lAOA/F1kYi/cyd4QRATxhdev90TXi9Vgd5jvfvhTAqy9kIyOUgFH+h4UB0MmaS2RXHIB3H86t9g3a9bspL5Fb2aU0w3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701246543; c=relaxed/simple; bh=/veD8oAL581ZS08wXDW2EAhcKJd3w64VerzjyL+zEN0=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=TTURkveINJh/Hoij+WBNWrj4dYvxxCYrqGqvSUf2gGlODgN0PFMSGLXWvWU9VhVD4B0j0mPl/eZISbeVLT3ecK+SGGI1XoSDp2ttDr1rbRam8CBwXWgWtw+yo3AE0BhZOfF9G703GZmwJqKMseZoQVZEiHuoLu77TfJ+zYF3dWI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701246541; 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=aIgyEq9TYWUa4ZtQ6avCfx7LxsH4hWp2wUIZUjqcbm4=; b=e8vTr0TnRpsK7WHVU/Lv/kTSFQ2ozx0gR5+0u3fNolKdFpC9xoqWHmjvpjrMljHG3RHFm+ YnxlLEHRFlNSycOmXyRYk5M4MjzyheYye/R5s+RJXnv9WoxzhYKuGiX65ZM8/FnrTlAGMg Qis1CglRicpUWlyLkS0fVba230sgXvQ= 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-204-MHY45joGOjegzvbOWFYvhg-1; Wed, 29 Nov 2023 03:28:57 -0500 X-MC-Unique: MHY45joGOjegzvbOWFYvhg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 A93D1805957; Wed, 29 Nov 2023 08:28:56 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6C9E61C060AE; Wed, 29 Nov 2023 08:28:56 +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 3AT8SrwY3259911 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 29 Nov 2023 09:28:54 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AT8SqQV3259910; Wed, 29 Nov 2023 09:28:52 +0100 Date: Wed, 29 Nov 2023 09:28:52 +0100 From: Jakub Jelinek To: Richard Biener , Richard Sandiford Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] fold-const: Fix up multiple_of_p [PR112733] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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: 1783886329014084826 X-GMAIL-MSGID: 1783886329014084826 Hi! We ICE on the following testcase when wi::multiple_of_p is called on widest_int 1 and -128 with UNSIGNED. I still need to work on the actual wide-int.cc issue, the latest patch attached to the PR regressed bitint-{38,39}.c, so will need to debug that, but there is a clear bug on the fold-const.cc side as well - widest_int is a signed representation by definition, using UNSIGNED with it certainly doesn't match what was intended, because -128 as the second operand effectively means unsigned 131072 bit 0xfffff............ffff80 integer, not the signed char -128 that appeared in the source. In the INTEGER_CST case a few lines above this we already use case INTEGER_CST: if (TREE_CODE (bottom) != INTEGER_CST || integer_zerop (bottom)) return false; return wi::multiple_of_p (wi::to_widest (top), wi::to_widest (bottom), SIGNED); so I think using SIGNED with widest_int is best there (compared to the other choices in the PR). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-11-29 Jakub Jelinek PR middle-end/112733 * fold-const.cc (multiple_of_p): Pass SIGNED rather than UNSIGNED for wi::multiple_of_p on widest_int arguments. * gcc.dg/pr112733.c: New test. Jakub --- gcc/fold-const.cc.jj 2023-11-28 08:46:28.345803059 +0100 +++ gcc/fold-const.cc 2023-11-28 17:16:26.872291024 +0100 @@ -14563,7 +14563,7 @@ multiple_of_p (tree type, const_tree top && TREE_CODE (op2) == INTEGER_CST && integer_pow2p (bottom) && wi::multiple_of_p (wi::to_widest (op2), - wi::to_widest (bottom), UNSIGNED)) + wi::to_widest (bottom), SIGNED)) return true; op1 = gimple_assign_rhs1 (stmt); --- gcc/testsuite/gcc.dg/pr112733.c.jj 2023-11-28 17:19:06.813048090 +0100 +++ gcc/testsuite/gcc.dg/pr112733.c 2023-11-28 17:18:45.331349335 +0100 @@ -0,0 +1,16 @@ +/* PR middle-end/112733 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +signed char a, c; +short b; + +void +foo (void) +{ + signed char *e = &a; + c = foo != 0; + *e &= c; + for (; b; --b) + *e &= -128; +}