From patchwork Wed Jan 4 09:20:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 38818 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp5048154wrt; Wed, 4 Jan 2023 01:22:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXvlF8qtWkI2YiSfQuMxrZWZ5BngocoPGG5halFHMoXuT4Pz9Bk7UyT5qWg5EM/4z1WSzbFG X-Received: by 2002:a17:907:76ad:b0:7c0:f2cf:23fb with SMTP id jw13-20020a17090776ad00b007c0f2cf23fbmr43109099ejc.52.1672824161097; Wed, 04 Jan 2023 01:22:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672824161; cv=none; d=google.com; s=arc-20160816; b=E2KVl/4sEHt1ZNLk6J9+hSAgV+Zcd1ghplUdSWiN4Tp/Bz2/uNtDemW1uQrsjaa0DZ rwlTvPr/MFbShvlDDHFSfnTCQs1Q+EreHC/xQAQ3iUWJGy9gg8GehnCT4zgSJ5M+NCRl hpEGDJGB5vLS15dbmtseDNXCcVbCwae7Fc6UlCXBaDXJ5bpFw/ih+dcHVIoT3/Ihzk6Z nepcYrM09DceL2QKfyBirrPt8xBvsELa5U+Ybk8AsfkAvo2/tlo45J2oaq9lwTHrk+O8 UDKJm9fPbK1AKahTvzoziSvi4eBAum8oyft2fJIMQu5TCf1t5uNXi4DZTd01ZqIzG/g4 8VHw== 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 :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=xLh2RqIT2xrBCyBHcLoUgqyGZctL9kxFMrnhNcYR22Y=; b=hTJXWKB8T02jreZcqGLAfIpF8XlqI1F8tfpS5jbkfci24oTlCPZoLJWKE14Sy/J47/ UyO0KVViRPkkNrplnhPlmfPlgjEDKVSFWK8eOtl6Icn0koHxLokGgJPJ6VXRvEt1cMno AhomtKV39agxd8FsgkqD3HITCz1Geox0P+qf0CXSAsj/dqquTLM/+ObvFha6wr+AMq+E bcu8w+ZqjIcihRvf9hZ+dzoOjQ2WnAfdhxPSyb+ghsNqNvjBnlOWoKMiWOLlPRcsujsu w2COyd4sxbvp4rP/7xrqLLn0fywHBiIGn5NTeHB4eadOMNczRgBO+SsJp1LJ7GbSBehg 4jbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=az+xNN7y; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qb11-20020a1709077e8b00b007ada2ec1a28si32110102ejc.165.2023.01.04.01.22.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 01:22:41 -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=@gcc.gnu.org header.s=default header.b=az+xNN7y; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3CEA938493EA for ; Wed, 4 Jan 2023 09:21:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CEA938493EA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672824105; bh=xLh2RqIT2xrBCyBHcLoUgqyGZctL9kxFMrnhNcYR22Y=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=az+xNN7yk+eQdwUz3Ugf8mCY0SJe4x2911byiEpVuxaIEp90Eu4lXi90gg8V8KAXt OSV3zzp+jcNuCkAgzbFBYve5XQGnsYzXphhI9nwaGBim/iGdtldg3thXFvZQS5Dr1Y xOOauhCEKG0e6SiIGXD7j9FdJwstEvtzw28c7lXw= 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 3C4D4385B515 for ; Wed, 4 Jan 2023 09:21:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C4D4385B515 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-428-tqUDnYZ1OSSn-Zy2I094Aw-1; Wed, 04 Jan 2023 04:20:59 -0500 X-MC-Unique: tqUDnYZ1OSSn-Zy2I094Aw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7623D2999B2C; Wed, 4 Jan 2023 09:20:59 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 34C3751E5; Wed, 4 Jan 2023 09:20:59 +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 3049Kuiq2397937 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 4 Jan 2023 10:20:56 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3049KttK2397936; Wed, 4 Jan 2023 10:20:55 +0100 Date: Wed, 4 Jan 2023 10:20:55 +0100 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] generic-match-head: Don't assume GENERIC folding is done only early [PR108237] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.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.9 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 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek 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?1754083267244000782?= X-GMAIL-MSGID: =?utf-8?q?1754083267244000782?= Hi! We ICE on the following testcase, because a valid V2DImode != comparison is folded into an unsupported V2DImode > comparison. The match.pd pattern which does this looks like: /* Transform comparisons of the form (X & Y) CMP 0 to X CMP2 Z where ~Y + 1 == pow2 and Z = ~Y. */ (for cst (VECTOR_CST INTEGER_CST) (for cmp (eq ne) icmp (le gt) (simplify (cmp (bit_and:c@2 @0 cst@1) integer_zerop) (with { tree csts = bitmask_inv_cst_vector_p (@1); } (if (csts && (VECTOR_TYPE_P (TREE_TYPE (@1)) || single_use (@2))) (with { auto optab = VECTOR_TYPE_P (TREE_TYPE (@1)) ? optab_vector : optab_default; tree utype = unsigned_type_for (TREE_TYPE (@1)); } (if (target_supports_op_p (utype, icmp, optab) || (optimize_vectors_before_lowering_p () && (!target_supports_op_p (type, cmp, optab) || !target_supports_op_p (type, BIT_AND_EXPR, optab)))) (if (TYPE_UNSIGNED (TREE_TYPE (@1))) (icmp @0 { csts; }) (icmp (view_convert:utype @0) { csts; }))))))))) and that optimize_vectors_before_lowering_p () guarded stuff there already deals with this problem, not trying to fold a supported comparison into a non-supported one. The reason it doesn't work in this case is that it isn't GIMPLE folding which does this, but GENERIC folding done during forwprop4 - forward_propagate_into_comparison -> forward_propagate_into_comparison_1 -> combine_cond_expr_cond -> fold_binary_loc -> generic_simplify and we simply assumed that GENERIC folding happens only before gimplification. The following patch fixes that by checking cfun properties instead of always returning true in thos cases. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-01-04 Jakub Jelinek PR middle-end/108237 * generic-match-head.cc: Include tree-pass.h. (canonicalize_math_p, optimize_vectors_before_lowering_p): Define to false if cfun and cfun->curr_properties has PROP_gimple_opt_math resp. PROP_gimple_lvec property set. * gcc.c-torture/compile/pr108237.c: New test. Jakub --- gcc/generic-match-head.cc.jj 2023-01-02 09:32:42.954988078 +0100 +++ gcc/generic-match-head.cc 2023-01-03 17:31:07.627941369 +0100 @@ -40,6 +40,7 @@ along with GCC; see the file COPYING3. #include "tm.h" #include "tree-eh.h" #include "langhooks.h" +#include "tree-pass.h" /* Routine to determine if the types T1 and T2 are effectively the same for GENERIC. If T1 or T2 is not a type, the test @@ -71,7 +72,7 @@ single_use (tree t ATTRIBUTE_UNUSED) static inline bool canonicalize_math_p () { - return true; + return !cfun || (cfun->curr_properties & PROP_gimple_opt_math) == 0; } /* Return true if math operations that are beneficial only after @@ -90,7 +91,7 @@ canonicalize_math_after_vectorization_p static inline bool optimize_vectors_before_lowering_p () { - return true; + return !cfun || (cfun->curr_properties & PROP_gimple_lvec) == 0; } /* Return true if successive divisions can be optimized. --- gcc/testsuite/gcc.c-torture/compile/pr108237.c.jj 2023-01-03 17:35:37.411068635 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr108237.c 2023-01-03 17:35:22.490282820 +0100 @@ -0,0 +1,14 @@ +/* PR middle-end/108237 */ + +typedef unsigned char __attribute__((__vector_size__ (1))) U; +typedef unsigned long long __attribute__((__vector_size__ (16))) V; + +U u; +V v; + +V +foo (void) +{ + V w = v != ((unsigned char) ((unsigned char) u == u) & v); + return w; +}