From patchwork Tue Nov 5 05:33:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hu, Lin1" X-Patchwork-Id: 2006648 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=VjBbtESg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4XjH8F2ccZz1xyD for ; Tue, 5 Nov 2024 16:34:17 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3036E3857B91 for ; Tue, 5 Nov 2024 05:34:15 +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 [198.175.65.18]) by sourceware.org (Postfix) with ESMTPS id 41910385840B for ; Tue, 5 Nov 2024 05:33:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41910385840B 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 41910385840B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730784835; cv=none; b=PZOLa/3QB0xBaOIKBf6lIOXl/dVgzVpjUTl5WEDhFWN/3IjiQX2RKxZ0nP8L7e6PqCs5KgWLQS8F+zKoZJeDia0EFQDcUs1ZeSSUHoENd3POsA0c6ppHG9VFr9qi3RIcXp9nGipnCeUPV77+JtppV3tTo/xxqJ7jPNSmCUdHQOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730784835; c=relaxed/simple; bh=uPAMDUwGPSQD7521t48lTRUiW0DZQvLh+086caQxAxA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=OAl8lScUQKsW3EPs2qh47jBPdtzWrOvYqZge56Hb+BjpoGqMlp9WKBvD9GZ5ZWM9ZuUVwmuhbztx2C5AK5yAmW9ao8ymbGYSvrzGrYsv0l0D9fq0O02DopfOhqBpUvdnLxfscPzg8FVfmcZxwdWPS+Zragiizdoww8HW62Wd/TQ= 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=1730784833; x=1762320833; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uPAMDUwGPSQD7521t48lTRUiW0DZQvLh+086caQxAxA=; b=VjBbtESgEWRS7HxGd0f9nGkI5cieh++nvHd/xPigV9ptiPbKLzoq01Fk 5bCenhlyHcmmXAxv1nmvptHYQqSxSVgVlImYVZHEhkd4zC9MvpUNXg/bb tJCIZPbE0YXJaMywpJ151kyYwXjAZOdFPNQ0UYy0DGj2vY3M2Od5MNRpP /Breqw4smg3BiPqC6ZrkZngCqTr8lYoPHTJfw4lrgUL6hb+sepjAnJIsW f3OCxoOcxokxOiklvJM6kk0vaae+noUKUB82UfOItrFWcoZ6Y/iacydJe gXkkDBXtsYsDTofZDkmp0R8K7tGhXbCb6fl1k719NTSJp3g6M3jjdK4Zn Q==; X-CSE-ConnectionGUID: GSn8z5GbRyuparEkhknypA== X-CSE-MsgGUID: EaKXNqs3REiNlNGgETdxNw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="30685749" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="30685749" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Nov 2024 21:33:52 -0800 X-CSE-ConnectionGUID: PNHBE8WnQsCe7i7z0vabWw== X-CSE-MsgGUID: H/40StomTSud9ltSEvownw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,259,1725346800"; d="scan'208";a="88695738" Received: from shliclel4217.sh.intel.com ([10.239.240.127]) by orviesa005.jf.intel.com with ESMTP; 04 Nov 2024 21:33:50 -0800 From: "Hu, Lin1" To: gcc-patches@gcc.gnu.org Cc: hongtao.liu@intel.com, ubizjak@gmail.com Subject: [PATCH v2] i386: Handling exception input of __builtin_ia32_prefetch. [PR117416] Date: Tue, 5 Nov 2024 13:33:49 +0800 Message-Id: <20241105053349.1097940-1-lin1.hu@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 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 Add handler for op3, and the previously stated fail is a random fail not related to this change, OK for trunk? op1 should be between 0 and 2. Add an error handler, and op3 should be 0 or 1, raise a warning, when op3 is an invalid value. gcc/ChangeLog: PR target/117416 * config/i386/i386-expand.cc (ix86_expand_builtin): Raise warning when op1 isn't in range of [0, 2] and set op1 as const0_rtx, and raise warning when op3 isn't in range of [0, 1]. gcc/testsuite/ChangeLog: PR target/117416 * gcc.target/i386/pr117416-1.c: New test. * gcc.target/i386/pr117416-2.c: Ditto. --- gcc/config/i386/i386-expand.cc | 11 +++++++++++ gcc/testsuite/gcc.target/i386/pr117416-1.c | 12 ++++++++++++ gcc/testsuite/gcc.target/i386/pr117416-2.c | 12 ++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/pr117416-1.c create mode 100644 gcc/testsuite/gcc.target/i386/pr117416-2.c diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index 515334aa5a3..fcd4b3b67b7 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -14194,6 +14194,13 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget, return const0_rtx; } + if (!IN_RANGE (INTVAL (op1), 0, 2)) + { + warning (0, "invalid second argument to" + " %<__builtin_ia32_prefetch%>; using zero"); + op1 = const0_rtx; + } + if (INTVAL (op3) == 1) { if (INTVAL (op2) < 2 || INTVAL (op2) > 3) @@ -14216,6 +14223,10 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget, } else { + if (INTVAL (op3) != 0) + warning (0, "invalid forth argument to" + " %<__builtin_ia32_prefetch%>; using zero"); + if (!address_operand (op0, VOIDmode)) { op0 = convert_memory_address (Pmode, op0); diff --git a/gcc/testsuite/gcc.target/i386/pr117416-1.c b/gcc/testsuite/gcc.target/i386/pr117416-1.c new file mode 100644 index 00000000000..7062f27e21a --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr117416-1.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O0" } */ + +#include + +void* p; + +void extern +prefetch_test (void) +{ + __builtin_ia32_prefetch (p, 5, 0, 0); /* { dg-warning "invalid second argument to '__builtin_ia32_prefetch'; using zero" } */ +} diff --git a/gcc/testsuite/gcc.target/i386/pr117416-2.c b/gcc/testsuite/gcc.target/i386/pr117416-2.c new file mode 100644 index 00000000000..1397645cbfc --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr117416-2.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O0" } */ + +#include + +void* p; + +void extern +prefetch_test (void) +{ + __builtin_ia32_prefetch (p, 0, 0, 2); /* { dg-warning "invalid forth argument to '__builtin_ia32_prefetch'; using zero" } */ +}