From patchwork Fri Feb 23 08:28:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 205227 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp452964dyb; Fri, 23 Feb 2024 00:31:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVK7xb3a9bwcSAYazA3XoBoQA160/TUeH1AQVDE4UanrY8JYqeOpqP6GzvVbnBuSQbfUG1DIbbkDeRz6a3kB6Vj9r1/hg== X-Google-Smtp-Source: AGHT+IF6LPpvwNocD+Vx+VsxAONJ93LEskyRAFkEZfVd12CuNIjcGCdMCvsBF+2FxeO1zB5F5RBk X-Received: by 2002:ae9:f446:0:b0:787:34f6:a6fe with SMTP id z6-20020ae9f446000000b0078734f6a6femr1572554qkl.30.1708677093503; Fri, 23 Feb 2024 00:31:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708677093; cv=pass; d=google.com; s=arc-20160816; b=g62Ddda+t242M87Lnw4YLN1ZHozTvglAExdGjaPeVSm+WXV8LMDFUtJG+Y8/TmpKUJ hZnn8FrhhSTJz7DXWOK2LgNdSiKfOd4I5LFKi+MpdFdz7a69Nyw/9eVIXu7zJOaWN+GV iGg2ZvlyX7anJCs+I0amphiU1/56M7BGYpW5sQcOV6FSqU7eIaCq+04a1wdkIpwMfnYe G82tZz8mTszMh/1N6N24/2xUMHozgG19rHV7wL3KPOfipeIxr4MB4Y4kYZ72vRDomhjI ZNxVBjgLLx3aR+2CkTiwTCY8xmH97svzGdb+ZYfB6Dosl4xKpskh5Q19i9vKk+QmlSj9 J7QA== 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=dhIbXTsqZHOaabLTvbohbmanoOn5oKYJ7LsesfP0lB8=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=e6q9W3e0cB8lwUkZDJ3YYchOG4JchUBt/eldlhI2TSZPzD8ePsl7f1n5LOAsH/bvxc yI8bA6tnpsXqiANbuxPhe8fyvxVJMgtGNKiHi25nIkVLJgRXgatzFQBtrpKnLdBtb7vH W39gCFpUwpJM5TYgE+3U8kOp5vIOCW4DXVQsNtc3p0lWYfLBbtr6QGnXRBJKY/94ugXT e+IkhhzWK9ac0PCjRnSd5CYjPNqtufrFbyWLSvu8Y17qp5XjbGAYZZEEaEfc1bP0G1Kq W5Q7oFqCIeDTm+301rU0wtRLQRIotri/vHY/c8PJub7InFbjbgMClm+80JVVUyX7/SXT mPwg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fLiH7La7; 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 o6-20020a05620a0d4600b0078731f44049si14765894qkl.91.2024.02.23.00.31.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 00:31:33 -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=fLiH7La7; 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 D529F385828B for ; Fri, 23 Feb 2024 08:31:32 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 7AFE1385842B for ; Fri, 23 Feb 2024 08:28:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7AFE1385842B 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 7AFE1385842B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708676909; cv=none; b=u4ol95OURdrT8C4QhrEZ3m4l8A1S7c6/erYN3B4dXWovZh2/hbusJhmldrKHER6+NWjpQ7UZnznA6bUedESDif2k1uvJ97V/M/JXEdBCUNKf16+5kF0h0AL8nfLK0s8KFhpnfQmvnHL6kk0wowxjNvISQg1UecYZAz1CoV1JcDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708676909; c=relaxed/simple; bh=RgfUBtYHasWISACGjnjJN3pEX94tWEP+eUBPaDYwuBI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=w9DiT4TWQkqZN+kC8j8gbQUEf5UkshpeNPR8Y8AIez5oO63kLEQGB9SalOL6ImASIQPyvtSqw+iFs1Dvin4NMFVw0jo04OqiqPvgAHCOh88cAgA+4WMFl+39f9GFER7D/19RRCSYF+vO7pxD9Y48fuxNxruwZQXOTU1BDNI8iHI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708676906; 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=dhIbXTsqZHOaabLTvbohbmanoOn5oKYJ7LsesfP0lB8=; b=fLiH7La7nQ0b62Gy126iXNGW7QeIEF8EpkdhFHkKdURJ1UFpVKU/N7w5W+jqnmJA0EsEDx JkfotSHLv4OkkS0mjQ3RrdEtHngPFEMqawVqz0a6bRj0X2XnVYc95b8ELAnNGoTD6xlDCy Nj72rD3n/AwlQN03AeW51MQFPTXo6fo= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-351-nPc2TDBVMB-OdNrKW9J3rQ-1; Fri, 23 Feb 2024 03:28:24 -0500 X-MC-Unique: nPc2TDBVMB-OdNrKW9J3rQ-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 7710529AA39D; Fri, 23 Feb 2024 08:28:24 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B9F410800; Fri, 23 Feb 2024 08:28:24 +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 41N8SL4s955972 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 23 Feb 2024 09:28:22 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 41N8SKUR955971; Fri, 23 Feb 2024 09:28:20 +0100 Date: Fri, 23 Feb 2024 09:28:20 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] expr: Fix REDUCE_BIT_FIELD in multiplication expansion [PR114054] 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.7 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_H2, 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: 1791677792121825293 X-GMAIL-MSGID: 1791677792121825293 Hi! The following testcase ICEs, because the REDUCE_BIT_FIELD macro uses the target variable implicitly: #define REDUCE_BIT_FIELD(expr) (reduce_bit_field \ ? reduce_to_bit_field_precision ((expr), \ target, \ type) \ : (expr)) and so when the code below reuses the target variable, documented to be The value may be stored in TARGET if TARGET is nonzero. TARGET is just a suggestion; callers must assume that the rtx returned may not be the same as TARGET. for something unrelated (the value that should be returned), this misbehaves (in the testcase target is set to a CONST_INT, which has VOIDmode and reduce_to_bit_field_precision assert checking doesn't like that). Needed to say that If TARGET is CONST0_RTX, it means that the value will be ignored. but in expand_expr_real_2 does at the start: ignore = (target == const0_rtx || ((CONVERT_EXPR_CODE_P (code) || code == COND_EXPR || code == VIEW_CONVERT_EXPR) && TREE_CODE (type) == VOID_TYPE)); /* We should be called only if we need the result. */ gcc_assert (!ignore); - so such target is mainly meant for calls and the like in other routines. Certainly doesn't expect that target changes from not being ignored initially to ignore later on and other CONST_INT results as well as anything which is not an object into which anything can be stored. So, the following patch fixes that by using a more appripriate temporary for the result, which other code is using. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-02-23 Jakub Jelinek PR rtl-optimization/114054 * expr.cc (expand_expr_real_2) : Use temp variable instead of target parameter for result. * gcc.dg/bitint-92.c: New test. Jakub --- gcc/expr.cc.jj 2024-02-14 14:26:19.709811397 +0100 +++ gcc/expr.cc 2024-02-22 18:39:37.852431789 +0100 @@ -10259,12 +10259,12 @@ expand_expr_real_2 (sepops ops, rtx targ &algorithm, &variant, cost) : cost < mul_cost (speed, mode)) { - target = bit0_p ? expand_and (mode, negate_rtx (mode, op0), - op1, target) - : expand_and (mode, op0, - negate_rtx (mode, op1), - target); - return REDUCE_BIT_FIELD (target); + temp = bit0_p ? expand_and (mode, negate_rtx (mode, op0), + op1, target) + : expand_and (mode, op0, + negate_rtx (mode, op1), + target); + return REDUCE_BIT_FIELD (temp); } } } --- gcc/testsuite/gcc.dg/bitint-92.c.jj 2024-02-22 18:43:56.433910671 +0100 +++ gcc/testsuite/gcc.dg/bitint-92.c 2024-02-22 18:43:29.464277919 +0100 @@ -0,0 +1,17 @@ +/* PR rtl-optimization/114054 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-Og -fwhole-program -fno-tree-ccp -fprofile-use -fno-tree-copy-prop -w" } */ + +int x; + +void +foo (int i, unsigned u) +{ + x = __builtin_mul_overflow_p ((unsigned _BitInt(1)) u, i, (_BitInt(33)) 0); +} + +int +main () +{ + foo (11, 0); +}