From patchwork Wed Jan 31 14:18:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 194781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1923364dyb; Wed, 31 Jan 2024 06:25:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRmEtPL1BMVPp+TmhFapf/adpbO97OyubPX+W++DlU5KIclqf+//Ex+OSciRz7ASO1yr2p X-Received: by 2002:a05:6214:c4d:b0:686:964a:fda with SMTP id r13-20020a0562140c4d00b00686964a0fdamr1610887qvj.49.1706711110230; Wed, 31 Jan 2024 06:25:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706711110; cv=pass; d=google.com; s=arc-20160816; b=wUz9pXfbGdSIYmxL3dNHGOnBEk3A3qiX4koxGYMncJVmYrnMS5FVU6SwsoFXnSUBEd 3HHY4J15OJUh+vesbAb68wxB8HvqygoJZOoUvCg8yqhwfe4RRTM635iorn0IAYTisTkg rJUhQ42SpWOZUAjAdrwXUiq1wsYQA68vvuW94nIOOvtk8YJ25xLxxkvCf2RX+O/YlRAI H36iDHUlIjxBmmQvM6U5IUTU6xxMO7xnbnU/fzBM4AYbDYTAkJV1BeQm1fZezJD2VmYl Pa0/VUNRniFBT7FEJ8Dne5iqgHDRr+yLmfA1MxrxyCtYUsDUs+32ofuXt9eq6fG4QwQ+ E3iw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:errors-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :subject:to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=D5rpQWPj+rsF+QkXSQ+aDARpJPPwV4HJOf6MUfC5VUs=; fh=U/VSvyj1Xm3meSMvF+mtowY97nlmYo3/XniP2/CfZgE=; b=CS0zP2z9jjnRsDRi4nRa688hnOKFIEf4F20jqmb7eUUNoqLxC5/QjHVIgcD3ATjtF4 LHrBttc/2NyRN/v+GH8fudDYa87QI4D65qAqPRwjkchyn7hNhK3PPmeUiu2vAVYHDcyt 3ujZggoSfKX4kG4aqFVVhSdYkla8oPWY/+k3fZwqczZJR6WZjin7MiGsS5NazAR3FwZd LW4omCpcb4jgZm/0PBYBXhs3YxWIrtOfWsk6c2inVBiT90YTy+lLckf6YvmPxD1D+O5r ZMB+9UhYdVd2KWp+/vYmWNevaRfVLQ0c9ESqOcOguwbZGHgWmew64ZionobPKUPSf/E/ KB+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=c419Lj0+; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=c419Lj0+; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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=suse.de X-Forwarded-Encrypted: i=1; AJvYcCUTGM7J4CNfMyRU+jibF5uK6W56H8YkJfwwdj9RionmYdIxMmp4mYfxkXJuZYPfgCU0KjCvBCAaHuhbLb5xYTfkfmtiQw== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j28-20020a05620a147c00b00783f928838dsi7516822qkl.465.2024.01.31.06.25.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 06:25:10 -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=@suse.de header.s=susede2_rsa header.b=c419Lj0+; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=c419Lj0+; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E4BE53858D20 for ; Wed, 31 Jan 2024 14:25:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 40042385802B for ; Wed, 31 Jan 2024 14:24:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 40042385802B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 40042385802B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706711044; cv=none; b=YfGeGC1c0mRuFm49OeZx23VQNYd4Br1Hmmp6ntgR+eKOU/gvSZnpamJafyC0hHdz3YtoJlUlFAyjosaeauL988AkFzA/eTDgP/4NCjbUHR8+/okpG8kEcf+Rd2/Gg1fCfcQ32VtR3TBu/PDY0G+AVXBUCaqIea5+sr14dTIoN2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706711044; c=relaxed/simple; bh=BH4ReXQggPM3AymVVRZt2r3dt1DCrvc9AmDzEicXjoo=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=uA3SxGtaUw/JntlMwzz3bL05AtpDy+Rk1QSPe2D3q1SuVndGDwO0RW50X2ZxWvkL4Qm05gCWK3zQ9z6yZ/1+jOY8JGrVWchQCc2Qm6JZvM3L7/xcfoUTUU/mR31b3TX0jwv6hejJdpxpJZ/fp/DSuGEwQeqAHqcvVBDK7dFEL38= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5693C22018 for ; Wed, 31 Jan 2024 14:24:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706711040; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=D5rpQWPj+rsF+QkXSQ+aDARpJPPwV4HJOf6MUfC5VUs=; b=c419Lj0+dYmXS6ZHIfegRKzflPbVZAYfYMqm/KX0mUyYm2Gzpqd9+Axdz0wdwqQAP0vMy/ 1LIH1wjlnrBjUqJ1z2PH8HDqmZpLkfEYOpoRefwz7vBJ4gqLMvnC/QNmQVIpISfXIvjCcQ 8I+hO85BSJat0hgUnkHfRIHQAblbgyg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706711040; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=D5rpQWPj+rsF+QkXSQ+aDARpJPPwV4HJOf6MUfC5VUs=; b=cMxwnaH3CBfetremfihPeYBnkTwOnEASEil2FzrtOZP4KufvPSAHqJ3Vghph4ZDaJe+MbP sQLKFoqyZUGSzVBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706711040; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=D5rpQWPj+rsF+QkXSQ+aDARpJPPwV4HJOf6MUfC5VUs=; b=c419Lj0+dYmXS6ZHIfegRKzflPbVZAYfYMqm/KX0mUyYm2Gzpqd9+Axdz0wdwqQAP0vMy/ 1LIH1wjlnrBjUqJ1z2PH8HDqmZpLkfEYOpoRefwz7vBJ4gqLMvnC/QNmQVIpISfXIvjCcQ 8I+hO85BSJat0hgUnkHfRIHQAblbgyg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706711040; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=D5rpQWPj+rsF+QkXSQ+aDARpJPPwV4HJOf6MUfC5VUs=; b=cMxwnaH3CBfetremfihPeYBnkTwOnEASEil2FzrtOZP4KufvPSAHqJ3Vghph4ZDaJe+MbP sQLKFoqyZUGSzVBg== Date: Wed, 31 Jan 2024 15:18:22 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/110176 - wrong zext (bool) <= (int) 4294967295u folding MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 2.47 X-Spamd-Result: default: False [2.47 / 50.00]; TO_DN_NONE(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(3.00)[1.000]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_ONE(0.00)[1]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_SPAM_LONG(0.07)[0.021]; FUZZY_BLOCKED(0.00)[rspamd.com] X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Message-Id: <20240131142509.E4BE53858D20@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789616309122233624 X-GMAIL-MSGID: 1789616309122233624 The following fixes a wrong pattern that didn't match the behavior of the original fold_widened_comparison in that get_unwidened returned a constant always in the wider type. But here we're using (int) 4294967295u without the conversion applied. Fixed by doing as earlier in the pattern - matching constants only if the conversion was actually applied. Boostrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. PR middle-end/110176 * match.pd (zext (bool) <= (int) 4294967295u): Make sure to match INTEGER_CST only without outstanding conversion. * gcc.dg/torture/pr110176.c: New testcase. --- gcc/match.pd | 12 +++---- gcc/testsuite/gcc.dg/torture/pr110176.c | 46 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr110176.c diff --git a/gcc/match.pd b/gcc/match.pd index e42ecaf9ec7..a82bb08cd45 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -6754,19 +6754,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) >= TYPE_PRECISION (TREE_TYPE (@10))) && (TYPE_UNSIGNED (TREE_TYPE (@00)) == TYPE_UNSIGNED (TREE_TYPE (@10)))) - || (TREE_CODE (@10) == INTEGER_CST + || (TREE_CODE (@1) == INTEGER_CST && INTEGRAL_TYPE_P (TREE_TYPE (@00)) - && int_fits_type_p (@10, TREE_TYPE (@00))))) + && int_fits_type_p (@1, TREE_TYPE (@00))))) (cmp @00 (convert @10)) - (if (TREE_CODE (@10) == INTEGER_CST + (if (TREE_CODE (@1) == INTEGER_CST && INTEGRAL_TYPE_P (TREE_TYPE (@00)) - && !int_fits_type_p (@10, TREE_TYPE (@00))) + && !int_fits_type_p (@1, TREE_TYPE (@00))) (with { tree min = lower_bound_in_type (TREE_TYPE (@10), TREE_TYPE (@00)); tree max = upper_bound_in_type (TREE_TYPE (@10), TREE_TYPE (@00)); - bool above = integer_nonzerop (const_binop (LT_EXPR, type, max, @10)); - bool below = integer_nonzerop (const_binop (LT_EXPR, type, @10, min)); + bool above = integer_nonzerop (const_binop (LT_EXPR, type, max, @1)); + bool below = integer_nonzerop (const_binop (LT_EXPR, type, @1, min)); } (if (above || below) (if (cmp == EQ_EXPR || cmp == NE_EXPR) diff --git a/gcc/testsuite/gcc.dg/torture/pr110176.c b/gcc/testsuite/gcc.dg/torture/pr110176.c new file mode 100644 index 00000000000..e41e3a0c3a7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr110176.c @@ -0,0 +1,46 @@ +/* { dg-do run } */ + +int f(_Bool t) +{ + int tt = t; + unsigned x = -1; + int xx = x; + return xx <= tt; +} + +int a, b; +void c() {} +__attribute__((noipa)) +void h() {__builtin_abort();} +int d() { + unsigned f[1]; + int i; + if (a) + goto h; + f[0] = -1; + while (1) { + c(); + for (; a < 1; a++) { + if (0) { + j: + continue; + } + i = f[0]; + if (a) + break; + b = i >= (b == 0); + } + if (!b) { + if (0) { + h: + goto j; + } + return 0; + } + h(); + } +} +int main() { + d(); + return 0; +}