From nobody Mon May 20 21:40:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1614556514; cv=none; d=zohomail.com; s=zohoarc; b=VF3owbRLjUHOPJ+8AX+uVUkczsK4NV8rsC8dMJQtaiN2tZ33yJRjY9d6bQQryCZ36426u8VayHZkL0hnWF+xzh31R1TFgqZnA7iv6Kh/m5PMVZ+2TlKmAsEYXsqYisS0sFG2Lv0YgyM8EpGqxkkUS42nbA6cHbfvwpro3BoW5Dk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614556514; h=Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=CuWrYyiZWdulIwmEpBK4yxV1iSuukhkkcBuC0p9tN6M=; b=ZGbzSZ8Vu0gxc/QCufTussfjEVxW2oIv0kogsaHWdn4Crj/8xnK3+aMXHqh/v6JXH7WMA/4ngb8MkTz420kMmtm18+LPHX76uthubqfXPunQ9ugqVI9X8a5p2s7k/8L/S795Ndpos2yK8ZMhDV1YZkd4uoEDTqY7wQxEOS4kR1E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614556514498942.4380448176851; Sun, 28 Feb 2021 15:55:14 -0800 (PST) Received: from localhost ([::1]:57072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGVu5-000076-H1 for importer@patchew.org; Sun, 28 Feb 2021 18:55:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGVUd-00042H-3p for qemu-devel@nongnu.org; Sun, 28 Feb 2021 18:28:55 -0500 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:46711) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGVUb-0001R2-0x for qemu-devel@nongnu.org; Sun, 28 Feb 2021 18:28:54 -0500 Received: by mail-pl1-x636.google.com with SMTP id u11so8749231plg.13 for ; Sun, 28 Feb 2021 15:28:49 -0800 (PST) Received: from localhost.localdomain (174-21-84-25.tukw.qwest.net. [174.21.84.25]) by smtp.gmail.com with ESMTPSA id q91sm6050767pjk.37.2021.02.28.15.28.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 15:28:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=CuWrYyiZWdulIwmEpBK4yxV1iSuukhkkcBuC0p9tN6M=; b=B0v1cPXteMsT+3w3zGYlGw29tHorlcQHWbiCXqZkkordvWOG40hDDeaRxMDs7xJaSd xodD+jF6OQnkfxd0Q8yFl9i94kCUVK6zX4guMCRJxUXkP3wavmhYONWryFrtca9hoVKJ 1cItzgQDQpxxJKdZxDU925tIWNcsML3Xwyx6Nr7k9+arPhq7hGkbVW8VCZMV8qYkymIG G4P3GQNxSL9kOqg04BlbYseUkImQuv50x14GA8jx0OOxfMFvJ4mXDBsNKpK29RGwp2YJ N05QUW+V8l9PYxA1K/d3EDlHXfKNRn3F4i3bJSzF2IX1ai0zjcyyYLICJoiHPIxlPzul MWhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=CuWrYyiZWdulIwmEpBK4yxV1iSuukhkkcBuC0p9tN6M=; b=HXm0+mgzsaSO4K4XC4KsFXbHWCxvT7cGhc/qQ/tkd0kMHBk+FWf80Rf55sY4SZZ7nw lXJdyPxF/AyhGv+KdqXNg8gI43BaXwzL5iWyFGIuLNRo+ByaAy9gvEVk5j5H2vbqvR2Z 29TNveCEe9SxjllmIG0ixMTPPs1rgn/vgxYXocbh4G1PoVV3+qfCv0SyyBXdOeazI1Em wg7WePkyJYHOes1qLM/F6VUK0OP2fODDueAbJi8qc2X8FEunT5fqKOANEzw7KsmwydqV m30dZewj2DE0WLFp5v3ARQuz/O1R+dRdSmwtntyJiut9pCeM+4R30n49CW5/8EV0WWPr IL9A== X-Gm-Message-State: AOAM532dAUu8upmKbyUF8SDyp6By247YUV6vsOPbEFdcntEq36qhgRSN E2u7/nt9ESTCJ7USZjac3CoLqTt9BQR2cA== X-Google-Smtp-Source: ABdhPJysmjtA7ZXc0kWAgWmd+ffc2IIJuoWBlt6a684O7tgU9YvRIhakEd9kzXv3cT4WP++fNDn75Q== X-Received: by 2002:a17:902:9a49:b029:df:fab8:384 with SMTP id x9-20020a1709029a49b02900dffab80384mr13072776plv.37.1614554928816; Sun, 28 Feb 2021 15:28:48 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH] tcg/aarch64: Fix constant subtraction in tcg_out_addsub2 Date: Sun, 28 Feb 2021 15:28:47 -0800 Message-Id: <20210228232847.322468-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" An hppa guest executing 0x000000000000e05c: ldil L%10000,r4 0x000000000000e060: ldo 0(r4),r4 0x000000000000e064: sub r3,r4,sp produces ---- 000000000000e064 000000000000e068 sub2_i32 tmp0,tmp4,r3,$0x1,$0x10000,$0x0 after folding and constant propagation. Then we hit tcg-target.c.inc:640: tcg_out_insn_3401: Assertion `aimm <=3D 0xfff' failed. because aimm is in fact -16, but unsigned. The ((bl < 0) ^ sub) condition which negates bl is incorrect and will always lead to this abort. If the constant is positive, sub will make it negative; if the constant is negative, sub will keep it negative. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- tcg/aarch64/tcg-target.c.inc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc index 1376cdc404..ec0a86d9d8 100644 --- a/tcg/aarch64/tcg-target.c.inc +++ b/tcg/aarch64/tcg-target.c.inc @@ -1410,10 +1410,10 @@ static void tcg_out_addsubi(TCGContext *s, int ext,= TCGReg rd, } } =20 -static inline void tcg_out_addsub2(TCGContext *s, TCGType ext, TCGReg rl, - TCGReg rh, TCGReg al, TCGReg ah, - tcg_target_long bl, tcg_target_long bh, - bool const_bl, bool const_bh, bool sub) +static void tcg_out_addsub2(TCGContext *s, TCGType ext, TCGReg rl, + TCGReg rh, TCGReg al, TCGReg ah, + tcg_target_long bl, tcg_target_long bh, + bool const_bl, bool const_bh, bool sub) { TCGReg orig_rl =3D rl; AArch64Insn insn; @@ -1423,11 +1423,13 @@ static inline void tcg_out_addsub2(TCGContext *s, T= CGType ext, TCGReg rl, } =20 if (const_bl) { - insn =3D I3401_ADDSI; - if ((bl < 0) ^ sub) { - insn =3D I3401_SUBSI; + if (bl < 0) { bl =3D -bl; + insn =3D sub ? I3401_ADDSI : I3401_SUBSI; + } else { + insn =3D sub ? I3401_SUBSI : I3401_ADDSI; } + if (unlikely(al =3D=3D TCG_REG_XZR)) { /* ??? We want to allow al to be zero for the benefit of negation via subtraction. However, that leaves open the --=20 2.25.1