From patchwork Mon Oct 26 21:50:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1388147 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=LbaJV/Qk; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 ozlabs.org (Postfix) with ESMTPS id 4CKpS83dbSz9sSf for ; Tue, 27 Oct 2020 08:51:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 793C33947437; Mon, 26 Oct 2020 21:51:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 793C33947437 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1603749061; bh=E7yqBYWzlD08PHW9lwZcY/NvPPkgp2IP5f78P7M4ZjA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=LbaJV/Qk4BNHvbRNgJSQYlyiEn/w2qPSbb8iVI1fqdGTMtreMx90yBYKiZl6Qf4iM rklHUOCshco05EpwJzYbZ2mfyzNEZqYz9iTc5s+SES9B9lr5AZQUcrd2ybte+bmJSM NyBlBd9e1qt7VUUIBESBuo1Y/0EcVjhbXI+8+p4M= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 750A43857C43 for ; Mon, 26 Oct 2020 21:50:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 750A43857C43 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-589-C4kN5ktfMuyrwtxSzW0Rdw-1; Mon, 26 Oct 2020 17:50:55 -0400 X-MC-Unique: C4kN5ktfMuyrwtxSzW0Rdw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CBD0680365F for ; Mon, 26 Oct 2020 21:50:54 +0000 (UTC) Received: from [10.10.112.225] (ovpn-112-225.rdu2.redhat.com [10.10.112.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A01560FC2 for ; Mon, 26 Oct 2020 21:50:54 +0000 (UTC) To: gcc-patches Subject: [PATCH] Combine logical OR ranges properly. pr97567 Message-ID: <1d5dd212-cd02-6b6d-0e89-20c7e96f3a02@redhat.com> Date: Mon, 26 Oct 2020 17:50:53 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" In the core of gori_compute::logical_combine we are suppose to combine the calculated true and false ranges on each side of  the operation. when encountering [0,0] =   c_3  | c_4 we know we only need to consider the FALSE values of the range carried by c_3 and c_4, but it can be EITHER of those ranges, so we need to union them together to get the correct result. The code was performing an intersection instead, and in this particualr case, we knew the range carried thru c_3 was alwasy [0,0]  and it was always varying through c_4....    instead of returning varying,  we were returning [0,0]  which then caused some folding which was incorrect. Fixed by correctly calling union... Bootstrapped on x86_64-pc-linux-gnu, no regressions, and pushed. Andrew commit 48722d158cbf692c24025e345ecbbbb570f66aa5 Author: Andrew MacLeod Date: Mon Oct 26 14:55:00 2020 -0400 Combine logical OR ranges properly. When combining logical OR operands with a FALSE result, union the false ranges for operand1 and operand2... not intersection. gcc/ PR tree-optimization/97567 * gimple-range-gori.cc (gori_compute::logical_combine): Union the ranges of operand1 and operand2, not intersect. gcc/testsuite/ * gcc.dg/pr97567.c: New. diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 5d50b111d2a..de0f653860d 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -730,10 +730,10 @@ gori_compute::logical_combine (irange &r, enum tree_code code, if (lhs.zero_p ()) { // An OR operation will only take the FALSE path if both - // operands are false, so [20, 255] intersect [0, 5] is the + // operands are false, so either [20, 255] or [0, 5] is the // union: [0,5][20,255]. r = op1.false_range; - r.intersect (op2.false_range); + r.union_ (op2.false_range); } else { diff --git a/gcc/testsuite/gcc.dg/pr97567.c b/gcc/testsuite/gcc.dg/pr97567.c new file mode 100644 index 00000000000..b2b72a4d2a7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr97567.c @@ -0,0 +1,34 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +int a, b, c, d; +void k() { + unsigned f = 1; + long g = 4073709551615; + for (; a; a++) + for (;;) { + d = 0; + L1: + break; + } + if (f) + for (; a; a++) + ; + g || f; + int i = 0 - f || g; + long j = g - f; + if (j || f) { + if (g < 4073709551615) + for (;;) + ; + int e = ~f, h = b / ~e; + if (c) + goto L2; + g = f = h; + } + g || d; +L2: + if (c) + goto L1; +} +int main() { k(); return 0; }