From patchwork Thu Jul 4 21:00:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 809969 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp1334966wru; Thu, 4 Jul 2024 14:03:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXGwKSolBcpRLBiHAqMsYMkMUZdNyAgbrmgNrWuejz3dyUyCQ5HhFuPoxqdUvXkA7DU+YAZTYIqtempcIP1S2Ap X-Google-Smtp-Source: AGHT+IFbEZ59w0A20/BMq2ZbgRE7fy2XOGmnTJ2VzCYuq8GoXJ55wUAc8r6E9SlFwJPUFJruQwbt X-Received: by 2002:a05:6214:529c:b0:6b5:5485:dec9 with SMTP id 6a1803df08f44-6b5ed196e73mr31081936d6.62.1720126996272; Thu, 04 Jul 2024 14:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720126996; cv=none; d=google.com; s=arc-20160816; b=A19qXl9cZGyIse0W1epDp4jTWdsqy4cn6xL8uJzrH2sNuIRNeBy++DpY0Vii61gAKZ iQkot0rDmd/MEV8V2BDpjIAdJZbwyAkbzlJEcNZCxH3GvU3xD6bi8W0bjOLMq5ZtGJV0 HyJSI2m0Vh16LtW3o1NXCIOAvLFaj6H1+J1sWFc4wuPVCXBOF12fst7kw25nFOaFNSyv VkOjJt8ePjBVz8NH2NmMHFWK4GEmllg5rDXozTVRti0X00sZucn2WiBlr19i1trCjwx8 IvlGwpM5AQWwdZ8P7j4p3qAhLz28pdqhOGaxSsdRzLtdS5+vRXoCGM4CV5lkPewh4EQ8 SVyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=EfiaJOFHOi/bNbuAef2XkTZVjQ8B7IdryJWzfP4OXAY=; fh=fA8wXgZkOijV3QzeJqIqYxlGqKQb9nNVVJRQwjQ6hao=; b=SSpp9P81VSY2aFT3+Hu/iVuDTiv0wybaS8xbr61XOQ4dLSNRqTzKhI9BeQ7kY/fPoG i0mopcPNZuOo69hWNdJ29rrmY8bPbwdeGg8+0YA7EEvVn3Uepir5V4hjxpeeJnkeLfjp E6s30SYjZouDCQhH67P8W/ecDwh+6MGy+SjTRxpZetutuAeZ6BLARguctWG0nxVTi36d 0WduY/mi3FO6OzEUCeTgbp6EteHYIwfNxrXVz2VJGeVDAiWj8td03Khtp0qv+IG7S+/q kPTsSSjkEzNz8HEkcCD1wavy7uB9Otis1QThvLkbGWFLTom4gNuabO/ydM2G88YtjOGr /evw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6b5eb71e2absi23437526d6.65.2024.07.04.14.03.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jul 2024 14:03:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sPTbT-0004H9-OZ; Thu, 04 Jul 2024 17:02:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sPTbO-0003Ts-3a; Thu, 04 Jul 2024 17:02:50 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sPTbK-0004T2-6Q; Thu, 04 Jul 2024 17:02:49 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id D509E77574; Fri, 5 Jul 2024 00:00:51 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id EBC76FECAD; Fri, 5 Jul 2024 00:00:56 +0300 (MSK) Received: (nullmailer pid 1507781 invoked by uid 1000); Thu, 04 Jul 2024 21:00:55 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9e?= , Michael Tokarev Subject: [Stable-9.0.2 22/22] tcg/optimize: Fix TCG_COND_TST* simplification of setcond2 Date: Fri, 5 Jul 2024 00:00:52 +0300 Message-Id: <20240704210055.1507652-22-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Richard Henderson Argument ordering for setcond2 is: output, a_low, a_high, b_low, b_high, cond The test is supposed to be against b_low, not a_high. Cc: qemu-stable@nongnu.org Fixes: ceb9ee06b71 ("tcg/optimize: Handle TCG_COND_TST{EQ,NE}") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2413 Signed-off-by: Richard Henderson Tested-by: Alex Bennée Message-Id: <20240701024623.1265028-1-richard.henderson@linaro.org> (cherry picked from commit a71d9dfbf63db42d6e6ae87fc112d1f5502183bd) Signed-off-by: Michael Tokarev diff --git a/tcg/optimize.c b/tcg/optimize.c index 2e9e5725a9..8c49229d6f 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -2274,7 +2274,7 @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op) case TCG_COND_TSTEQ: case TCG_COND_TSTNE: - if (arg_is_const_val(op->args[2], 0)) { + if (arg_is_const_val(op->args[3], 0)) { goto do_setcond_high; } if (arg_is_const_val(op->args[4], 0)) { diff --git a/tests/tcg/x86_64/Makefile.target b/tests/tcg/x86_64/Makefile.target index e64aab1b81..1d427cdc2c 100644 --- a/tests/tcg/x86_64/Makefile.target +++ b/tests/tcg/x86_64/Makefile.target @@ -8,6 +8,8 @@ include $(SRC_PATH)/tests/tcg/i386/Makefile.target +X86_64_TESTS += test-2413 + ifeq ($(filter %-linux-user, $(TARGET)),$(TARGET)) X86_64_TESTS += vsyscall X86_64_TESTS += noexec diff --git a/tests/tcg/x86_64/test-2413.c b/tests/tcg/x86_64/test-2413.c new file mode 100644 index 0000000000..456e5332fc --- /dev/null +++ b/tests/tcg/x86_64/test-2413.c @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Copyright 2024 Linaro, Ltd. */ +/* See https://gitlab.com/qemu-project/qemu/-/issues/2413 */ + +#include + +void test(unsigned long *a, unsigned long *d, unsigned long c) +{ + asm("xorl %%eax, %%eax\n\t" + "xorl %%edx, %%edx\n\t" + "testb $0x20, %%cl\n\t" + "sete %%al\n\t" + "setne %%dl\n\t" + "shll %%cl, %%eax\n\t" + "shll %%cl, %%edx\n\t" + : "=a"(*a), "=d"(*d) + : "c"(c)); +} + +int main(void) +{ + unsigned long a, c, d; + + for (c = 0; c < 64; c++) { + test(&a, &d, c); + assert(a == (c & 0x20 ? 0 : 1u << (c & 0x1f))); + assert(d == (c & 0x20 ? 1u << (c & 0x1f) : 0)); + } + return 0; +}