From patchwork Sun Apr 28 03:53:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1928561 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=dR0pP/Ix; 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 4VRsyQ6Mkjz23jG for ; Sun, 28 Apr 2024 13:53:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A300E3858C60 for ; Sun, 28 Apr 2024 03:53:46 +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 4D34B3858D33 for ; Sun, 28 Apr 2024 03:53:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4D34B3858D33 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 4D34B3858D33 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=1714276409; cv=none; b=Gs2CHi02W1NgMb9q2/2Oj9F7uLh8PDDdCN2iBKIBSP/scKSa3ZaEZ9X69yC0fws4jhxgIi12569KpreD1kZBvfBzx2Y3hjaT2tdGRM1XjVkI/h/wwHb+eHP9X2sj5RC9AQR2s52cXaxOxXNfVC2JYYW4U5edK8OmxFI23vAf+28= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714276409; c=relaxed/simple; bh=BzkwcICXu1VgnyOM5X1+qZxak5Mj4GGOHFJqAbxPwFU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=h8Re0sgAbJCMGzNBrcQXEjYm7tCfuFbU6inTBeazsV2ZAMH2fVTUv00DZ9bagoDFWrciOsS80ykYNfrlPrSComrjnsOCgLRpT2cShb5VJp1sM2nzkbJQypu4dnp3WxxKcwuS5JIuCyaz+VXYahO4euH5RVzEijIawHk5zRDJ6a4= 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=1714276408; x=1745812408; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=BzkwcICXu1VgnyOM5X1+qZxak5Mj4GGOHFJqAbxPwFU=; b=dR0pP/Ix5PI30teup+5AwoH8yaHO8AQCXPBhztEJrYIJ80w+iD9A2AD4 6R4i4bk5ZFbeZDf17XA4Woxo4ptnKBq5OIwjl3KYsJbpXsDdrbdC1Y3xl 9HGCa6Nq01tWOpT8CVyEgamZvyWcrz+d2221Z1jZsuIoVorSvL9fwjPJ6 CjdQlatMzZRjbTVS0w8kMQhNmOPwS9vm9qEQ6wKJtVoDHLtU0D5/T5WEs w1MCywHGZS9PN6No5ycbd/V3xO+fRrAG7qTTN5+g+wWkNL3XCe6B7qepX u0NBKKjMiyLUYHvKF4Vuat4X+OQ5rC9ykj5HXd1PJhDr7u2/rF0ehE8JZ w==; X-CSE-ConnectionGUID: VBmONL4+QGuyyt+fGthfag== X-CSE-MsgGUID: yk+0M5B+RQ6BgITwixc8Pg== X-IronPort-AV: E=McAfee;i="6600,9927,11057"; a="10133212" X-IronPort-AV: E=Sophos;i="6.07,236,1708416000"; d="scan'208";a="10133212" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2024 20:53:25 -0700 X-CSE-ConnectionGUID: xU+BhZeVRtyf59WlHjVwxQ== X-CSE-MsgGUID: 2xvRI3SmSUqzi34re98I6A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,236,1708416000"; d="scan'208";a="30592671" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by orviesa005.jf.intel.com with ESMTP; 27 Apr 2024 20:53:24 -0700 Received: from pli-ubuntu.sh.intel.com (pli-ubuntu.sh.intel.com [10.239.159.47]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 43C5F10189EF; Sun, 28 Apr 2024 11:53:22 +0800 (CST) From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, kito.cheng@gmail.com, Pan Li Subject: [PATCH v1] RISC-V: Fix ICE for legitimize move on subreg const_poly_move Date: Sun, 28 Apr 2024 11:53:21 +0800 Message-Id: <20240428035321.283941-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 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 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 When we build with isl, there will be a ICE for graphite in both the c/c++ and fortran. The legitimize move cannot take care of below rtl. (set (subreg:DI (reg:TI 237) 8) (subreg:DI (const_poly_int:TI [4, 2]) 8)) Then we will have ice similar to below: internal compiler error: in extract_insn, at recog.cc:2812. This patch would like to take care of the above rtl. Given the value of const_poly_int can hardly excceed the max of int64, we can simply consider the highest 8 bytes of TImode is zero and then set the dest to (const_int 0). The below test cases are fixed by this PATCH. C: FAIL: gcc.dg/graphite/pr111878.c (internal compiler error: in extract_insn, at recog.cc:2812) FAIL: gcc.dg/graphite/pr111878.c (test for excess errors) Fortran: FAIL: gfortran.dg/graphite/vect-pr40979.f90 -O (internal compiler error: in extract_insn, at recog.cc:2812) FAIL: gfortran.dg/graphite/pr29832.f90 -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions (internal compiler error: in extract_insn, at recog.cc:2812) FAIL: gfortran.dg/graphite/pr29581.f90 -O3 -g (test for excess errors) FAIL: gfortran.dg/graphite/pr14741.f90 -O (test for excess errors) FAIL: gfortran.dg/graphite/pr29581.f90 -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions (test for excess errors) FAIL: gfortran.dg/graphite/vect-pr40979.f90 -O (test for excess errors) FAIL: gfortran.dg/graphite/id-27.f90 -O (internal compiler error: in extract_insn, at recog.cc:2812) FAIL: gfortran.dg/graphite/pr29832.f90 -O3 -g (internal compiler error: in extract_insn, at recog.cc:2812) FAIL: gfortran.dg/graphite/pr29832.f90 -O3 -g (test for excess errors) FAIL: gfortran.dg/graphite/id-27.f90 -O (test for excess errors) FAIL: gfortran.dg/graphite/pr29832.f90 -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions (test for excess errors) FAIL: gfortran.dg/graphite/pr29581.f90 -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions (internal compiler error: in extract_insn, at recog.cc:2812) FAIL: gfortran.dg/graphite/pr14741.f90 -O (internal compiler error: in extract_insn, at recog.cc:2812) FAIL: gfortran.dg/graphite/pr29581.f90 -O3 -g (internal compiler error: in extract_insn, at recog.cc:2812) The below test suites are passed for this patch: * The rv64gcv fully regression test. * The rv64gc fully regression test. Try to write some RTL code for test but not works well according to existing test cases. Thus, take above as test cases. Please note graphite require the gcc build with isl. gcc/ChangeLog: * config/riscv/riscv.cc (riscv_legitimize_subreg_const_poly_move): New func impl to take care of (const_int_poly:TI 8). (riscv_legitimize_move): Handle subreg is const_int_poly, Signed-off-by: Pan Li Signed-off-by: Pan Li --- gcc/config/riscv/riscv.cc | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 0519e0679ed..bad23ea487f 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -2786,6 +2786,44 @@ riscv_v_adjust_scalable_frame (rtx target, poly_int64 offset, bool epilogue) REG_NOTES (insn) = dwarf; } +/* Take care below subreg const_poly_int move: + + 1. (set (subreg:DI (reg:TI 237) 8) + (subreg:DI (const_poly_int:TI [4, 2]) 8)) + => + (set (subreg:DI (reg:TI 237) 8) + (const_int 0)) */ + +static bool +riscv_legitimize_subreg_const_poly_move (machine_mode mode, rtx dest, rtx src) +{ + gcc_assert (SUBREG_P (src) && CONST_POLY_INT_P (SUBREG_REG (src))); + gcc_assert (SUBREG_BYTE (src).is_constant ()); + + int byte_offset = SUBREG_BYTE (src).to_constant (); + rtx const_poly = SUBREG_REG (src); + machine_mode subreg_mode = GET_MODE (const_poly); + + if (subreg_mode != TImode) /* Only TImode is needed for now. */ + return false; + + if (byte_offset == 8) + { /* The const_poly_int cannot exceed int64, just set zero here. */ + emit_move_insn (dest, CONST0_RTX (mode)); + return true; + } + + /* The below transform will be covered in somewhere else. + Thus, ignore this here. + 1. (set (subreg:DI (reg:TI 237) 0) + (subreg:DI (const_poly_int:TI [4, 2]) 0)) + => + (set (subreg:DI (reg:TI 237) 0) + (const_poly_int:DI [4, 2])) */ + + return false; +} + /* If (set DEST SRC) is not a valid move instruction, emit an equivalent sequence that is valid. */ @@ -2839,6 +2877,11 @@ riscv_legitimize_move (machine_mode mode, rtx dest, rtx src) } return true; } + + if (SUBREG_P (src) && CONST_POLY_INT_P (SUBREG_REG (src)) + && riscv_legitimize_subreg_const_poly_move (mode, dest, src)) + return true; + /* Expand (set (reg:DI target) (subreg:DI (reg:V8QI reg) 0)) Expand this data movement instead of simply forbid it since