From patchwork Thu Mar 7 09:16:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 1909149 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=BKfzbxIm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4Tr3bd2gDZz1yX4 for ; Thu, 7 Mar 2024 20:17:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C6A73857BA7 for ; Thu, 7 Mar 2024 09:17:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id A75EE3858D35 for ; Thu, 7 Mar 2024 09:16:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A75EE3858D35 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 A75EE3858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::234 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709803015; cv=none; b=Y1fASr+4Ua2Es7qb4bqlB/jbii/ReP6JKGIqcmJDrNOFmlWReSyvX4ydC1fBUdZlvM8VhXuY+RIMMxeyO9ILqbNV1yK9lH/Dv8fWEuOb8DAHsOLa6S21lvo8q3l2tAA0cIZ5NLp3iFEbsYv+ctu6AiDNpIstiJ+OqT8/L1pxlgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709803015; c=relaxed/simple; bh=lKDVnh13C7qMfZmniYS3+CdvrCHTA1JLLWyMqxgt9t8=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=abWSdSM4ZMgj6aBZg4gOSKagcO+FuKmgT6R4NCAa4sboGhmHUibANVKA4UV8SyfvpdESxdGYnbuJNr2AwGAadAea25B5IAx90xMuu32DY4ivVtZTMoWpIEFb/wgM4oWCehG4O7jzPXfJKcWcENxwCXDU4vZhGbPKmLrlQskvyc4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2d288bac3caso7791751fa.2 for ; Thu, 07 Mar 2024 01:16:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709803012; x=1710407812; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=P51Mrpiziij1wR/9+fgJ4AuAAdKlaBnuu4m0ds5rWYo=; b=BKfzbxImmP6ZA9+0XhA8kdvYu+mQgAPItXJUmJjaAIspAUiUBYh2I2PWAw/UVzfRf3 5CbzP/OQBKBQkRQa80zGdIcc3j5wdYtJfCfGdgRVytk7HSYyn0tYwdUqXuYTX9bPKt/w x8Abp4SKvtAkKl/3BRqtofmcqM71EGOFPIC5pRWARL4Yq0sXJr7ZhMnez8a8HIwqGu8q jZbWol8WPJ4yNdCzRjvdE+XqJQ/tos18zror02NyWHeGtINg0vtzwrlUvgATLTCh5MgA Vgg6fM+j3FFtK3PDFWREyitkzk6PNTRMvLbYSCR5ocQyhucHWLfHgtEqKi56lzbizW2w EJgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709803012; x=1710407812; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=P51Mrpiziij1wR/9+fgJ4AuAAdKlaBnuu4m0ds5rWYo=; b=XPLaUgDuT9AX9xWxq9DIOls9L+Igb/lLwjMa4+eJ3UhukqDJsq6i4nqizJmQw2HEZr 593oQG1xakrrutMKOuMKhgB88Te8G+nzwnAxij7lHwuqOMXmteG1bTS2k+7JJ8OT30TA 9iasD8V7zukYpGhtAStlkih2iJZzdDCh5p6gh/+z3I+Rug1A7UBCXWWVRUS2CFsHbmG0 cfdwoqWXfoycfOLX/oeQx5lRb6bjsopXK1GnBBbwm1SDv4nWAtCgfb5dDCmyeatcRaKp zGkvJcnPpDaNOF+7OOS6dDO9SpJmhlB0xIMyiEe1a1gP+cr6qiRhAfHoo33JV9pbogFT PHsQ== X-Gm-Message-State: AOJu0Yyp+aPBsQgHgMReBuuxCRyoSllL10zzBrN4z3A7khtpm+vCcAdJ BzjtnKxAxSKRSu4dHdivsVl0aW9M4vInBxLtZdhJdu8Nt3XL8ZhuGFXj4tiv1o30VTFsROHs+16 d0NZc8ejL4GRZ8sWwQ/EM1vezE/xk3IWsGV20Qg== X-Google-Smtp-Source: AGHT+IF1T6cOgdyU2Gj/hecxYoAWkyAoxC72GDTHkqDeqHCVcyiOWcd6T5TmZcQ/NHhBFk9ZgGIDmt5lW+TDOqPx7Is= X-Received: by 2002:a05:651c:150b:b0:2d3:b37b:6a50 with SMTP id e11-20020a05651c150b00b002d3b37b6a50mr1112396ljf.19.1709803011329; Thu, 07 Mar 2024 01:16:51 -0800 (PST) MIME-Version: 1.0 From: Uros Bizjak Date: Thu, 7 Mar 2024 10:16:39 +0100 Message-ID: Subject: [PATCH v2] combine: Fix ICE in try_combine on pr112494.c [PR112560] To: "gcc-patches@gcc.gnu.org" Cc: Jeff Law , Richard Biener 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 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. 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? Uros. diff --git a/gcc/combine.cc b/gcc/combine.cc index a4479f8d836..6dac9ffca85 100644 --- a/gcc/combine.cc +++ b/gcc/combine.cc @@ -3184,11 +3184,21 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0, && (cc_use_loc = find_single_use (SET_DEST (newpat), i3, &cc_use_insn))) { - compare_code = orig_compare_code = GET_CODE (*cc_use_loc); - if (is_a (GET_MODE (i2dest), &mode)) - compare_code = simplify_compare_const (compare_code, mode, - &op0, &op1); - target_canonicalize_comparison (&compare_code, &op0, &op1, 1); + if (COMPARISON_P (*cc_use_loc)) + { + compare_code = orig_compare_code = GET_CODE (*cc_use_loc); + if (is_a (GET_MODE (i2dest), &mode)) + compare_code = simplify_compare_const (compare_code, mode, + &op0, &op1); + target_canonicalize_comparison (&compare_code, &op0, &op1, 1); + } + else + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "CC register not used in comparison.\n"); + undo_all (); + return 0; + } } /* Do the rest only if op1 is const0_rtx, which may be the @@ -3221,9 +3231,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) + if (compare_code != orig_compare_code) { /* Replace cc_use_loc with entire new RTX. */ SUBST (*cc_use_loc,