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: 200019 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp128443dyb; Mon, 12 Feb 2024 11:39:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVd579GvFxGV/WEGYOFdc1zy/n8liTVO9oUeIW1nA1iwZkw36ojtznSJ2m/WfzpSoel2DfFszQKC9TQoIRx2ovzI4/mKw== X-Google-Smtp-Source: AGHT+IHp1qg3WBsVLMY9MkHGU9uSp1Fm7krIa1xsGv24mQPppVxuy+jVws7EWTgwdse3l6pW2qSe X-Received: by 2002:a0c:ca8e:0:b0:68c:bd41:e78a with SMTP id a14-20020a0cca8e000000b0068cbd41e78amr8327980qvk.28.1707766749217; Mon, 12 Feb 2024 11:39:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707766749; cv=pass; d=google.com; s=arc-20160816; b=nE5q+LXXDU+7+feNsX2+7d/nVklclwuU0FfrKLrU2EpQsUqKRM9XMglpfredAzgrgi Al5/waaGWldD0J8QhI/Q3xbef39lXZaSkKg/rDr2axnotUL34BhHiSRo+NWyBGBTIQx/ ygW6pHinWoA404qfuo94PICflC44hNIVzoH/vOKeTmWMKfFCVSHWHj7X5Eg4DcFrhtsv 1Lo4wsa50aAHb6r9EstlNnxAx6iyxQUpeyNwzB6Z29U9dZYmmk9Zcnac+nc6oL/XmEho pQxrvw0uoyoSjgftbVEMbYjuQMlP/qLhAy9+cREZ0cLUK5ifdJ0wp5m75gn2fdToPlQn zM9A== 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 :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=I1GSxJ/VDLoY5C3uuGqyj7hB4R9VpoOduktPjrMEClQ=; fh=342qg525JfKuCbgoQs872ZEBqAtrxwZzRQpnOfczTqw=; b=vywVLMpWagnuHvIynABb5R3XtHh7XIcK/y8Ue75OROj41U1q5/zLlGt4MtI5BFIXO0 d5VqhtAL3yq3LEmH81ZCKggMcDyjbGqBnkV82h2FV6UJcx2Xz6IHInkBHI8PkAvciQW9 0GmH9W9FGZY3JQbT5xJ7tV/Lm/mWM3oY2XcpCo50LS77XNuThaylx8hjft1tYUHcNEQc P/DrC/dwKZEAijbWDGSWzt5296hqIEdlt3rTgMK2x/ihyqeR0OxkSsZkAYD689IwGECi 7HZpoS8t7e63Mt8XEDm1mTjdeaoo46xNHjbsps46vwwbaquNYK3+ESRdavdIdLiSBLse 1iGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=YOFgK1+e; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" X-Forwarded-Encrypted: i=2; AJvYcCVYNtNMziLH5UQHGSlvQovH5Bj+yMjn67dvpDBYxE8AcU5CJlAYafiHPwAmxPR31iYT+B1ihUPwsVfF4T2bJhgaOH8/lg== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m2-20020ad45dc2000000b0067f4a6eca31si1096457qvh.65.2024.02.12.11.39.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 11:39:09 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=YOFgK1+e; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 DB57D385840A for ; Mon, 12 Feb 2024 19:39:08 +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-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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790723227265152728 X-GMAIL-MSGID: 1790723227265152728 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 } {