From patchwork Mon Feb 12 19:38:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edwin Lu X-Patchwork-Id: 1897935 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=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=YOFgK1+e; 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 4TYZWt1NCWz23hw for ; Tue, 13 Feb 2024 06:38:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 07E643858419 for ; Mon, 12 Feb 2024 19:38:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id B02D13858C52 for ; Mon, 12 Feb 2024 19:38:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B02D13858C52 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B02D13858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1036 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707766708; cv=none; b=Q5fCbGl8/Nt19OQ6kff88I0npt/yECxyC7OoA/iMZE4vmaxqncRsRK3QH+vhfwMZD/6CfNo1ZVSwQWw370GSQxzZfVpR7hD7bpVnlYiCtgiK6D0by+6Egfv8vKPEMPalzwpSfycao7TG6gMRGGwSmM+LhJbMpzuqf9Bc8bCnZ4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707766708; c=relaxed/simple; bh=Xnl+8u26ZfOjh1r443XBXtPRim9sLcq9fo/8UwZK8Jg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=jYlvYXf1C43jZTBq7oW3F5fTWfy7mC/3W0zpgIvHeGcfptiSqMLIs5LNwxxa+FfaIc25ae0Q/94UBv+hRceDWUbnuAoIA7jh/+QG6O/OhCVm1QMVCUatxiPDVtF7CXB+ChoRO8w8e5o6HA3bBlPApZl3kyyElNECyNg6Ne4OFME= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-296c58a11d0so2661274a91.3 for ; Mon, 12 Feb 2024 11:38:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1707766705; x=1708371505; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=I1GSxJ/VDLoY5C3uuGqyj7hB4R9VpoOduktPjrMEClQ=; b=YOFgK1+eBdOi1mHfYUZCzgev69izZDFa6/+VvMgxXf8qJQXog0l6Rgila0g+Jv2+li 4x7s5tXNslrq+x/mpXUA8aEjv8b70hxpJT4p6dqN+4nwWPrlQxUTJtxOZ2/lAE8hYfIj lnc/I55VwrTXRA253lapv/w6Wc9uTZB6TX6IeSobDUcfMyDg2UIAmTicoaEyg31SIyct rrqgXYM7zcmkttTnqRNpEEaMoDQDJCVpw7EBMyVZyVXDdaq9rrYlWswU1Tq7QP1/qPpq axnQyX4HjpUpb1BfLXOZM+rQ5MJslNY8bY5cHBJwJqTUUHmKOIaWE2/IUU/qEDAqXX+z LM4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707766705; x=1708371505; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=I1GSxJ/VDLoY5C3uuGqyj7hB4R9VpoOduktPjrMEClQ=; b=PAofEX7XnHo2M0SUsxRSN2jMfFUUX/WGPEQa1aZ3fN3XamQuC8qcQaUE5sRm6jEwOf JMgNl7JfOUvTD8zEI/YaqLhGOEJj1WJlL85RdyoIZrd4qXY1V+IH97aXBxfQ0N0oSyH9 hhX9cmXb3hIu87Q8DxhCQIj4He/SFPAdCcrJEdEElG7Vd2rIiqtFU0q31U0VSQT7EDfY hJ9EmxJXvCfr2FzepxxRS5yB4bIzxxVAY42ELBeKnu7OWcgKEmk344BbfXmYlSvRpmc2 P5KDEDplv2ql3KguY7LOhIa3IZ02z1/lb3WXNdwJQ9cA+ZBnBA/ZUIvHhif/V00Orn6o 60kw== X-Gm-Message-State: AOJu0YyGhMOSgPFjs9w3uAWmnKgSBjbsWT/OffQj1eGTdDm/6d0mYssm 7iBSmK1boAtZINMF994jkowvb/B1Gnp/jLQnKTh0bW/lYrAIZyYVFR4kKTlvIOjSiTp3ZG+v0TC I X-Google-Smtp-Source: AGHT+IGV/t1eOqvTAY65ebLoSOTDQJSpPBs4+gttH3zhbEzD1/wWd/fn5hSrQ90+/6rA/RZ2pWtoug== X-Received: by 2002:a17:90a:c7d2:b0:297:224e:4a5a with SMTP id gf18-20020a17090ac7d200b00297224e4a5amr3492706pjb.16.1707766703127; Mon, 12 Feb 2024 11:38:23 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWAEsJ1UMqJ8lsKA3BBFxzFFjqKj/ca13uY6u1lqWJeOUgLjcdFdlNE/W8/WX+oy0t/LLScSC2mP6uK4Gh6jyUmIQ== Received: from ewlu.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id sw12-20020a17090b2c8c00b002963cab9e2asm936798pjb.2.2024.02.12.11.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 11:38:22 -0800 (PST) From: Edwin Lu To: gcc-patches@gcc.gnu.org Cc: gnu-toolchain@rivosinc.com, Edwin Lu Subject: [PATCH] testsuite: Add support for scanning assembly with comparitor Date: Mon, 12 Feb 2024 11:38:15 -0800 Message-Id: <20240212193815.3771167-1-ewlu@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org There is currently no support for matching at least x lines of assembly (only scan-assembler-times). This patch would allow setting upper or lower bounds. Use case: using different scheduler descriptions and/or cost models will change assembler output. Testing common functionality across tunes would require a separate testcase per tune since each assembly output would be different. If we know a base number of lines should appear across all tunes (i.e. testing return values: we expect at minimum n stores into register x), we can lower-bound the test to search for scan-assembler-bound {RE for storing into register x} >= n. This avoids artificially inflating the scan-assembler-times expected count due to the assembler choosing to perform extra stores into register x (using it as a temporary register). The testcase would be more robust to cpu/tune changes at the cost of not being as granular towards specific cpu tuning. gcc/ChangeLog: * doc/sourcebuild.texi: add scan-assembler-bound gcc/testsuite/ChangeLog: * lib/scanasm.exp: add scan-assembler-bound Signed-off-by: Edwin Lu --- gcc/doc/sourcebuild.texi | 4 +++ gcc/testsuite/lib/scanasm.exp | 64 +++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi index 193be19767f..4a8c672c9fd 100644 --- a/gcc/doc/sourcebuild.texi +++ b/gcc/doc/sourcebuild.texi @@ -3396,6 +3396,10 @@ excluding LTO sections. Passes if @var{regex} is matched exactly @var{num} times in the test's assembler output, excluding LTO sections. +@item scan-assembler-bound @var{regex} @var{cmp} @var{num} [@{ target/xfail @var{selector} @}] +Passes if @var{regex} is matched @var{cmp} @var{num} times in the test's +assembler output, excluding LTO sections. @var{cmp} is a comparitor. + @item scan-assembler-dem @var{regex} [@{ target/xfail @var{selector} @}] Passes if @var{regex} matches text in the test's demangled assembler output, excluding LTO sections. diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp index 165890eb976..741a5a048b8 100644 --- a/gcc/testsuite/lib/scanasm.exp +++ b/gcc/testsuite/lib/scanasm.exp @@ -516,6 +516,70 @@ proc scan-assembler-times { args } { set_required_options_for scan-assembler-times +# Call pass if pattern is present within a lower or upper bound, +# otherwise fail. +# ex /* { dg-final { scan-assembler-bound {RE} > 3 } } +proc scan-assembler-bound { args } { + if { [llength $args] < 3 } { + error "scan-assembler-bound: too few arguments" + return + } + if { [llength $args] > 4 } { + error "scan-assembler-bound: too many arguments" + return + } + if { [llength $args] >= 4 } { + switch [dg-process-target [lindex $args 3]] { + "S" { } + "N" { return } + "F" { setup_xfail "*-*-*" } + "P" { } + } + } + + set testcase [testname-for-summary] + # The name might include a list of options; extract the file name. + set filename [lindex $testcase 0] + set pattern [lindex $args 0] + set cmp [lindex $args 1] + set bound [lindex $args 2] + set pp_pattern [make_pattern_printable $pattern] + + # This must match the rule in gcc-dg.exp. + set output_file "[file rootname [file tail $filename]].s" + + set files [glob -nocomplain $output_file] + if { $files == "" } { + verbose -log "$testcase: output file does not exist" + unresolved "$testcase scan-assembler-bound $pp_pattern $min $max" + return + } + + if { [lsearch { < > <= >= } $cmp] == -1 } { + error "scan-assembler-bound: illegal argument: $cmp" + return + } + if ![string is integer $bound ] { + error "scan-assembler-bound: illegal argument: $bound" + return + } + + set fd [open $output_file r] + set text [read $fd] + close $fd + regsub -all {(^|\n)[[:space:]]*\.section[[:space:]]*"?\.gnu\.lto_(?:[^\n]*\n(?![[:space:]]*\.(section|text|data|bss)))*[^\n]*\n} $text {\1} text + + set result_count [regexp -all -- $pattern $text] + if [expr $result_count $cmp $bound] { + pass "$testcase scan-assembler-bound $pp_pattern $cmp $bound" + } else { + verbose -log "$testcase: $pp_pattern found $result_count times" + fail "$testcase scan-assembler-bound $pp_pattern $cmp $bound" + } +} + +set_required_options_for scan-assembler-bound + # Utility for scanning demangled compiler result, invoked via dg-final. # Call pass if pattern is present, otherwise fail. proc scan-assembler-dem { args } {