From patchwork Thu Mar 21 08:32:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 1914320 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=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=QfE3xPIb; 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 4V0dzm0TP4z1yWs for ; Thu, 21 Mar 2024 19:34:28 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D5753858C98 for ; Thu, 21 Mar 2024 08:34:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) by sourceware.org (Postfix) with ESMTPS id 4FF8B3858CD1 for ; Thu, 21 Mar 2024 08:32:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4FF8B3858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4FF8B3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711009946; cv=none; b=v8WFzQriRhw0l38gwjCYjiciKPploKWRCsiDDrX7GNwDUAoC6T3cFi+RXINX6OcwMvhHh6RKUhR/m4pfl3TWL262734wmpsjFLBa5y6P1flyCz8oeKbwb6NRRZF+1iIpJJq+vNq1xo4eYbK2xrO+7Mum6AS0IsgoaUsomx78wu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711009946; c=relaxed/simple; bh=Apl23pTMZAPZG5AY1Godhx9P2veqgqLaPoQZaZyhMZs=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=MCe/yq0Saa1TU5pRJRp/lMi7zxs1P52DuKDSlkUFI0Jgc9FRyTx44MbNqZuw7t0MkyBKuQgxYlMGQo6Io4cLYlrQa5+3LlMSORElGE6WCmoy4DNZqcwHut1+baJnrgxFLskR2ovm4aQoahg3tI/YBWScUB5EukYxe4o8wsU1UyY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711009937; x=1742545937; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Apl23pTMZAPZG5AY1Godhx9P2veqgqLaPoQZaZyhMZs=; b=QfE3xPIbnEuUIL7kM9KD6Qp74aeKzrP9utYcToCpMoKf56zIzEqoaA74 MV8OC/JeF7TIQ2qSFlJAbOzgGJRSd3bU49mRh1yo89/RPChD0dW2eZCb7 D4SNypiTcrFtdJLipuJTiEGxMr1CebfT23lWcD7vdrmikLxJlAnJBjOrs MZLZBSaxQMNkUfdnkzzSNxu3AxzfumiaD6EatcFFIJjEizI1oOa2je8KU grF5qHus1gJ325WCKi5+VDBLS/x/ADunvaoX4ox0kPZST8gf6t0Z98krb jIJe+vn70yHqvQgXYgealmY4zmGeJsFR1V7Y3P4Kt1fTDfRsQsXH/wk6T A==; X-IronPort-AV: E=McAfee;i="6600,9927,11019"; a="5829498" X-IronPort-AV: E=Sophos;i="6.07,142,1708416000"; d="scan'208";a="5829498" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2024 01:32:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,142,1708416000"; d="scan'208";a="14334812" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmviesa010.fm.intel.com with ESMTP; 21 Mar 2024 01:32:15 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 15C2D10081DD; Thu, 21 Mar 2024 16:32:14 +0800 (CST) From: liuhongt To: gcc-patches@gcc.gnu.org Cc: crazylht@gmail.com, hjl.tools@gmail.com Subject: [PATCH] Fix runtime error for nonlinear iv vectorization(step_mult). Date: Thu, 21 Mar 2024 16:32:14 +0800 Message-Id: <20240321083214.184183-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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 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 wi::from_mpz doesn't take a sign argument, we want it to be wrapped instead of saturation, so pass utype and true to it, and it fixes the bug. Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. Ok for trunk and backport to gcc13? gcc/ChangeLog: PR tree-optimization/114396 * tree-vect-loop.cc (vect_peel_nonlinear_iv_init): Pass utype and true to wi::from_mpz. gcc/testsuite/ChangeLog: * gcc.target/i386/pr114396.c: New test. --- gcc/testsuite/gcc.target/i386/pr114396.c | 105 +++++++++++++++++++++++ gcc/tree-vect-loop.cc | 2 +- 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr114396.c diff --git a/gcc/testsuite/gcc.target/i386/pr114396.c b/gcc/testsuite/gcc.target/i386/pr114396.c new file mode 100644 index 00000000000..4c4015f871f --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr114396.c @@ -0,0 +1,105 @@ +/* { dg-do run } */ +/* { dg-options "-O1 -fwrapv -fno-vect-cost-model" } */ + +short a = 0xF; +short b[16]; +unsigned short ua = 0xF; +unsigned short ub[16]; + +short +__attribute__((noipa)) +foo (short a) +{ + for (int e = 0; e < 9; e += 1) + b[e] = a *= 5; + return a; +} + +short +__attribute__((noipa)) +foo1 (short a) +{ + for (int e = 0; e < 9; e += 1) + b[e] = a *= -5; + return a; +} + +unsigned short +__attribute__((noipa)) +foou (unsigned short a) +{ + for (int e = 0; e < 9; e += 1) + ub[e] = a *= -5; + return a; +} + +unsigned short +__attribute__((noipa)) +foou1 (unsigned short a) +{ + for (int e = 0; e < 9; e += 1) + ub[e] = a *= 5; + return a; +} + +short +__attribute__((noipa,optimize("O3"))) +foo_o3 (short a) +{ + for (int e = 0; e < 9; e += 1) + b[e] = a *= 5; + return a; +} + +short +__attribute__((noipa,optimize("O3"))) +foo1_o3 (short a) +{ + for (int e = 0; e < 9; e += 1) + b[e] = a *= -5; + return a; +} + +unsigned short +__attribute__((noipa,optimize("O3"))) +foou_o3 (unsigned short a) +{ + for (int e = 0; e < 9; e += 1) + ub[e] = a *= -5; + return a; +} + +unsigned short +__attribute__((noipa,optimize("O3"))) +foou1_o3 (unsigned short a) +{ + for (int e = 0; e < 9; e += 1) + ub[e] = a *= 5; + return a; +} + +int main() { + unsigned short uexp, ures; + short exp, res; + exp = foo (a); + res = foo_o3 (a); + if (exp != res) + __builtin_abort (); + + exp = foo1 (a); + res = foo1_o3 (a); + if (uexp != ures) + __builtin_abort (); + + uexp = foou (a); + ures = foou_o3 (a); + if (uexp != ures) + __builtin_abort (); + + uexp = foou1 (a); + ures = foou1_o3 (a); + if (uexp != ures) + __builtin_abort (); + + return 0; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 4375ebdcb49..2921a9e6aa1 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -9454,7 +9454,7 @@ vect_peel_nonlinear_iv_init (gimple_seq* stmts, tree init_expr, wi::to_mpz (skipn, exp, UNSIGNED); mpz_ui_pow_ui (mod, 2, TYPE_PRECISION (type)); mpz_powm (res, base, exp, mod); - begin = wi::from_mpz (type, res, TYPE_SIGN (type)); + begin = wi::from_mpz (utype, res, true); tree mult_expr = wide_int_to_tree (utype, begin); init_expr = gimple_build (stmts, MULT_EXPR, utype, init_expr, mult_expr);