From patchwork Tue Nov 14 15:33:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1863719 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=X3TsXLyD; 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 4SV9MD0M9wz1yRX for ; Wed, 15 Nov 2023 02:34:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 76B913858413 for ; Tue, 14 Nov 2023 15:34:10 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 64AF83858C78 for ; Tue, 14 Nov 2023 15:33:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 64AF83858C78 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 64AF83858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699976039; cv=none; b=gjw/SQxjoOT8eqaEolUNJhbQB6Xn0Fp8Fx0oC3wUZtv0NV+y4gI6Ww7pB0t4sdPp65ow4nu8lWF0Z/bD+9F45mNpJC1Nv5xvOcb9glU67Zq8Y9Vr/YgoOA0kNj5yiA+vSkhK1LrO2uFbqG7HvyUCynBSvGR9UeC8/9inbqDjtyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699976039; c=relaxed/simple; bh=Z/VS1AiAbgR6jWmvhWbo/zuhfHEDW0x9JfVni1TEi84=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=tjkXEy4yLHQSmZq4u7e0sXX6dwRCdXUXAovH46FT/93+fQkrqiEJKApUiXbYd2UKbIY48C/Peq7sa2O8mI9sgJkfE8IY/o33cwvNAIiiLy5Rdw4YAD9Js7NnSqhoZeTu403pKPsf9XgVhHrwVXj5vgdpAPm/gp9b20WSHJgv4Q4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699976038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=/MXSkdUkwW83q1wBIQRYTcbNo/hI/opQDHcq3IwvbcM=; b=X3TsXLyDvWwz6MKtTZGUKbGjWofR4KmJugmNHOK4kJXfWc8nW6FJ8rCky6luaeDYFE/coz MucwOqc52oObjGgZ5EKi4MLqiMArgRSkJHfErGGyuaZ7PnBJ+o5mtpSEBDNI8b2xb7Rgog KYAN0o6TLXMfmlqs8Egk+GE02Gi+1sY= Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-wxvUTmf9MnmY32F6X9FzYw-1; Tue, 14 Nov 2023 10:33:54 -0500 X-MC-Unique: wxvUTmf9MnmY32F6X9FzYw-1 Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-5a839b31a0dso120100487b3.0 for ; Tue, 14 Nov 2023 07:33:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699976029; x=1700580829; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1MZ60x/YOvqOWSos8vIkKtOxd5sPcs7K92Uuin/+wvc=; b=gnTQrW5JLpinNi2iNnqF9jtpaBIG2Z6A8uvqp+T6PJTyDQ+j+YQyR8wbFmMltMQmTL g9mmkuXrc/w2GygyVL2AGbInxGd/FCuo/hgF3fQyEKHXk2mhKJcI3I09hcy9Mr49iTOj GkVX6M2r/+vIymiRo+8HURM2pgvi3azCZZcqpcZFDFAyZM0OWN6csijNtPl4LnDm6fTP w2Vz1esl2brNwCvDH5NgAH5GVTfSga+m9HJdQf5jfcColyCQaiumjqc41q+pQiW+/czP MCF5bhfVHfPfoRhQQZksHKQldkDD/Sril46GAGI8uJzBPKwjZrQXA//whkJ/yb+aI8xP F1rQ== X-Gm-Message-State: AOJu0Ywnq/gjG71I1SWftLGiyBNMF8zwMJDznp1ysFXt/ZaeiXEDzcEx FAFob/J1yFqHQ8+g1b60kBs+Sz/EallagYGwBWAEu8bNn6Uhcqkt4GPbB3TCte+YLAvWddEd7g2 QjCHxtPTMDsqWUUtseWLWKX4TLJTS6/62XJY2YcIUB7JEHpDPW+STp1wQLjR61z6j29r0YcL9ut UhoA== X-Received: by 2002:a25:2905:0:b0:da0:88a1:1e64 with SMTP id p5-20020a252905000000b00da088a11e64mr9377082ybp.40.1699976028855; Tue, 14 Nov 2023 07:33:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHKjbcItPDGuiH+TYp0jb6jo+duOgjVtx04E93TCe253krS7MejX0we82kK3QjC+t13IyP71A== X-Received: by 2002:a25:2905:0:b0:da0:88a1:1e64 with SMTP id p5-20020a252905000000b00da088a11e64mr9377062ybp.40.1699976028519; Tue, 14 Nov 2023 07:33:48 -0800 (PST) Received: from ?IPV6:2607:fea8:51dd:2b00::18c7? ([2607:fea8:51dd:2b00::18c7]) by smtp.gmail.com with ESMTPSA id i15-20020a056214030f00b0066d32666a20sm2985711qvu.71.2023.11.14.07.33.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Nov 2023 07:33:47 -0800 (PST) Message-ID: <755c6708-2200-4a22-a065-45b721bf692a@redhat.com> Date: Tue, 14 Nov 2023 10:33:46 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED] PR tree-optimization/112509 - Use case label type to create case range. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.5 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_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.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 We should create a range from the case labels directly, and then cast it to the type we care about rather than trying to convert it to the switch index type and then the type we care about. Bootstraps on x86_64-pc-linux-gnu  with no regressions.   Pushed. Andrew From 4553a0496458a712dfd2f04b9803b611fdc777cc Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 13 Nov 2023 09:58:10 -0500 Subject: [PATCH] Use case label type to create case range. Create a range from the label type, and cast it to the required type. PR tree-optimization/112509 gcc/ * tree-vrp.cc (find_case_label_range): Create range from case labels. gcc/testsuite/ * gcc.dg/pr112509.c: New. --- gcc/testsuite/gcc.dg/pr112509.c | 22 ++++++++++++++++++++++ gcc/tree-vrp.cc | 6 +----- 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr112509.c diff --git a/gcc/testsuite/gcc.dg/pr112509.c b/gcc/testsuite/gcc.dg/pr112509.c new file mode 100644 index 00000000000..b733780bdc7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr112509.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-vrp -fno-tree-fre -fno-tree-forwprop" } */ + +struct S { + unsigned j : 3; +}; +int k, l, m_1 = {0}; +void f(int l, struct S x) { + unsigned int k_1; + while (m_1 % 8) switch (x.j) { + case 1: + case 3: + case 4: + case 6: + case 2: + case 5: l = m_1; + case 7: + case 0: k_1 = 0; + default: break; + } +} +void foo(struct S x) { f(l, x); } diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc index 19d8f995d70..917fa873714 100644 --- a/gcc/tree-vrp.cc +++ b/gcc/tree-vrp.cc @@ -886,8 +886,6 @@ find_case_label_range (gswitch *switch_stmt, const irange *range_of_op) size_t i, j; tree op = gimple_switch_index (switch_stmt); tree type = TREE_TYPE (op); - unsigned prec = TYPE_PRECISION (type); - signop sign = TYPE_SIGN (type); tree tmin = wide_int_to_tree (type, range_of_op->lower_bound ()); tree tmax = wide_int_to_tree (type, range_of_op->upper_bound ()); find_case_label_range (switch_stmt, tmin, tmax, &i, &j); @@ -900,9 +898,7 @@ find_case_label_range (gswitch *switch_stmt, const irange *range_of_op) = CASE_HIGH (label) ? CASE_HIGH (label) : CASE_LOW (label); wide_int wlow = wi::to_wide (CASE_LOW (label)); wide_int whigh = wi::to_wide (case_high); - int_range_max label_range (type, - wide_int::from (wlow, prec, sign), - wide_int::from (whigh, prec, sign)); + int_range_max label_range (TREE_TYPE (case_high), wlow, whigh); if (!types_compatible_p (label_range.type (), range_of_op->type ())) range_cast (label_range, range_of_op->type ()); label_range.intersect (*range_of_op); -- 2.41.0