From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id 408A93857BBC for ; Tue, 31 May 2022 09:52:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 408A93857BBC Received: by mail-ej1-x62e.google.com with SMTP id gh17so25536778ejc.6 for ; Tue, 31 May 2022 02:52:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=uIuns4LyAl0vkXxKP9wSfSvjKW6iVm16r/d1suRpaJw=; b=YG9lNYYrkik00gYhKJCnyF5JPDVm2L7+Sc+rpvNLcLqghdV1mY9XQpBfk0eKgFItbb 0rwIiqznmttfPZsPqBo1pcf+a2WbeYeqLfHGZaKelZKt1Kr6eciyj2ZVY4XmPT/+ZK7h is6sBjxNhL5ncR9TlkAY8s99hMf4+6vAcFIFYlcz5Uonjt57HEn/AT1bXUhfjH0uUFLP sVqUxqpBb4VjdKbXcDntxsCkic0q7bsdatpTYZsk6LK51I6h+bfc6idkfGp+wX35JQWT Ja5mMyIRSIeUwMaIk0LZLgXI2MbhPjzoDMnu6F9k/wkIZxuEAPlT7djQl0VJUepNEbK3 oWvQ== X-Gm-Message-State: AOAM532vNKrBU+bELnI5wM936U9U8Kttg5pJESSWIsEVJ6vDyVhiCxGN s2DkdNU5r9uRLVQQYCDEA7fwb2knnZo= X-Google-Smtp-Source: ABdhPJyWYKHQEAeHuInPpxOgBW+/ORqP35KRZiJpCaR38iNucIB1UAQqb7vF/fI3tS2RaWRR019KUQ== X-Received: by 2002:a17:907:7e83:b0:6fe:e929:ead0 with SMTP id qb3-20020a1709077e8300b006fee929ead0mr36450073ejc.286.1653990733717; Tue, 31 May 2022 02:52:13 -0700 (PDT) Received: from smtpclient.apple ([2a02:3038:f:58f6:8556:b701:7f92:25e4]) by smtp.gmail.com with ESMTPSA id i23-20020a508717000000b0042dc6336684sm5038087edb.73.2022.05.31.02.52.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 May 2022 02:52:13 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Richard Biener Mime-Version: 1.0 (1.0) Subject: Re: [PATCH] unswitch: Fold case label lo/hi values to index type [PR105770] Date: Tue, 31 May 2022 11:52:12 +0200 Message-Id: <0BB89524-5D8B-40DA-BFEF-C92A1B4E2B5F@gmail.com> References: Cc: Richard Biener , gcc-patches@gcc.gnu.org In-Reply-To: To: Jakub Jelinek X-Mailer: iPhone Mail (19F77) X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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-List-Received-Date: Tue, 31 May 2022 09:52:17 -0000 > Am 31.05.2022 um 11:33 schrieb Jakub Jelinek via Gcc-patches : >=20 > =EF=BB=BFHi! >=20 > The following testcase ICEs because we use different types in comparison, > idx has int type, while CASE_LOW has char type. >=20 > While I believe all CASE_{LOW,HIGH} in the same switch have to use the sam= e > or compatible type, the index expression can have a promoted type as happe= ns > in this testcase. Other spots that handle switches do such foldings too. >=20 > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Ok. Richard=20 > 2022-05-31 Jakub Jelinek >=20 > PR tree-optimization/105770 > * tree-ssa-loop-unswitch.cc (find_unswitching_predicates_for_bb): Cast > CASE_LOW and CASE_HIGH to TREE_TYPE (idx) before comparisons with idx. >=20 > * gcc.dg/pr105770.c: New test. >=20 > --- gcc/tree-ssa-loop-unswitch.cc.jj 2022-05-25 11:07:29.754185772 +020= 0 > +++ gcc/tree-ssa-loop-unswitch.cc 2022-05-30 10:57:23.165131441 +0200 > @@ -494,6 +494,7 @@ find_unswitching_predicates_for_bb (basi > { > unsigned nlabels =3D gimple_switch_num_labels (stmt); > tree idx =3D gimple_switch_index (stmt); > + tree idx_type =3D TREE_TYPE (idx); > if (TREE_CODE (idx) !=3D SSA_NAME > || nlabels < 1) > return; > @@ -526,16 +527,18 @@ find_unswitching_predicates_for_bb (basi > if (CASE_HIGH (lab) !=3D NULL_TREE) > { > tree cmp1 =3D fold_build2 (GE_EXPR, boolean_type_node, idx, > - CASE_LOW (lab)); > + fold_convert (idx_type, > + CASE_LOW (lab))); > tree cmp2 =3D fold_build2 (LE_EXPR, boolean_type_node, idx, > - CASE_HIGH (lab)); > + fold_convert (idx_type, > + CASE_HIGH (lab))); > cmp =3D fold_build2 (BIT_AND_EXPR, boolean_type_node, cmp1, cmp2)= ; > lab_range.set (CASE_LOW (lab), CASE_HIGH (lab)); > } > else > { > cmp =3D fold_build2 (EQ_EXPR, boolean_type_node, idx, > - CASE_LOW (lab)); > + fold_convert (idx_type, CASE_LOW (lab))); > lab_range.set (CASE_LOW (lab)); > } >=20 > --- gcc/testsuite/gcc.dg/pr105770.c.jj 2022-05-30 11:08:30.603530499 +0= 200 > +++ gcc/testsuite/gcc.dg/pr105770.c 2022-05-30 11:07:12.066406193 +0200= > @@ -0,0 +1,19 @@ > +/* PR tree-optimization/105770 */ > +/* { dg-do compile } */ > +/* { dg-options "-O1 -funswitch-loops -fno-tree-forwprop" } */ > + > +char a; > + > +void > +foo (void) > +{ > + while (a) > + switch (a) > + { > + case ' ': > + case '\t': > + return; > + } > + > + __builtin_unreachable (); > +} >=20 > Jakub >=20