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: 164998 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a59:b0:164:83eb:24d7 with SMTP id 25csp2004830rwb; Tue, 14 Nov 2023 07:34:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlBoauRIAixIgN8rgrbNP+D13fZnWcBwBEZwknmlwH98GMGXIHV22ZiQC5nkn0uXf00cGE X-Received: by 2002:a05:620a:2907:b0:772:6364:1409 with SMTP id m7-20020a05620a290700b0077263641409mr2944949qkp.10.1699976062633; Tue, 14 Nov 2023 07:34:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699976062; cv=pass; d=google.com; s=arc-20160816; b=l7JP6CS0VVUDwP+oZhEL4ehKPJQOvTiJPjM8XT08zLNz2hdc18oeZK6nAlYCMC1Wg6 c0oqeC/nIy2SopR8Ag1T7W8r/Qg0AWA2FFK/HJahluF73lTL5SCCB4Jd/IfKhcZftxDh JWXZfA+HgDHA5pnsLH/jTIeNpXjEZxkJGjg1BaEJ7uXKXsin8G8AZIOhzE1/lu2Zbdca zaIvObkFuUG8JTPKCwuWj8SiuAhdCaXAtXNJknhfbl+8wjNQ5/6GJTT/DQURrx44yHca Z5gMUsLV/IGxJ/YSvKDuISg0VcRbDH4+0P6o6iKLA3NAHEhy/zlzLK39sslk2afFikvE qTQQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:subject:from :cc:to:user-agent:mime-version:date:message-id:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=/MXSkdUkwW83q1wBIQRYTcbNo/hI/opQDHcq3IwvbcM=; fh=ZE6EPE2PZ3ED3Eq5R4AB8kSxxMSuW2qQfXnHfqWWl4c=; b=lb7rbsEDIkeAsE/PyAwSIlRNkt+D4h6lXzTKiAm/vRa/qWsGeDlEZQPcd580DdD3wO FLQTA2jwBqYwJtkYoByloa0M6xrvepPrq6ybxXBzAS81gK2yhGYLiSF1zZLi/xZeHUdv JMl9R9xhL9a+8pCynXiQ9k0rmGy20bvDuGN+fP1CngD0Z6TJI2caKN41q0/8JV9AtedM K0Zr3KILLvuO2hPk7pZN/exDwFXZGieHyHED6tsMM74xIZ7mDhIiASv9jwfvyDX/X/Sh 5w0ShGuVxSOaePTrYUA08kXgetF/DYGypEI3FQRaOYhlqwEVlBqyTzqjBH9tZ9CL6vYc CQug== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X3TsXLyD; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id o10-20020a05620a2a0a00b0077893a5a7fdsi7557219qkp.740.2023.11.14.07.34.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 07:34:22 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X3TsXLyD; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5F3D53858425 for ; Tue, 14 Nov 2023 15:34:22 +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-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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782554099713220657 X-GMAIL-MSGID: 1782554099713220657 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