From patchwork Sat Sep 17 06:02:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1275 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp76066wrt; Fri, 16 Sep 2022 23:03:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4jz5h++MWB+oeZRMNdXPoQecTbtcoQNVY9wv7KQOL/uQco/8o9xL9QJ9WsJ/qmi33N/NRK X-Received: by 2002:a17:907:75f4:b0:77c:1b9b:96b3 with SMTP id jz20-20020a17090775f400b0077c1b9b96b3mr5763852ejc.459.1663394637723; Fri, 16 Sep 2022 23:03:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663394637; cv=none; d=google.com; s=arc-20160816; b=IO/Rd1HL9/RZXlSuHkMSv0VKhz4q2qiQVn6Wjqpf7773zsiRhzWl7wj21nlE+TzlmO Kr1fTd0XUvyWEt+WOBMiDLGUF/xG0ivXXm12V6r0hYFAyJRCsOXQGSOW9eLW74NIQugH mc83NjQyCv2LiDyQwVcU2mhjDeGHIJiNGSk1tGNB0bDg1wiBdJ8HyMrkcqCxUMAS/6lp x6GyMBnn4B4ESe2cGMm9YvU3z1hchokShrIZzDbYX3/pEU5aMUN5OFjcAR3i3uSVHTkg b6nXja3+4zFI8lhwWjREGNmXK5bAZDoJskYxXjRzl448+bJ2/EVgfVLG4UbjdjKOtw6+ nLNw== 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 :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=A3ENRt4itG4wEFrhyU3A0k1sWnpdoifkh29L+J5OeJY=; b=mEF41iOIQjmyEtxit8BJ3yeMRxPFYBcx0yw6NFhCzCWNLYGxc1h7Ue6FjnbXIzgtK/ S7Ai9bSaaoNQFV4PDGAjOLtCQMNFD7SIu3kARsImnZZSFuq0f07HMUM+/qlp0kT/or3k kklbRfb75P9wsMltvcZsrTd5PNjVdQtz2hhk8PsT0bYB6b/JWpIaQlUtzGBPnlPBPNa9 ANdH4GwuGuTAq6hz0QIt2PYPK0CFjLv1it5Q/Gi2TlbUF3KRdlH0nfhzwkDGiAW6WW+Y +u6Q4uvptFsH6MghmJA5G1jWWebogVHc3qHNuWjqfXpWnFRT4kCvwL9k2www0Vtle98G C6jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Fed67gW0; 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 u28-20020a50d51c000000b004527d7fffacsi3238643edi.189.2022.09.16.23.03.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 23:03:57 -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=Fed67gW0; 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 6AA26381158A for ; Sat, 17 Sep 2022 06:03:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6AA26381158A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663394636; bh=A3ENRt4itG4wEFrhyU3A0k1sWnpdoifkh29L+J5OeJY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Fed67gW0cObcvt7sSD1fe2EbDILK8+Q7I6P5M6ahW2kYfb+GasFgFNBO5fUSYpsrz 0+j+wOdGdQmIrSY/BApINFoUCfZOftoSBmuvGTtZm/DTAfeBw8vJJuCcETpV6+GPAh OcE5ZDST5yWXWmi78o1BzJISV9iZYCbjImQIfTMc= 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 86B263857C4C for ; Sat, 17 Sep 2022 06:03:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 86B263857C4C 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-671-MpmCj8ZnMU-92fNoYw1HBQ-1; Sat, 17 Sep 2022 02:03:05 -0400 X-MC-Unique: MpmCj8ZnMU-92fNoYw1HBQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8C3073804087; Sat, 17 Sep 2022 06:03:05 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D87D82166B26; Sat, 17 Sep 2022 06:03:02 +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 28H62cCg4076999 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 17 Sep 2022 08:02:38 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 28H62ang4076998; Sat, 17 Sep 2022 08:02:36 +0200 Date: Sat, 17 Sep 2022 08:02:36 +0200 To: Richard Biener , Jeff Law Subject: [PATCH] reassoc: Fix up recent regression in optimize_range_tests_cmp_bitwise [PR106958] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, 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?1744195695395803295?= X-GMAIL-MSGID: =?utf-8?q?1744195695395803295?= Hi! As the following testcase reduced from glibc fmtmsg.c shows (it doesn't ICE on x86_64/i686 unfortunately, but does on various other arches), my last optimize_range_tests_cmp_bitwise change wasn't fully correct. The intent was to let all pointer operands be cast to pointer_sized_int_node first in addition to the other casts (to type1) which are done for id >= l cases. But one spot I've touched used always cast to type1 (note, the (b % 4) == 3 case is impossible for pointer operands because that is for !TYPE_UNSIGNED operands and pointers are TYPE_UNSIGNED) and in the other spot the cast would be done only for id >= l if not useless, but for pointers we need to cast it always. The following patch fixes that, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-09-17 Jakub Jelinek PR tree-optimization/106958 * tree-ssa-reassoc.cc (optimize_range_tests_cmp_bitwise): If id >= l, cast op to type1, otherwise to pointer_sized_int_node. If type has pointer type, cast exp to pointer_sized_int_node even when id < l. * gcc.c-torture/compile/pr106958.c: New test. Jakub --- gcc/tree-ssa-reassoc.cc.jj 2022-09-14 12:36:28.902351064 +0200 +++ gcc/tree-ssa-reassoc.cc 2022-09-16 22:25:23.671110030 +0200 @@ -3680,15 +3680,18 @@ optimize_range_tests_cmp_bitwise (enum t if (id == l || POINTER_TYPE_P (TREE_TYPE (op))) { code = (b % 4) == 3 ? BIT_NOT_EXPR : NOP_EXPR; - g = gimple_build_assign (make_ssa_name (type1), code, op); + tree type3 = id >= l ? type1 : pointer_sized_int_node; + g = gimple_build_assign (make_ssa_name (type3), code, op); gimple_seq_add_stmt_without_update (&seq, g); op = gimple_assign_lhs (g); } tree type = TREE_TYPE (r->exp); tree exp = r->exp; - if (id >= l && !useless_type_conversion_p (type1, type)) + if (POINTER_TYPE_P (type) + || (id >= l && !useless_type_conversion_p (type1, type))) { - g = gimple_build_assign (make_ssa_name (type1), NOP_EXPR, exp); + tree type3 = id >= l ? type1 : pointer_sized_int_node; + g = gimple_build_assign (make_ssa_name (type3), NOP_EXPR, exp); gimple_seq_add_stmt_without_update (&seq, g); exp = gimple_assign_lhs (g); } --- gcc/testsuite/gcc.c-torture/compile/pr106958.c.jj 2022-09-16 22:27:53.143079198 +0200 +++ gcc/testsuite/gcc.c-torture/compile/pr106958.c 2022-09-16 22:27:25.196458901 +0200 @@ -0,0 +1,13 @@ +/* PR tree-optimization/106958 */ + +int a; +void bar (int); + +void +foo (char *x, char *y) +{ + int b = a != 0; + int c = x != 0; + int d = y != 0; + bar (b | c | d); +}