From patchwork Sun Nov 19 05:36:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 166676 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1504891vqn; Sat, 18 Nov 2023 21:36:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzGwa4qSrHWSoj9a2hZ4n0DPxy0f6Ou/lnIDIqTRPsEb296OR3ahajspadFBnpCtTIp0TA X-Received: by 2002:ac8:4e81:0:b0:41e:2d41:7de2 with SMTP id 1-20020ac84e81000000b0041e2d417de2mr6226969qtp.24.1700372198405; Sat, 18 Nov 2023 21:36:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700372198; cv=pass; d=google.com; s=arc-20160816; b=apnOG8cuacar21JEPVOEJODXRyf01ID4rK966d2vf765NpBbstJtNtzAqJPWqg3iz8 DZjK6yGH3nLWyU5LmUe0YNMvF4UHdWYUvcTKRzfhtodc4P57F8mCLXxRkiUENAo12ubI AK4yxm+3qpU6H21Wl4FKWSh8MJCYbPx5J86jF05zgsL4XBo+410b0NpmmavHn0VVrrEn bK8Sx2cGS5xO+od/mW+SGkCw0Tw0sB0WnecP5Gbijp+YWGlFdz829NhnWGg2PlUh0lwW ATFz0vv4t8nxyp2w7Htk9VnPTGpmRSCLmo7W1jZffjtdpx9i5jaKRpLumCJg4sLisXy2 m+lA== 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:mime-version:user-agent :references:message-id:in-reply-to:subject:cc:to:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=SQCJUnl3JVJg6CUD/dwVsRYRkaoWvF+XHNpqJEfPBWE=; fh=dp1z4I3tVhinwswv7IAFxpunWK+Ws/fGQfmox9vHv3I=; b=j/8YkvmHlf56/6ePlvL5OV7DPv/ObQeQB0A3P75u7t80SiCM0BkN8X8ewAcS2LjQ01 zHByaR3A9b2Ns4lnoVvFxi/Gxngy5F7FrFJj5UZvnqFGZ/6HV8e2DJQP6MZJkPd9n3Cn pfjQbz8F3P+2Nb4LI5vLjN5FIvZWg5aq1ypgoAySlQcUUMdwJ7zvVHb9wzANlK243GL5 sxacINpVgHOvPI4T8UIubXhrIYp/BxwM5CEjaOO20hr1u505akq+b8L8rF+8/+1eQqc3 kfIumpEKDZN0xhnJ/0EgtwDg5D8QP2u+kuq8wTfzaMmBJkFNcGAqnDSXSXe9+vkPLW/e 1L3w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=KuSApKf0; 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" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j13-20020a05622a038d00b0040b4cb9b6f9si5164627qtx.102.2023.11.18.21.36.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 21:36:38 -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=@embecosm.com header.s=google header.b=KuSApKf0; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9403B3858037 for ; Sun, 19 Nov 2023 05:36:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id 694B43857C4A for ; Sun, 19 Nov 2023 05:36:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 694B43857C4A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 694B43857C4A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::531 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700372168; cv=none; b=IMpIfKfg3HkHiunVF8lrOPHbzruTAduCAPvGQXN1s6QTPdhXcHolcyxiVU5HWbY3LA6gfK8kDwcPeuGEL8NTj+8VPxe3nAbM9RQCbWZzIthlRRbZqucsqjdeLClWBKUseSqujhORM4M5zjD+qcDSEecN2KQFxx1l5MutNemya+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700372168; c=relaxed/simple; bh=2jNmEiIBJ2MoV2AR7EWAifyEkhA/M9aOZMAKSxNJXXc=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=VTmS1q/5H0J7tsiaAar3/yN/iKB+WQY9/e/zsvJI3/1/mbEu/cTp69pICWoByEN5o4Fz0rzUbxD6y8V+UTvxY1he6+uH7I02cBtVEmQeV3hDpdQvUZqgj32jnqJPEgfsy3X+bwUIOzjcpKs+pbM+MiKmQ7R7B9PL/fMWXB9q+5I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-53e2308198eso4761385a12.1 for ; Sat, 18 Nov 2023 21:36:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1700372166; x=1700976966; darn=gcc.gnu.org; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=SQCJUnl3JVJg6CUD/dwVsRYRkaoWvF+XHNpqJEfPBWE=; b=KuSApKf0VTzvAk8foPMBzwhJsaBmSKtEq0QABMPBjB9OYFMD0pC9S3hlwPyL41oMDC Ay8rM8Htw9rGwnEDtqrJlwkdvx+MhIeeY4iF3X9dL+XR18Hu9OZjpqGG2WXiQZUXIheX zAYjqNyltFUenCccoY14YFNriZG4aDwYXeAH0wRp5084Q6sGp6WQtv6EVgPPPCZWwXRY YRuhIVX9bHTw46ZKohedVJOg9BV1Xm0pvhvsE8xnsIsb1GZYwQuVtnmTXAsAPlL69LuO mplNUe5R6dMyszLvSZE4eX476vNPoah+uivPE56LeF+O86d8dFqXHzIuLN6lSl8UYdw0 bbYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700372166; x=1700976966; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=SQCJUnl3JVJg6CUD/dwVsRYRkaoWvF+XHNpqJEfPBWE=; b=bYMWml7Ll69fnF1B4ilay3qrxFJ1dwK56HQgKt3/3R3+MIgBtZxY5XMkiQoAgL4r6N +XNGTkXXXcI1UYbwUGIbl1A+QjxF7VAQcYOLsiyr/S8fmonJbCRxnIpNwaRojmVjDRzI a93tu625mlKXVKFPVW/A44sxta0lpdmResUhfZYnFnlA1rfM8Q9TC2cG1XT5Rvd/RWW4 t/FMZXhCFFsiYvs0F0JJozwLi4cXghTc9rvMU8UMeCINhOBojshJbsGivBP1e7VUCp0O FYs6nBOmTX8uGXFqHPkrerqnY88IeM830ZdtCs24kQI5JneW5AJHQtgRvgIEW4G3RrY6 QCKg== X-Gm-Message-State: AOJu0Yx+mouVL9JfxCkq9L0OIIJ8fu2iKZ8Qjv0EQBYE/w0OwwfwawuD xr5ZC9pDfKn3awqM0wGpKm09MddyXfGZvYI7IOEGaA== X-Received: by 2002:a05:6402:14d6:b0:542:f28e:2947 with SMTP id f22-20020a05640214d600b00542f28e2947mr3041719edx.26.1700372166187; Sat, 18 Nov 2023 21:36:06 -0800 (PST) Received: from [192.168.219.3] ([78.8.192.131]) by smtp.gmail.com with ESMTPSA id v4-20020aa7d644000000b0053e3d8f1d9fsm2331619edr.67.2023.11.18.21.36.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Nov 2023 21:36:05 -0800 (PST) Date: Sun, 19 Nov 2023 05:36:03 +0000 (GMT) From: "Maciej W. Rozycki" To: gcc-patches@gcc.gnu.org cc: Andrew Waterman , Jim Wilson , Kito Cheng , Palmer Dabbelt Subject: [PATCH 04/44] RISC-V: Sanitise NEED_EQ_NE_P case with `riscv_emit_int_compare' In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK autolearn=no 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: 1782969478142015561 X-GMAIL-MSGID: 1782969478142015561 For the NEED_EQ_NE_P `riscv_emit_int_compare' is documented to only emit EQ or NE comparisons against zero, however it does not catch incorrect use where a non-equality comparison has been requested and falls through to the general case then. Add a safety guard to catch such a case then. Arguably the NEED_EQ_NE_P case would best be moved into a function of its own, but let's leave it for a separate cleanup. gcc/ * config/riscv/riscv.cc (riscv_emit_int_compare): Bail out if NEED_EQ_NE_P but the comparison is neither EQ nor NE. --- FWIW the structure of code here clearly shows the NEED_EQ_NE_P case has been bolted on as an afterthought rather than how this piece would look if written from scratch right away. Let's defer any further cleanups at this stage of the development cycle though. --- gcc/config/riscv/riscv.cc | 1 + 1 file changed, 1 insertion(+) gcc-riscv-emit-int-compare-need-eq-ne.diff Index: gcc/gcc/config/riscv/riscv.cc =================================================================== --- gcc.orig/gcc/config/riscv/riscv.cc +++ gcc/gcc/config/riscv/riscv.cc @@ -3779,6 +3779,7 @@ riscv_emit_int_compare (enum rtx_code *c *op1 = const0_rtx; return; } + gcc_unreachable (); } if (splittable_const_int_operand (*op1, VOIDmode))