From patchwork Tue Mar 12 17:53:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 1911306 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=BFeFYOXY; 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 4TvLqn1cs9z1yWn for ; Wed, 13 Mar 2024 04:54:13 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1EEA23858036 for ; Tue, 12 Mar 2024 17:54:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by sourceware.org (Postfix) with ESMTPS id D1806385840C for ; Tue, 12 Mar 2024 17:53:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D1806385840C 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 D1806385840C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::231 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710266032; cv=none; b=flxnooAnqZk8BItiNhIe6/+8l9McTOcud9COIFkHDRlLRSXEm7N04kpO+SlcIYzFT0IinL9KQifFFM4h9eBvMwXTtbYiv6CHaJ3saZsC3/rBkVMlCH5xusqj6jjaMyeyqYgPzSu53kDnocw/z7cjH0i9gyxf4Escp5EAIRGmtyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710266032; c=relaxed/simple; bh=jZmBVlhAz5ABnqxv1ydeXBn/HwjnB2Znpy/tlY0dD8A=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=SZ7wLgOkKiCNjtnQv/XbMqmAKUxwZcDZRXBuj9Dkiw5A1Jx2gh3i+ddzlwtT0wO13H2smD4Qho7A5LGzaqcz8sLFGRdjTw+6UNtyiWKWPBz8E4nEATqrpbopqOpK1bIgGxtKC8w3KUkCim5Rt98RaYk561gsgMwPr2IkRsJOCGU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2d3f962a9dfso49387441fa.1 for ; Tue, 12 Mar 2024 10:53:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710266027; x=1710870827; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=dk88N0kDbkvrh3ciSOIujBo8GD8x2j1S7XRu5KWx+gI=; b=BFeFYOXYhZc3vtFv7NNNDTD+ytRjaL4r7mIHVLnmY1Nc/WLRShSBAC5B7WbNHWO8vn 0QwzDIWbRe4sc2eFczRCb1v4o+sgsS6FihCUEP0f6fplikknfXsNtWW0ZVczCGWM5+9a jLuf73qTclhvBvYOkkqx8yNhWWUAqI6SLMj5c6LYCntiboa5q5Nn5EIvLviDtrDbYgea VSNRYoNsmvFiTNCU6C5PBCnkErGecq8/LjyOYcbmWp9OVEuGc7PWUnvIZmuF72ZFgjqg IcyS9z24LZBf1QMhLaznFhEC6CxUrscYZbJLvPrqncBwnP8ovwizuQH3G13dHgqVKeXO kXVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710266027; x=1710870827; h=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=dk88N0kDbkvrh3ciSOIujBo8GD8x2j1S7XRu5KWx+gI=; b=XQKvBleJuWvcGjKx2mWWdKq6ztd2bnf9cQ5rIlJdpNh80QHwTIVoaBuVLcjSI7RUtr QE0oHQa6taMgCR7HYdGvOhAaHTNMkZcIIChd+KLm9A1+scFsBHvXD3XQ3aFieRTezDhX gOIyvLOnZfgKFeom6+MZPY+tl1bELsT83K0Hts8PIqvhdY7n4RcsdyULLHhJWyucGT3K GaR4kwnM3qXu1+WZjoDovTMKNth1NxH4octVY9ndv2EeWWUnWLDdaojgbJ691aPqxFQn zZUaJX5kSJSzt7tO5TGVLLxRKs0bRAeS1MvuTJevIX4I5aaPT1K4sxNMz+sP6ZB3Jfam yj1Q== X-Gm-Message-State: AOJu0YzdMWrtpBbD94WG0f4/LEUyAuxGL/eBMuSSgyFTu4toCxgUm4X0 C92TInDlDCy0c6dh2wGtAD5g2niyEwgG15/Wx+jAcZU14D7Xmm3wac1ibCqrl/0ZkuQB97G4b10 7J45yFP1pSO8g7oVlGmXImQVVg2V53XuC X-Google-Smtp-Source: AGHT+IHzF1i6ybuDIr0zcuoLw35tcgag4+3a+ys+YiJ9/SnGx/IMd36+A0gAip2uzcBTrGF7XeX7GD8e74UGKnCc3ig= X-Received: by 2002:a2e:350d:0:b0:2d4:16a5:b361 with SMTP id z13-20020a2e350d000000b002d416a5b361mr801313ljz.25.1710266027228; Tue, 12 Mar 2024 10:53:47 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Uros Bizjak Date: Tue, 12 Mar 2024 18:53:35 +0100 Message-ID: Subject: Fwd: [PATCH v3] combine: Fix ICE in try_combine on pr112494.c [PR112560] To: "gcc-patches@gcc.gnu.org" Cc: Segher Boessenkool , Richard Biener , Jeff Law X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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 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 Forgot to CC gcc-patches@ ML... sorry for the duplicate... The compiler, configured with --enable-checking=yes,rtl,extra ICEs with: 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 = 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. Replace cc_use_loc with the entire new RTX only in case cc_use_loc satisfies COMPARISON_P predicate. Otherwise scan the entire cc_use_loc RTX for CC reg to be updated with a new mode. PR rtl-optimization/112560 gcc/ChangeLog: * combine.cc (try_combine): Replace cc_use_loc with the entire new RTX only in case cc_use_loc satisfies COMPARISON_P predicate. Otherwise scan the entire cc_use_loc RTX for CC reg to be updated with a new mode. * config/i386/i386.md (@pushf2): Allow all CC modes for operand 1. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. OK for trunk? Uros. diff --git a/gcc/combine.cc b/gcc/combine.cc index a4479f8d836..92b8d98e6c1 100644 --- a/gcc/combine.cc +++ b/gcc/combine.cc @@ -3222,8 +3222,7 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0, #endif /* Cases for modifying the CC-using comparison. */ if (compare_code != orig_compare_code - /* ??? Do we need to verify the zero rtx? */ - && XEXP (*cc_use_loc, 1) == const0_rtx) + && COMPARISON_P (*cc_use_loc)) { /* Replace cc_use_loc with entire new RTX. */ SUBST (*cc_use_loc, @@ -3233,8 +3232,19 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0, } else if (compare_mode != orig_compare_mode) { + subrtx_ptr_iterator::array_type array; + /* Just replace the CC reg with a new mode. */ - SUBST (XEXP (*cc_use_loc, 0), newpat_dest); + FOR_EACH_SUBRTX_PTR (iter, array, cc_use_loc, NONCONST) + { + rtx *loc = *iter; + if (REG_P (*loc) + && REGNO (*loc) == REGNO (newpat_dest)) + { + SUBST (*loc, newpat_dest); + iter.skip_subrtxes (); + } + } undobuf.other_insn = cc_use_insn; } } diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index df97a2d6270..9dc33fd239a 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -2213,9 +2213,9 @@ (define_insn "*pop1_epilogue" (define_insn "@pushfl2" [(set (match_operand:W 0 "push_operand" "=<") - (unspec:W [(match_operand:CC 1 "flags_reg_operand")] + (unspec:W [(match_operand 1 "flags_reg_operand")] UNSPEC_PUSHFL))] - "" + "GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_CC" "pushf{}" [(set_attr "type" "push") (set_attr "mode" "")])