From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sender-0.a4lg.com (mail-sender-0.a4lg.com [IPv6:2401:2500:203:30b:4000:6bfe:4757:0]) by sourceware.org (Postfix) with ESMTPS id 494EA3858C1F for ; Tue, 5 Sep 2023 02:19:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 494EA3858C1F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=irq.a4lg.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=irq.a4lg.com Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id D6252300089; Tue, 5 Sep 2023 02:19:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irq.a4lg.com; s=2017s01; t=1693880367; bh=BMh2AYBzbKpx9G0fl8pM4+wvCd1q7rjqJTMz0jLcZ5o=; h=Message-ID:Date:Mime-Version:Subject:To:References:From:Cc: In-Reply-To:Content-Type:Content-Transfer-Encoding; b=MWHTzsU1T7+k+YaH+fAL/s/XnLTYY/Bw7eZymh4N3hfjkvPODVkHSVWWsr2CaUX4M PSow7xiNW34xzgs3nnT2XevjUo/pCyTDNBpv/Aa7QJLkLGZ1vQigq22YY1AXUYSQ6P ZKZAdEQraC8oZswqs0eyqIeixH3uIduwzLKRdfQw= Message-ID: <2bc7f639-6fd9-49e6-ba30-03617598ac24@irq.a4lg.com> Date: Tue, 5 Sep 2023 11:19:26 +0900 Mime-Version: 1.0 Subject: Re: [PATCH v2] RISC-V: zicond: Fix opt2 pattern Content-Language: en-US To: Vineet Gupta , Jeff Law References: <20230901195311.761131-1-vineetg@rivosinc.com> From: Tsukasa OI Cc: GCC Patches In-Reply-To: <20230901195311.761131-1-vineetg@rivosinc.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP 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: Sorry, I want to directly reply to Jeff but I couldn't because I haven't subscribed to gcc-patches and Jeff's recent reply hasn't archived yet. Bug confirmed for me. I tried the full test with following configuration (I found another bug [ICE] as I submitted a quick fix while testing this and requires following patch set to be applied; will make a PATCH v2 though): Possibly, ICE, simulator configuration and/or dirty build tree might be the reason Jeff couldn't reproduce the bug. # ZiCond enabled # Remove "_zicond" to disable ZiCond. # ${SYSROOT} points to the prebuilt sysroot with # glibc + libgcc with -march=rv64imafdc -mabi=lp64d ${GCC_SRCDIR}/configure \ --target=riscv64-unknown-linux-gnu \ --prefix=${PREFIX} \ --with-sysroot=${SYSROOT} \ --with-system-zlib \ --disable-shared \ --enable-tls \ --enable-languages=c,c++ \ --disable-libmudflap \ --disable-libssp \ --disable-libquadmath \ --disable-libsanitizer \ --disable-nls \ --disable-bootstrap \ --disable-multilib \ --with-tune=rocket \ --with-arch=rv64imafdc_zicond \ --with-abi=lp64d \ --with-isa-spec=20191213 Then I ran "make; make check RUNTESTFLAGS='--target_board=riscv-sim'". Note that I configured DejaGnu (riscv-sim.exp) to execute tests with: "qemu-riscv64 -L ${SYSROOT} -cpu rv64,g=on,x-zicond=on" (QEMU 8.1.0 Linux user emulation). Warning: abort() on QEMU with Linux user emulation causes QEMU to abort, too (possibly making many coredumps). The diff of test failures are as follows. -: Occurs only when ZiCond is disabled +: Occurs only when ZiCond is enabled -FAIL: 30_threads/async/async.cc execution test +FAIL: gcc.c-torture/execute/pr60003.c -O1 execution test +FAIL: gcc.dg/setjmp-3.c execution test +FAIL: gcc.dg/torture/stackalign/setjmp-3.c -O1 execution test +FAIL: gcc.dg/torture/stackalign/setjmp-3.c -O1 -fpic execution test I'm not sure why 30_threads/async/async.cc succeeds after enabling the 'Zicond' extension but I am sure that setjmp-3.c failures are caused by this very bug. Smaller example (not involving setjmp / longjmp) to reproduce this bug in my environment is as follows (you *don't* have to apply my patch above, make all-gcc && make install-gcc overwriting existing RV64 GCC prefix will work): > #include > > __attribute__((noinline, noclone)) > void sample(long* a) > { > *a = 1; > } > > __attribute__((noinline, noclone)) > long foo(long x) > { > long a = 0; > sample(&a); // a is overwritten to 1. > if (a == 0) > return 0; > else > return x; // should be always taken > } > > int main(int argc, char** argv) > { > printf("%ld\n", foo(5)); // should print 5 > return 0; > } Note that we have to make sure that variables are not easily inferred by another optimization pass (that's why I needed two functions). > riscv64-unknown-linux-gnu-gcc -march=rv64gc_zicond -O1 -static a.c > qemu-riscv64 -cpu rv64,g=on,x-zicond=on ./a.out printed 0, not 5 as I expected. I support Vineet's patch set (v2). Thanks, Tsukasa