From patchwork Mon Sep 23 14:56:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1988621 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=XCYckknm; 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 4XC5hc0hDBz1xsg for ; Tue, 24 Sep 2024 00:58:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B801E3858C78 for ; Mon, 23 Sep 2024 14:58:04 +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.11]) by sourceware.org (Postfix) with ESMTPS id 88B433858D26 for ; Mon, 23 Sep 2024 14:57:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 88B433858D26 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 88B433858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727103464; cv=none; b=EHIVOo70EycjZGSu1tZGwsphfWEjxMPrAiNtxp1t8FoKUu/kpNsjwM//rqtpmaXtVcDCbX6lC7eEryjD40nH7P9AtghswJo06nlVP3cBl06byhN9+kvQsKn69lW2YKpxhXFQR2anH7080Kqj1lJTQVzwBCzZ2C/QOOR5KCRjPjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727103464; c=relaxed/simple; bh=z9c2AoO2FaKa2FwcLPwrzmfsXvK7L79zSrA6n2hVZsM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qc2z5F9lmWtL4H6+ZjLlj15SVZ5vem6vNWeaLNTtp/de08KQghzFN/cQBqavqW+6rWpsYt8DNsywgvuWq0SN7y8OlRhFIX+/HlkaZhK7vmFFfP0zYB7RODf5iDqUyeaewSwp6ZObMIDjLo96zXXA84uuv3CilLkXLeVjsiJC/xs= 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=1727103463; x=1758639463; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=z9c2AoO2FaKa2FwcLPwrzmfsXvK7L79zSrA6n2hVZsM=; b=XCYckknm6wl2hCN+7OlzO+U9APXT9tvyZBS1LWxtNbmKMFj1mjU69H0D 93A65csB7TU7UqAlS8L61crvQT1/aY0CbyTIiNuZ/hmdQrc5u/0sJbdVS dxc8mEiDllxS/UWBDNQ7ypOAQK9dMNsBLkX0QCGuwQ7nvk0H8onCQnkzB jZu7zsDf7ZOa1kCdUEU9hNLwHWpJaIbZDYJHPD9D/b58kDWEUI3fpr6ob DuIq8So9hI0DanT4wXyfIBK0rqtKQbwd12lK8PkGhIqdTwF3Ame63Z3TG MZ3M0lDGjMfs/Ht+SojJ1XpQb/QWUjw87yO77Qeu7WMYJnCvqi8gbu5PX Q==; X-CSE-ConnectionGUID: GooghWeIQXCq76hcftog8g== X-CSE-MsgGUID: B/pICuVXTxetAwGpCufkcA== X-IronPort-AV: E=McAfee;i="6700,10204,11204"; a="36639276" X-IronPort-AV: E=Sophos;i="6.10,251,1719903600"; d="scan'208";a="36639276" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2024 07:57:41 -0700 X-CSE-ConnectionGUID: r0uyu9hiT4+ufjyrqUEbCw== X-CSE-MsgGUID: LedazeBJSL2VqnpIv6pn5g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,251,1719903600"; d="scan'208";a="71409036" Received: from panli.sh.intel.com ([10.239.154.73]) by orviesa006.jf.intel.com with ESMTP; 23 Sep 2024 07:57:11 -0700 From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com, Tamar.Christina@arm.com, juzhe.zhong@rivai.ai, kito.cheng@gmail.com, jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, Pan Li Subject: [PATCH v1] Widening-Mul: Fix one ICE for SAT_SUB matching operand promotion Date: Mon, 23 Sep 2024 22:56:02 +0800 Message-ID: <20240923145602.3872286-1-pan2.li@intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP, WEIRD_PORT 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 From: Pan Li This patch would like to fix the following ICE for -O2 -m32 of x86_64. during RTL pass: expand JackMidiAsyncWaitQueue.cpp.cpp: In function 'void DequeueEvent(unsigned int)': JackMidiAsyncWaitQueue.cpp.cpp:3:6: internal compiler error: in expand_fn_using_insn, at internal-fn.cc:263 3 | void DequeueEvent(unsigned frame) { | ^~~~~~~~~~~~ 0x27b580d diagnostic_context::diagnostic_impl(rich_location*, diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag (*) [1], diagnostic_t) ???:0 0x27c4a3f internal_error(char const*, ...) ???:0 0x27b3994 fancy_abort(char const*, int, char const*) ???:0 0xf25ae5 expand_fn_using_insn(gcall*, insn_code, unsigned int, unsigned int) ???:0 0xf2a124 expand_direct_optab_fn(internal_fn, gcall*, optab_tag, unsigned int) ???:0 0xf2c87c expand_SAT_SUB(internal_fn, gcall*) ???:0 We allowed the operand convert when matching SAT_SUB in match.pd, to support the zip benchmark SAT_SUB pattern. Aka, (convert? (minus (convert1? @0) (convert1? @1))) for below sample code. void test (uint16_t *x, unsigned b, unsigned n) { unsigned a = 0; register uint16_t *p = x; do { a = *--p; *p = (uint16_t)(a >= b ? a - b : 0); // Truncate after .SAT_SUB } while (--n); } The pattern match for SAT_SUB itself may also act on below scalar sample code too. unsigned long long GetTimeFromFrames(int); unsigned long long GetMicroSeconds(); void DequeueEvent(unsigned frame) { long long frame_time = GetTimeFromFrames(frame); unsigned long long current_time = GetMicroSeconds(); DequeueEvent(frame_time < current_time ? 0 : frame_time - current_time); } Aka: uint32_t a = (uint32_t)SAT_SUB(uint64_t, uint64_t); Then there will be a problem when ia32 or -m32 is given when compiling. Because we only check the lhs (aka uint32_t) type is supported by ifn and missed the operand (aka uint64_t). Mostly DImode is disabled for 32 bits target like ia32 or rv32gcv, and then trigger ICE when expanding. The below test suites are passed for this patch. * The rv64gcv fully regression test. * The x86 bootstrap test. * The x86 fully regression test. PR target/116814 gcc/ChangeLog: * tree-ssa-math-opts.cc (build_saturation_binary_arith_call): Add ifn is_supported check for operand TREE type. gcc/testsuite/ChangeLog: * g++.dg/torture/pr116814-1.C: New test. Signed-off-by: Pan Li --- gcc/testsuite/g++.dg/torture/pr116814-1.C | 12 ++++++++++++ gcc/tree-ssa-math-opts.cc | 23 +++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/torture/pr116814-1.C diff --git a/gcc/testsuite/g++.dg/torture/pr116814-1.C b/gcc/testsuite/g++.dg/torture/pr116814-1.C new file mode 100644 index 00000000000..8db5b020cfd --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr116814-1.C @@ -0,0 +1,12 @@ +/* { dg-do compile { target { i?86-*-* x86_64-*-* } } } */ +/* { dg-options "-O2 -m32" } */ + +unsigned long long GetTimeFromFrames(int); +unsigned long long GetMicroSeconds(); + +void DequeueEvent(unsigned frame) { + long long frame_time = GetTimeFromFrames(frame); + unsigned long long current_time = GetMicroSeconds(); + + DequeueEvent(frame_time < current_time ? 0 : frame_time - current_time); +} diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc index d61668aacfc..361761cedef 100644 --- a/gcc/tree-ssa-math-opts.cc +++ b/gcc/tree-ssa-math-opts.cc @@ -4042,15 +4042,22 @@ build_saturation_binary_arith_call (gimple_stmt_iterator *gsi, gphi *phi, internal_fn fn, tree lhs, tree op_0, tree op_1) { - if (direct_internal_fn_supported_p (fn, TREE_TYPE (lhs), OPTIMIZE_FOR_BOTH)) - { - gcall *call = gimple_build_call_internal (fn, 2, op_0, op_1); - gimple_call_set_lhs (call, lhs); - gsi_insert_before (gsi, call, GSI_SAME_STMT); + tree lhs_type = TREE_TYPE (lhs); + tree op_type = TREE_TYPE (op_0); - gimple_stmt_iterator psi = gsi_for_stmt (phi); - remove_phi_node (&psi, /* release_lhs_p */ false); - } + if (!direct_internal_fn_supported_p (fn, lhs_type, OPTIMIZE_FOR_BOTH)) + return; + + if (lhs_type != op_type + && !direct_internal_fn_supported_p (fn, op_type, OPTIMIZE_FOR_BOTH)) + return; + + gcall *call = gimple_build_call_internal (fn, 2, op_0, op_1); + gimple_call_set_lhs (call, lhs); + gsi_insert_before (gsi, call, GSI_SAME_STMT); + + gimple_stmt_iterator psi = gsi_for_stmt (phi); + remove_phi_node (&psi, /* release_lhs_p */ false); } /*