From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id 37B5F3858D35 for ; Thu, 7 Mar 2024 10:11:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37B5F3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 37B5F3858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::232 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709806311; cv=none; b=lx6VzKeAOauYLU6ONDZ9AW1bpcAZxWAATeCIWCX5S6zq8x5WXX1PnqLbiE917XQzSLYSitljuzHHGaYQwmLnRGP0C4hzZQmEdyI9jUhOPFCkj/pHCu/IaJ3W7qQY4LELeJ6O9OK3Hg8ye6ioo/6mKQxjMKOIF47WRROrHZq4xGo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709806311; c=relaxed/simple; bh=H5Y8dDYgFuHe0eFLj3H48rmtqxoSpR/sFRiAdjf4+hA=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=jOfPQfljERPo3vLyqwwOwACPWfHF6SpzMSI38LGd8W0xBTto8cOe2oRXGacE3FxjH6g99+TIssgJvJsxIZ0ZKXvLWlYsLreSLIrDv8v1GjJ8vLxmVxKx1VgUOPD8LHaaHUqiu2MeDbJyMiyXs6pY2g8QPCGwRtL+1PCCyBuCYoM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2d26227d508so7263031fa.2 for ; Thu, 07 Mar 2024 02:11:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709806308; x=1710411108; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pIEqbFz7yAkrHEtzwcCt+yY/fSVfhRB+el7y4NxKgdM=; b=XwbnXGvX6kQcKhjNabGDOPeW9EzQnOIr04nNykw9ZIfCEn1WRYqDXAA480HQEr8/pO oU27StCRLXJYZiARv2weINWas9LgDQALQGwmF1yvNYB+7mu8txdP5Z3AEZ2lOQu8q1wo NPQtwsJpggVd6dmE8MpT+MrEDfpX5X8VyGL0IYsaTh1A2nnQEvpkaVq/gih97Ju6oNA3 YXMVVhUR6vswEcrsrDm0azmf32r0LunhjNLvPuwdjFzhSfQE7AYRRPR7H8RWBDrT33NY +LqNWq8R1izaWpQqMFcfeS7BDjS5AUKSCe01d4cniMt4g/Rzt1o5gNd33z92Z7EU5dWr EDAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806308; x=1710411108; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pIEqbFz7yAkrHEtzwcCt+yY/fSVfhRB+el7y4NxKgdM=; b=tVMzxnTTI0xwk4jFxTHbx15FcwqdUueS9Vhr72fAomFKrVTiBwyTzN9Yfeo7ERhWaF 2iAl4lP/szRLbwhK7FfTQznKHYt+P2wRNMAbKlupx0+6gYcWhwpxqSukZw1BZehZ8APo 9knp/Y/5WiOOIwnVPeW+iCklQCf9fSh4qf6vAozFOg0W6bJOR2fEJuvj1eT3XUsDLTzu WS8Qm0jxNqhgJ//cbj+TFWlCOJo7BmH+OBqiOuCNW+zKt1ZTRFtkBv6elnYmGQ+maEiB krkbroUlFTGM4BS4ddqXJ1PTcROn6csnmXgog4vBpDedo7n0WcwH/J6bZQSda0ZXoh7p 19lg== X-Gm-Message-State: AOJu0YxHYhGXb1dwbhFOKwucAyez5aRZun8wx1k0OLfR90n+jFcPYkgp lEifpn/Xr7ay0LmTbA+EQUEcS53fX9jl1MTlX1hisdsROjAVFzJMdSGvAdNB+SNh00c5qqGq/Qf 6PzGyRFATIbzbqEJ6Tax3XpYzn7M= X-Google-Smtp-Source: AGHT+IG9OCT8T+x7HgKs1UchzTT4BrBREr5d1aBmbUFAE2XFKYp8TtTrZJ1hayHoKsZxVdd+wLxcoS05BXoOwtzE5r0= X-Received: by 2002:a2e:b90a:0:b0:2d2:7702:cb74 with SMTP id b10-20020a2eb90a000000b002d27702cb74mr954043ljb.20.1709806307354; Thu, 07 Mar 2024 02:11:47 -0800 (PST) MIME-Version: 1.0 References: <2737spr1-459p-3oon-n852-qn034s55p66r@fhfr.qr> In-Reply-To: <2737spr1-459p-3oon-n852-qn034s55p66r@fhfr.qr> From: Uros Bizjak Date: Thu, 7 Mar 2024 11:11:35 +0100 Message-ID: Subject: Re: [PATCH v2] combine: Fix ICE in try_combine on pr112494.c [PR112560] To: Richard Biener Cc: "gcc-patches@gcc.gnu.org" , Jeff Law , segher@kernel.crashing.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, Mar 7, 2024 at 10:56=E2=80=AFAM Richard Biener = wrote: > > On Thu, 7 Mar 2024, Uros Bizjak wrote: > > > The compiler, configured with --enable-checking=3Dyes,rtl,extra ICEs wi= th: > > > > internal compiler error: RTL check: expected elt 0 type 'e' or 'u', > > have 'E' (rtx unspec) in try_combine, at combine.cc:3237 > > > > This is > > > > 3236 /* Just replace the CC reg with a new mode. */ > > 3237 SUBST (XEXP (*cc_use_loc, 0), newpat_dest); > > 3238 undobuf.other_insn =3D cc_use_insn; > > > > in combine.cc, where *cc_use_loc is > > > > (unspec:DI [ > > (reg:CC 17 flags) > > ] UNSPEC_PUSHFL) > > > > combine assumes CC must be used inside of a comparison and uses XEXP (.= .., 0) > > without checking on the RTX type of the argument. > > > > Undo the combination if *cc_use_loc is not COMPARISON_P. > > > > Also remove buggy and now redundant check for (const 0) RTX as part of > > the comparison. > > > > PR rtl-optimization/112560 > > > > gcc/ChangeLog: > > > > * combine.cc (try_combine): Reject the combination > > if *cc_use_loc is not COMPARISON_P. > > > > Bootstrapped and regression tested on x86_64-pc-linux-gnu {,-m32}. > > > > OK for trunk? > > Since you CCed me - looking at the code I wonder why we fatally fail. > The following might also fix the issue and preserve more of the > rest of the flow of the function. > > If that works I'd prefer it. But I'll defer approval to the combine > maintainer which is Segher. Your patch is basically what v1 did [1], but it was suggested (in a reply by you ;) ) that we should stop the attempt to combine if we can't handle the use. So, the v2 patch undoes the combine and records a nice message in this case. Also, please note the removal of an existing crude hack that tries to reject non-comparison uses by looking for (const_int 0) in the use RTX, which is wrong as well. [1] https://gcc.gnu.org/pipermail/gcc-patches/2023-November/638589.html Uros. > > Thanks, > Richard. > > diff --git a/gcc/combine.cc b/gcc/combine.cc > index a4479f8d836..e280cd72ec7 100644 > --- a/gcc/combine.cc > +++ b/gcc/combine.cc > @@ -3182,7 +3182,8 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn > *i1, rtx_insn *i0, > > if (undobuf.other_insn =3D=3D 0 > && (cc_use_loc =3D find_single_use (SET_DEST (newpat), i3, > - &cc_use_insn))) > + &cc_use_insn)) > + && COMPARISON_P (*cc_use_loc)) > { > compare_code =3D orig_compare_code =3D GET_CODE (*cc_use_loc); > if (is_a (GET_MODE (i2dest), &mode)) > @@ -3200,7 +3201,7 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn > *i1, rtx_insn *i0, > the above simplify_compare_const() returned a new comparison > operator. undobuf.other_insn is assigned the CC use insn > when modifying it. */ > - if (cc_use_loc) > + if (cc_use_loc && COMPARISON_P (*cc_use_loc)) > { > #ifdef SELECT_CC_MODE > machine_mode new_mode >