From patchwork Fri Dec 1 15:20:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 172539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1198337vqy; Fri, 1 Dec 2023 07:21:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IH06iKHP23wuWV25mzoU+tBrCR9keZaxP6Ois1PP4iNKGJQgDqpdiMDcet4jQpXlFPnAEa+ X-Received: by 2002:a05:620a:8d89:b0:77d:bdba:2270 with SMTP id rc9-20020a05620a8d8900b0077dbdba2270mr10619326qkn.55.1701444062461; Fri, 01 Dec 2023 07:21:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701444062; cv=pass; d=google.com; s=arc-20160816; b=OyeFPdIj/VrIbKMzf66+B2dp86Pd0YpsjBSN6sSRr5xj9N8pOkreXX5SGrRZECW9Gk puFtNhazUZUud3Pj0y90MpB2WCHH/zRs4/g+N5n4RIGt2MC1UggTqLheCh0TgtNEHgWw ndZMC9tEcmTYnNDOT+J6x+4jimTYafLTb52XZoSI4XSHNYMqCnCvxTWh7f8xgOZLtDJl aVXfePaknv/7wzVwlxHbs7EoA1MF53z882Aa1Ap4fj45zNQA5eFcKPC/SIRU3RHeIsYj rRrdSqmxlnDQ2IWBrFWR2C/KqHHQJdCFmapNPbSb6ahuu0lRQabLhB7KZLvuABiTVQW1 9QgQ== 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:content-transfer-encoding :subject:from:to:content-language:cc:user-agent:mime-version:date :message-id:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=bU1lI2QsvZQ9ZqIhvLWrlX9DYaUiwlZ7TvqZrYOYSOg=; fh=MP1/pUCFlWKCuVsZg/AyiqM/gAN9eNrTjtzrUP16xWo=; b=ibUnALNQ6v2ufRCu6CD+ezg44oG4caVYq+0gaB5o079eYxWuDrs9rPU6sFbVy5/eyc uybRSqDDaSG5qO7Y0cDUU2gAXz8HX96xB8gbiOkIbB76Q/aNXKtJwdClS2KqbmT3ljnk bbd3P7/GhvjJSyS1rwIgNnD2MEUWdPwc4ZpYsHGQVjk6Jxk6hSdZ9UL7sWcThD+N35ah bg8oq0UqGGA3JjkuY/9mNUpxsDU7wMTS+m4nSXOBPgihKxa+NTSyhtLB7yo7PRtQGDTS toc0H71InWb0WhYldRc9oANKJmyP62ltQrhX3bgvDsbvZjb+Q0RsiY027+jxTNSqmJby Vl2g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=BqGD3B0L; 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"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qs19-20020a05620a395300b0077d96086de9si3548957qkn.428.2023.12.01.07.21.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 07:21:02 -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=@gmail.com header.s=20230601 header.b=BqGD3B0L; 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"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E4B13853308 for ; Fri, 1 Dec 2023 15:21:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id CD247385AC3D for ; Fri, 1 Dec 2023 15:20:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD247385AC3D 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 CD247385AC3D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701444038; cv=none; b=FYIiZk+EWjaLwfwaSzl9d5O1CdzItnAPmFL6vBcjQJcFzyKuMBsJmtwcrgq8gzLjkesmOIpUKgrvEkbC3Mtjfa2LxLFj4HH5dU6KL+T1xiEsUVphLv8JJtrhW97Cgm6H6aKsQ3IMvQzgVTp4UkBe3Juxbry7lZPi+vhK6PmK4/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701444038; c=relaxed/simple; bh=J932Uv+iaMPIKXnE4PMu2FkOB1njgNWZbPeiSBu7dYI=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=gs68BZkjjrC7X6AUi+fDa1hJ2Op70QNHU3ONkV/S6rzq74nCzaTx5ItcvfB4l4TBePRBEWaVsfWRa/UqpDTxXxdORoO6KoVqCIHxnCetFUN6CQZC36WbKUJJSu/v3odt0BYlYEv+mgJJw68Un6dSXfhCtGlkEHKqYg7ckop/Wxg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2c9bbb30c34so28235491fa.1 for ; Fri, 01 Dec 2023 07:20:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701444032; x=1702048832; darn=gcc.gnu.org; h=content-transfer-encoding:subject:from:to:content-language:cc :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=bU1lI2QsvZQ9ZqIhvLWrlX9DYaUiwlZ7TvqZrYOYSOg=; b=BqGD3B0LF9C2Ml/0BNjtMU5brqJ6NqpkJaIjc0WqlaBYZDmJcZSPCQ/csUkSI+HI+j phmD0c3cXaD6UBXcUOtajq+Jz16VrwltRzp2QUf1rkukJKiNdiucodvOc7hHK5PepWL/ 2uGs8TQ5qudbQDYmm/PEA8fd3aoitVJLN29rAc3Zau7safwN/xK5veuZjdcF2mZJbzjc oFG9SGZyQzspxyVSTfqu6a/s0aro9DXX0Ld7BGe8SPyMmxu9ZGKWuZyMK+RCJrbVTyPo oXM+cRVGxX66wfGfjm5ec3wMWit0VHJkhca8fa7xPx+TGDc3iePC3wVJg+nTBDLy+LQZ e5Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701444032; x=1702048832; h=content-transfer-encoding:subject:from:to:content-language:cc :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=bU1lI2QsvZQ9ZqIhvLWrlX9DYaUiwlZ7TvqZrYOYSOg=; b=Tzl2CaRaJi4z3Coh6oQZFeVIDzNaLWVnO6PAM4m92C3rS2yulyTtX+18DmVOykBj4Y yCPVMDhGXN9/bms9yImJsmgd912xpWe3DUiDzv3Un2fGtUYYuHm390aLw/VGQulwHn70 c4cgqVVLsa9riZTTYwLwV/seQC+YHew0pPBxCXABaXexhqIcF8gdaz1iJSfp4SN0v72Q loXHqqDHtarr7qv1dOl9VvHXJe4hqob64Y8eXHknfkTb8ioQEUXoIV5qaEa6h8cgqbSW rhcGABUUls1pr9qH67ImygKlsh1rawsRupqBD/6c0OOdajdD/FMygHXVROstrqRr+k40 WOVQ== X-Gm-Message-State: AOJu0YxW/MKp/vaq4ExWhPssTve+uqE/o9xAWH+nMXNaN0i0Nxp3Yn9I Ra7JVoxBIxXAXdgLIrynapV1I5LHtAk= X-Received: by 2002:a2e:3e14:0:b0:2c9:d874:4b46 with SMTP id l20-20020a2e3e14000000b002c9d8744b46mr919842lja.54.1701444032019; Fri, 01 Dec 2023 07:20:32 -0800 (PST) Received: from [192.168.1.23] (ip-149-172-150-237.um42.pools.vodafone-ip.de. [149.172.150.237]) by smtp.gmail.com with ESMTPSA id lu5-20020a170906fac500b00a18e21b4dcasm1742012ejb.126.2023.12.01.07.20.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 01 Dec 2023 07:20:31 -0800 (PST) Message-ID: Date: Fri, 1 Dec 2023 16:20:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: rdapp.gcc@gmail.com Content-Language: en-US To: gcc-patches , palmer , Kito Cheng , jeffreyalaw , "juzhe.zhong@rivai.ai" From: Robin Dapp Subject: [PATCH] RISC-V: Fix rawmemchr implementation. X-Spam-Status: No, score=-9.1 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 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784093409006714645 X-GMAIL-MSGID: 1784093409006714645 Hi, this fixes a bug in the rawmemchr implementation by incrementing the source address by vl * element_size instead of just vl. This is normally harmless as we will just scan the same region more than once but, in combination with an older qemu version, would lead to an execution failure in SPEC2017. Regards Robin gcc/ChangeLog: * config/riscv/riscv-string.cc (expand_rawmemchr): Increment source address by vl * element_size. --- gcc/config/riscv/riscv-string.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gcc/config/riscv/riscv-string.cc b/gcc/config/riscv/riscv-string.cc index f3a4d3ddd47..594ff49fc5a 100644 --- a/gcc/config/riscv/riscv-string.cc +++ b/gcc/config/riscv/riscv-string.cc @@ -1017,6 +1017,8 @@ expand_rawmemchr (machine_mode mode, rtx dst, rtx src, rtx pat) machine_mode mask_mode = riscv_vector::get_mask_mode (vmode); rtx cnt = gen_reg_rtx (Pmode); + emit_move_insn (cnt, CONST0_RTX (Pmode)); + rtx end = gen_reg_rtx (Pmode); rtx vec = gen_reg_rtx (vmode); rtx mask = gen_reg_rtx (mask_mode); @@ -1033,6 +1035,11 @@ expand_rawmemchr (machine_mode mode, rtx dst, rtx src, rtx pat) rtx vsrc = change_address (src, vmode, src_addr); + /* Bump the pointer. */ + rtx step = gen_reg_rtx (Pmode); + emit_insn (gen_rtx_SET (step, gen_rtx_ASHIFT (Pmode, cnt, GEN_INT (shift)))); + emit_insn (gen_rtx_SET (src_addr, gen_rtx_PLUS (Pmode, src_addr, step))); + /* Emit a first-fault load. */ rtx vlops[] = {vec, vsrc}; emit_vlmax_insn (code_for_pred_fault_load (vmode), @@ -1055,16 +1062,10 @@ expand_rawmemchr (machine_mode mode, rtx dst, rtx src, rtx pat) emit_nonvlmax_insn (code_for_pred_ffs (mask_mode, Pmode), riscv_vector::CPOP_OP, vfops, cnt); - /* Bump the pointer. */ - emit_insn (gen_rtx_SET (src_addr, gen_rtx_PLUS (Pmode, src_addr, cnt))); - /* Emit the loop condition. */ rtx test = gen_rtx_LT (VOIDmode, end, const0_rtx); emit_jump_insn (gen_cbranch4 (Pmode, test, end, const0_rtx, loop)); - /* We overran by CNT, subtract it. */ - emit_insn (gen_rtx_SET (src_addr, gen_rtx_MINUS (Pmode, src_addr, cnt))); - /* We found something at SRC + END * [1,2,4,8]. */ emit_insn (gen_rtx_SET (end, gen_rtx_ASHIFT (Pmode, end, GEN_INT (shift)))); emit_insn (gen_rtx_SET (dst, gen_rtx_PLUS (Pmode, src_addr, end)));