From patchwork Mon Nov 4 15:00:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 2006281 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ArH9B6iV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xhvmc22rsz1xxW for ; Tue, 5 Nov 2024 02:01:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 317D63857BA7 for ; Mon, 4 Nov 2024 15:00:59 +0000 (GMT) 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 ESMTP id A02003858C2B for ; Mon, 4 Nov 2024 15:00:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A02003858C2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A02003858C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730732440; cv=none; b=SzHFSPMyMYmUTQ1v4zZwuxbaYMUD30mapnOgYGoWqkPwDF/QBGpaco5IiFNj62P9guH1caOcgDc61BflYp4b3dZlJfKKlN2AjCeUP9uyhtKWkBxcF+gYVJ+eNeqT/eW/4sxv3eQHw/I9oYK7WxR2fu2KtCwtAYZ6YjLHJClNn1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730732440; c=relaxed/simple; bh=3zQpuXwvixrZjGuiFcev7JhiPfCMwf1yC95dtxCHm+w=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=gkdb/gJ1q/+cXRiDvFmSQkDPSFFYlIDy9HhCYIor1xlvEgQg6c/5OMOof78CBSBKZTr9WP6DQFG4a3akR6L9TZOP2KejrERgbpPdjN26zSpmyN3dpqlidDNtM2YNIQT706BNZSEdgUPfer3DMfPbGGyiMbAtMkVzMxAkq8zOXiA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730732432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=TDbdLtCal6zL1z51T9XDcrMxoRRC4YN5OV70cztlFRA=; b=ArH9B6iVSI0OuPf8Oo5qqM50jHflL6whjJZi35RDvSnbXiqoZMUZoW+wiVQwExyIZCLImd DjkXMiQK3wyurny4I4bhi1AgRUbfFG+yqy38HTw0oac0dDD3CovV30eIFuJToX8/Jxo3sI czgigTpz2EPVVtnlnetRV/ndf0gjF5U= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-649-9CocHwVHP3C-LAMStxFidQ-1; Mon, 04 Nov 2024 10:00:29 -0500 X-MC-Unique: 9CocHwVHP3C-LAMStxFidQ-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6d3672225b1so47707566d6.3 for ; Mon, 04 Nov 2024 07:00:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730732428; x=1731337228; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=J7HL14X2yD1Ja9oxpkfUK5dJ7DLY9ukAD2Onzz4tzR8=; b=NLC7Xu3D2xrWstJYxgOpDeJMqDe4lI8AP2gB8UJksLX2M7h+wY6yDDnVPLZgN4Uiwp 9EbQot3lfag2oVyYceJFgPfrLYgHDVpGMChAPHsVZo1RR81mRATLjDvZzyPOryJLOvqW xNRRpIL6/JZcQCh2U64PMV+RsqL4iukKboEq0MQbl6RJyaq64JqMpPAqEFNo4+MngJa3 LSONMWtfhNrXSKsRTPbo9eaKAV4HsBEUDjUYBR1O+Zfm4VVhG1dYc1MExvadtEvWfs9n ymaQwmQGivrj3NE/ZqSbW7yUVvMcwuPltiFJizwZsjVAnuRlNmfKt9DcJiB/qNTAjUc3 h/0g== X-Gm-Message-State: AOJu0YxbWFIG7EWcjySpUvJ9oFOWoOYulZfARuY67+m3c3JLO6tGSGKA s/RDg4n1z0LhmLug2qwU7QxmAo+bG9Zn3vy7PnAguBelSfxkCIu2EadKdOjhYGaO3qSjka6vWt+ 8SOx1C2CEKXboEpinE1UpXzSvLRTCZsMEfEbVIZ0eYuB91yCrDgdSl+lcRwKagkC/oZZMB7iFS7 U8EsaZVjoVQcdy4Z9si/Ju9lMsMGujClGY1neuMTu93A== X-Received: by 2002:a05:6214:53c4:b0:6cb:832e:9267 with SMTP id 6a1803df08f44-6d35c0a3a96mr242443146d6.7.1730732428651; Mon, 04 Nov 2024 07:00:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHb6z/adQBUHLCO2ksj2eyAJrGHtOo6IKVT6XtJ61AD3XOPyWH5ff6act5OVfhz2Nbh+HPStg== X-Received: by 2002:a05:6214:53c4:b0:6cb:832e:9267 with SMTP id 6a1803df08f44-6d35c0a3a96mr242442826d6.7.1730732428286; Mon, 04 Nov 2024 07:00:28 -0800 (PST) Received: from ?IPV6:2607:fea8:51de:a700::c2e1? ([2607:fea8:51de:a700::c2e1]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353f9e1d7sm48565626d6.24.2024.11.04.07.00.27 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Nov 2024 07:00:27 -0800 (PST) Message-ID: <26efeb4d-94df-4cd6-9b8e-318d06136b5e@redhat.com> Date: Mon, 4 Nov 2024 10:00:26 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches From: Andrew MacLeod Subject: [COMMITTED] PR tree-optimization/117398 - Don't call invert on VARYING. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org The invert() range operation is not supported on values of either VARYING or UNDEFINED.  Primarily this is because UNDEFINED has no type, which makes it impossible to perform invert() twice on a value, and produce that same value.  There were also times when it wasn't precisely clear what the client expects when UNDEFINED or VARYING is inverted.. so it is handled at the caller point. When processing switches, whenever we find the ranges for a particular label, we invert that range, and intersect that inversion with the current "default:" ranges to determine the default case.   In this testcase, one label has all possible values, so the label was producing VARYING.  inverting that value was causing a trap. This patch simple checks for VARYING and sets the default ranges to UNDEFINED in this case. Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Backports to GCC12 - 14 forthcoming. Andrew From 766075c47db5cc9d04463bfb2219b593bb4263ee Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Sat, 2 Nov 2024 10:26:24 -0400 Subject: [PATCH] Don't call invert on VARYING. When all cases go to one label and resul in a VARYING value, we can't invert that value to remove all values from the default case. Simply check for this case and set the default to UNDEFINED. PR tree-optimization/117398 gcc/ * gimple-range-edge.cc (gimple_outgoing_range::calc_switch_ranges): Check for VARYING and don't call invert () on it. gcc/testsuite/ * gcc.dg/pr117398.c: New. --- gcc/gimple-range-edge.cc | 10 ++++++++-- gcc/testsuite/gcc.dg/pr117398.c | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr117398.c diff --git a/gcc/gimple-range-edge.cc b/gcc/gimple-range-edge.cc index e3a197a2293..d2387289ad2 100644 --- a/gcc/gimple-range-edge.cc +++ b/gcc/gimple-range-edge.cc @@ -159,8 +159,14 @@ gimple_outgoing_range::calc_switch_ranges (gswitch *sw) // Remove the case range from the default case. int_range_max def_range (type, low, high); range_cast (def_range, type); - def_range.invert (); - default_range.intersect (def_range); + // If all possible values are taken, set default_range to UNDEFINED. + if (def_range.varying_p ()) + default_range.set_undefined (); + else + { + def_range.invert (); + default_range.intersect (def_range); + } // Create/union this case with anything on else on the edge. int_range_max case_range (type, low, high); diff --git a/gcc/testsuite/gcc.dg/pr117398.c b/gcc/testsuite/gcc.dg/pr117398.c new file mode 100644 index 00000000000..c43f2a3ed6b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr117398.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int a; +void c(void); +int d(_Bool b) { + switch (b+0) { + case 0: + break; + case 1: + break; + default: + c(); + } + if (b) + return a; +} -- 2.45.0