From patchwork Mon Sep 26 08:30:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1463 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp1418100wrt; Mon, 26 Sep 2022 03:37:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7VbhrxvbPvgZ7toXXnS/hkJ9mQvDGOuMs15j1j+0tvCGwHoq91MpLdG10WCE84HRxjV9Nc X-Received: by 2002:a17:907:da2:b0:782:b6a:326d with SMTP id go34-20020a1709070da200b007820b6a326dmr17418162ejc.429.1664188668818; Mon, 26 Sep 2022 03:37:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664188668; cv=none; d=google.com; s=arc-20160816; b=ZmBVsLxAx3a+JCwHplpjW7LpO2LWpVFsIjSfbC0I1oqqFPcuq7AA9tm9wIqipPXW9a 2t0Rf1U6ss353sb0LkU6VQYZvojrRoDDAK3mELmdGGeqUj0eXBTLazrglGqPSfTjVNwb n4/oH+mk3XBOB+bE20Xfr8jOdokwUQoUy/45HUmfWCkXgegiM18m4u67HM/iTZH8cuGB gwZgNsAel1JLSI/oV4UXGixfjgRauAebUeRVgPUTO03ddj9K1bt79fmJ+UeKNqK9WVYB IdDIMaP6P5DzX9vEtUzblXK+7RjOJ0U3dTTNRuEEHf3HIj0hufHE57PnmJNKZgwUDQhW YPrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :resent-to:resent-message-id:resent-date:resent-from:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=A4W9RLfPOdK2yaaCl1Wy0bvCGbUADcKUW5YJ1RDwoCQ=; b=t8aC5eSCBZYHfMeMppHqN0NR1gaXEyH4fZ9UqqudiGWB2YE3LqGgH2Dau+4ytc7YFQ 15KBjqWxEZLrgv129fUdH6ohWbudBlQuW/kRsxfXTDFkiC3j9ViHxcLPm0yYdG+mN395 4hwJFjN7TUwb45UsvAbt9uiI8e0N4gqBtR0FU8EuIv4frVpPioXFcqu79k4sDIqflSig vy8qdJsmL8JpgdSXUcUkqU+VvJTiogTxMkw/s8D/zHQI9KJ5tYg3VQylYmGDFHwng3mY 1xwej0Oid/sLELYOUBB0aPG4LaQqAC/Q0vJ5OOfdOYsg6lSV5IogjT/hEthCmQv0AOOu DMuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wFDklkPf; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qb28-20020a1709077e9c00b00783b2e423f7si1149111ejc.8.2022.09.26.03.37.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 03:37:48 -0700 (PDT) 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=wFDklkPf; 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 B380D3858406 for ; Mon, 26 Sep 2022 10:37:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B380D3858406 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664188657; bh=A4W9RLfPOdK2yaaCl1Wy0bvCGbUADcKUW5YJ1RDwoCQ=; h=Resent-From:Resent-Date:Resent-To:Date:To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:Cc:From; b=wFDklkPfwAxJGEeemcA61GjZpBj/YYoIDCCa8e3N3qzUnG1j4yoO2naQ6+UNy6wC0 91T5/Rin50ZIECqm74oL0njeLKD47vjvDTy6FQdWgncAkpaM505hxL538k16m/NA/w 30jLs02vEu6wedw60kT6O3/6CrSR4/CigSebOPt8= 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 BE5D03858032 for ; Mon, 26 Sep 2022 10:36:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BE5D03858032 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-228-YMukfMywNYWqwCY79gIeDA-1; Mon, 26 Sep 2022 06:36:47 -0400 X-MC-Unique: YMukfMywNYWqwCY79gIeDA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 08D04101A52A; Mon, 26 Sep 2022 10:36:47 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC9521121314; Mon, 26 Sep 2022 10:36:46 +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 28QAaias3964141 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 26 Sep 2022 12:36:44 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 28QAahnA3964140; Mon, 26 Sep 2022 12:36:43 +0200 Resent-From: Jakub Jelinek Resent-Date: Mon, 26 Sep 2022 12:36:43 +0200 Resent-Message-ID: Resent-To: Richard Biener , gcc-patches@gcc.gnu.org Date: Mon, 26 Sep 2022 10:30:44 +0200 To: Richard Biener Subject: [PATCH] reassoc: Handle OFFSET_TYPE like POINTER_TYPE in optimize_range_tests_cmp_bitwise [PR107029[ Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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, 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 Cc: gcc-patches@gcc.gnu.org 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?1745028297339000845?= X-GMAIL-MSGID: =?utf-8?q?1745028297339000845?= Hi! As the testcase shows, OFFSET_TYPE needs the same treatment as POINTER_TYPE/REFERENCE_TYPE, otherwise we fail the same during the newly added verification. OFFSET_TYPE is signed though, so unlike POINTER_TYPE/REFERENCE_TYPE it can also trigger with the x < 0 && y < 0 && z < 0 to (x | y | z) < 0 optimization. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-09-26 Jakub Jelinek PR tree-optimization/107029 * tree-ssa-reassoc.cc (optimize_range_tests_cmp_bitwise): Treat OFFSET_TYPE like POINTER_TYPE, except that OFFSET_TYPE may be signed and so can trigger even the (b % 4) == 3 case. * g++.dg/torture/pr107029.C: New test. Jakub --- gcc/tree-ssa-reassoc.cc.jj 2022-09-17 08:18:16.935880254 +0200 +++ gcc/tree-ssa-reassoc.cc 2022-09-25 14:46:21.746367580 +0200 @@ -3608,13 +3608,13 @@ optimize_range_tests_cmp_bitwise (enum t tree type2 = NULL_TREE; bool strict_overflow_p = false; candidates.truncate (0); - if (POINTER_TYPE_P (type1)) + if (POINTER_TYPE_P (type1) || TREE_CODE (type1) == OFFSET_TYPE) type1 = pointer_sized_int_node; for (j = i; j; j = chains[j - 1]) { tree type = TREE_TYPE (ranges[j - 1].exp); strict_overflow_p |= ranges[j - 1].strict_overflow_p; - if (POINTER_TYPE_P (type)) + if (POINTER_TYPE_P (type) || TREE_CODE (type) == OFFSET_TYPE) type = pointer_sized_int_node; if ((b % 4) == 3) { @@ -3646,7 +3646,7 @@ optimize_range_tests_cmp_bitwise (enum t tree type = TREE_TYPE (ranges[j - 1].exp); if (j == k) continue; - if (POINTER_TYPE_P (type)) + if (POINTER_TYPE_P (type) || TREE_CODE (type) == OFFSET_TYPE) type = pointer_sized_int_node; if ((b % 4) == 3) { @@ -3677,10 +3677,20 @@ optimize_range_tests_cmp_bitwise (enum t op = r->exp; continue; } - if (id == l || POINTER_TYPE_P (TREE_TYPE (op))) + if (id == l + || POINTER_TYPE_P (TREE_TYPE (op)) + || TREE_CODE (TREE_TYPE (op)) == OFFSET_TYPE) { code = (b % 4) == 3 ? BIT_NOT_EXPR : NOP_EXPR; tree type3 = id >= l ? type1 : pointer_sized_int_node; + if (code == BIT_NOT_EXPR + && TREE_CODE (TREE_TYPE (op)) == OFFSET_TYPE) + { + g = gimple_build_assign (make_ssa_name (type3), + NOP_EXPR, op); + gimple_seq_add_stmt_without_update (&seq, g); + op = gimple_assign_lhs (g); + } g = gimple_build_assign (make_ssa_name (type3), code, op); gimple_seq_add_stmt_without_update (&seq, g); op = gimple_assign_lhs (g); @@ -3688,6 +3698,7 @@ optimize_range_tests_cmp_bitwise (enum t tree type = TREE_TYPE (r->exp); tree exp = r->exp; if (POINTER_TYPE_P (type) + || TREE_CODE (type) == OFFSET_TYPE || (id >= l && !useless_type_conversion_p (type1, type))) { tree type3 = id >= l ? type1 : pointer_sized_int_node; @@ -3705,7 +3716,7 @@ optimize_range_tests_cmp_bitwise (enum t op = gimple_assign_lhs (g); } type1 = TREE_TYPE (ranges[k - 1].exp); - if (POINTER_TYPE_P (type1)) + if (POINTER_TYPE_P (type1) || TREE_CODE (type1) == OFFSET_TYPE) { gimple *g = gimple_build_assign (make_ssa_name (type1), NOP_EXPR, op); --- gcc/testsuite/g++.dg/torture/pr107029.C.jj 2022-09-25 14:49:18.427954682 +0200 +++ gcc/testsuite/g++.dg/torture/pr107029.C 2022-09-25 14:49:00.654197418 +0200 @@ -0,0 +1,19 @@ +// PR tree-optimization/107029 +// { dg-do compile } + +struct S { long long a; int b; }; +long long S::*a; +int S::*b; +struct A { void foo (bool, bool); void bar (); int c; }; + +void +A::foo (bool a, bool b) +{ + c = a || b; +} + +void +A::bar() +{ + foo (a, b); +}