From patchwork Fri May 13 18:41:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1630924 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=Y0+F8kMQ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L0HZ30JWBz9sGF for ; Sat, 14 May 2022 04:42:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 70B62397EC27 for ; Fri, 13 May 2022 18:42:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70B62397EC27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652467335; bh=p67II6KtRiwb8hf9LipZVcSDnUv+d0WS4jyRpwrIR+4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Y0+F8kMQntatyapy6YmZXE1x/gYFkW5MQsh6eNv7irhifgPMzH9G4AMfF7tL0OS2J MjMHwHlcMc8EB6HjQGzwTN/uGqJiNEJWbL3hbtWhrq41nFBpgg6BJxVG77pj0OP4IV zuQ1UiMZdUC5Vi5WRjHcZLsqdYjGZoF3yzLSBRtE= 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 E3762397EC20 for ; Fri, 13 May 2022 18:41:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E3762397EC20 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-524-Co82dMrfPJy1bC_4o_Gn-g-1; Fri, 13 May 2022 14:41:41 -0400 X-MC-Unique: Co82dMrfPJy1bC_4o_Gn-g-1 Received: by mail-qv1-f71.google.com with SMTP id s19-20020ad44b33000000b00456107e1120so7488671qvw.0 for ; Fri, 13 May 2022 11:41:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:from:subject; bh=1cdhSO184an+DUEaihM8aAqdG5iyc+sKQ74a6HToku4=; b=7deoohR/N/H6WobOyBB/zM5QE197x3HkbgnkCmMq7rYQav6q7gmj3ISIJMr9o0gdrT pAaH7yCxrL0kL6ThnpUJIhkdxlfzl17TX/dg1ueHh+Jps1by8mUYzJsIe+o+hvP9XrJ3 AfzCHXctj4yCYgPdQpzINZqms6smFL0nBvkn6z2Ujs+m2XorOs+cHBOgWJMu2g3/n/3r uyuNxdyblA/v9LB8Weq1yTo7Tcyh69/Pe1TBG61STv/VLLi28Oj85f/AK7M5/UkEK2AM +nMTFFOpcvW3RZThXJzUDZbMIlOTdsuLsPK9CPhQ3HBbGO/5TKre6ITHU4KOgI350LGS Cxfg== X-Gm-Message-State: AOAM532nvC+6vWpgDkKRNCzop+LAf4ws9JHN2d2uugCg10NJwyeniSrm EhFNOwHfTcCtQ9mHBgtnVmC1+iUM/9N/kM+gWAgZJifzjmxmc5woO8dyfAXhBgK4FhycEznKxS/ SqrDVCQhotbeVHwbvoyWowGrha0AasqN5FBTj3ReRd8acxC9E+GMC31HKvHI2+Zk89YxrAw== X-Received: by 2002:ad4:5bc1:0:b0:42c:37be:6ac3 with SMTP id t1-20020ad45bc1000000b0042c37be6ac3mr5542475qvt.18.1652467300148; Fri, 13 May 2022 11:41:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOBgCu88o86rJ/I8z8wlEPxHnImpkyC99V4kQdf0w3j/BC6ht76c3+ZZW9HSgTmRkyR51GRQ== X-Received: by 2002:ad4:5bc1:0:b0:42c:37be:6ac3 with SMTP id t1-20020ad45bc1000000b0042c37be6ac3mr5542453qvt.18.1652467299881; Fri, 13 May 2022 11:41:39 -0700 (PDT) Received: from ?IPV6:2607:fea8:a261:5e00::94b0? ([2607:fea8:a261:5e00::94b0]) by smtp.gmail.com with ESMTPSA id j16-20020ac84c90000000b002f39b99f69csm1814922qtv.54.2022.05.13.11.41.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 May 2022 11:41:39 -0700 (PDT) Message-ID: <7f4cfcb9-1f8d-a268-e4c8-0b7c39871390@redhat.com> Date: Fri, 13 May 2022 14:41:37 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 To: gcc-patches Subject: [COMMITTED] PR tree-optimization/105597 - Check operand for type, not LHS. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Earlier patch was picking the type of the expression in a minus operation from the LHS.   When we are folding, the LHS may not be defined yet. Instead, pick up the type from operand 1, and ensure it isn't undefined while we're at it. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew commit e97e99296505e6015bc9e281364818bb89ca8a49 Author: Andrew MacLeod Date: Fri May 13 13:11:18 2022 -0400 Check operand for type, not LHS. When folding, the LHS has not been set, so we should be checking the type of op1. We should also make sure op1 is not undefined. PR tree-optimization/105597 gcc/ * range-op.cc (operator_minus::lhs_op1_relation): Use op1 instead of the lhs and make sure it is not undefined. gcc/testsuite/ * gcc.dg/pr105597.c: New. diff --git a/gcc/range-op.cc b/gcc/range-op.cc index e6b32e288b0..c88da8caa6c 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1343,10 +1343,10 @@ operator_minus::wi_fold (irange &r, tree type, // OP1 and OP2. relation_kind -operator_minus::lhs_op1_relation (const irange &lhs, const irange &, +operator_minus::lhs_op1_relation (const irange &, const irange &op1, const irange &, relation_kind rel) const { - if (TYPE_SIGN (lhs.type ()) == UNSIGNED) + if (!op1.undefined_p () && TYPE_SIGN (op1.type ()) == UNSIGNED) switch (rel) { case VREL_GT: diff --git a/gcc/testsuite/gcc.dg/pr105597.c b/gcc/testsuite/gcc.dg/pr105597.c new file mode 100644 index 00000000000..e463ec6c194 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105597.c @@ -0,0 +1,27 @@ +/* PR tree-optimization/105597 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wno-int-conversion" } */ + +typedef struct { + int allocated; +} vvec; + +int vvneeds_want, mgpssort; + +void vvinit(vvec *v, int minelems) { v->allocated = -minelems; } + +void vvneeds(vvec *v, int needed) { + if (needed > v->allocated) + if (v->allocated < 0) + ; + else { + int next = v->allocated + (v->allocated >> 1); + vvneeds_want = next; + } +} + +void mgpssort_1() { + vvinit((vvec *) &mgpssort, mgpssort_1); + vvneeds((vvec *) &mgpssort, mgpssort_1); +} +