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: 86256 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE696385828B for ; Fri, 23 Feb 2024 08:30:30 +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+patchwork=sourceware.org@gcc.gnu.org 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); +}