From patchwork Fri Jun 16 11:45:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 109064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1278259vqr; Fri, 16 Jun 2023 04:46:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6AdMFp8JTi6yLfzNO7xyEqleue1Szq9xMxDpoV5USr8QZVSZg49DrYgyU05SFSwUj7yXtV X-Received: by 2002:a17:907:3187:b0:96f:c0b0:f137 with SMTP id xe7-20020a170907318700b0096fc0b0f137mr1739419ejb.16.1686915994154; Fri, 16 Jun 2023 04:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686915994; cv=none; d=google.com; s=arc-20160816; b=hmBiykKC3wZyfRyZ9nnWWVrZiUk43hWGxG0xyc3SN/qfLUoeOVW0t1AezpCTBMYlGN oc5N7YPt4k9+UQ8Wvqk+st/aaMZuJwYtswyTCt1kiVIq1mgBHYw3zgNGCsz8KA3id3xd k2dSfuZBGcg/VqH6lAiPhSvRSOv0FXufRX0w7mrdvvKVb6918d7DgGkzJVry1IO+rnDS r2aXF/bZCDfZ3LA+y4y+ma0v4wOnZKqT1PKgaM3dEcVMpVmJ4BvPZI6553GFF8N31FS0 bp4w0HTLy19zs9YA6+03hCcQXU4W6cgKGJWnnCaAZUgy39Wfo/G35ccAgd/QhsrwMh8c ZGxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=isptrB0YA+kMbtGtcQrm4EzaYhcZmY2pFc92WwvaqkI=; b=ADm/75ZYBG4JcFCpj/zC+A0BUcZGUvDDQWzZ8zw1zLYi7m4WnRK3z+WR/x8YDth9t0 ZIxx9W4L1pnAqUr4TTc+TYZw5xDWrdE4e9UbFNJd+5LKAyzqQuCgcXQ8Poabs0+3l7XM F+WKASBZJY/0m25YOvajQfgoeSDTJEsrHWET1eKCa+91SWlIcqENYuiqQ88rCeAqlC4B QqZlKHVHwo75d6zOrKnpfFIiGf78+/zvfLgRGYKheM3rYLduQnKDsDzPHheAo2HTRzSL pvezpgAwiOiJ9IG/HCZw2lDmPT3RToa3rnbGUBedQGWVgobajfEviuW1EMwSoclI008o pxsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=luj83G2x; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a5-20020a17090680c500b00986b9d4b626si80425ejx.268.2023.06.16.04.46.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 04:46:34 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=luj83G2x; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 488D53857722 for ; Fri, 16 Jun 2023 11:46:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 488D53857722 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686915992; bh=isptrB0YA+kMbtGtcQrm4EzaYhcZmY2pFc92WwvaqkI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=luj83G2xk75BTjYTvlPLr45LaLjZ4OBM5KwHnFxJ3wapMiQGDQA6I2hYPY9tSgHBV 2jo5ckdnyUPNnNd7pBEFgkUfswEnILKlEagqdaWUbEDSZwGkeaj97ZhydthK8DrRj9 eAJos+ol5w0VNY+pY9ToGjpGqdirwAJtED6nFa5o= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 5917E3858D35 for ; Fri, 16 Jun 2023 11:45:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5917E3858D35 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 5A0AB1F88E for ; Fri, 16 Jun 2023 11:45:49 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 47732138E8 for ; Fri, 16 Jun 2023 11:45:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0lkFEG1LjGSHEgAAMHmgww (envelope-from ) for ; Fri, 16 Jun 2023 11:45:49 +0000 Date: Fri, 16 Jun 2023 13:45:48 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/110278 - uns < (typeof uns)(uns != 0) is always false MIME-Version: 1.0 Message-Id: <20230616114549.47732138E8@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768859625581806674?= X-GMAIL-MSGID: =?utf-8?q?1768859625581806674?= The following adds two patterns simplifying comparisons, uns < (typeof uns)(uns != 0) is always false and x != (typeof x)(x == 0) is always true. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/110278 * match.pd (uns < (typeof uns)(uns != 0) -> false): New. (x != (typeof x)(x == 0) -> true): Likewise. --- gcc/match.pd | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gcc/match.pd b/gcc/match.pd index 264f9cb8a40..48b76e6a051 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -6410,6 +6410,17 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (cmp == GT_EXPR) (lt (view_convert:st @0) { build_zero_cst (st); }))))))))))) +/* unsigned < (typeof unsigned)(unsigned != 0) is always false. */ +(simplify + (lt:c @0 (convert (ne @0 integer_zerop))) + (if (TYPE_UNSIGNED (TREE_TYPE (@0))) + { constant_boolean_node (false, type); })) + +/* x != (typeof x)(x == 0) is always true. */ +(simplify + (ne:c @0 (convert (eq @0 integer_zerop))) + { constant_boolean_node (true, type); }) + (for cmp (unordered ordered unlt unle ungt unge uneq ltgt) /* If the second operand is NaN, the result is constant. */ (simplify