From patchwork Mon Apr 29 07:40:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1928850 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=LES33fwF; 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 4VSZxz58GJz23hd for ; Mon, 29 Apr 2024 17:40:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95EB43858415 for ; Mon, 29 Apr 2024 07:40:52 +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.16]) by sourceware.org (Postfix) with ESMTPS id CC6C03858D33 for ; Mon, 29 Apr 2024 07:40:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CC6C03858D33 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 CC6C03858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714376433; cv=none; b=DPIckT8oZcGZEk/4s96TAdfAUEJKEWN3SNOTZfU7nf9bCaYrFDdxPIwcRGY1HTavry6S6PdbM8pwLIFGUTdhbEvCBDY4RtWWLFjDka1lIsFZTNIvwmxLNwT91Y/05RtWWl70MPq1MRcaPf+tNuV6IaFkoO0Kd6RgFjWxQh5ikBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714376433; c=relaxed/simple; bh=Fctvahqr8Fe2t+ZOZdix6KMAyCqZUty2fCAiRWv/f80=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=PlzjrJEI6ppB7dEtMOoLarJdpuomkhYdzKN+k49cOYU8WX0nP3QZM77yRRsZh1lshme3lXqHvZ7YtSVfvyEHcjTwpDgBbVdcA/fu0eiJMQqS5AB3h+VP/v/bMmRZkssUrIk687Z6+4JEbJiY0vjlsavzQH8ceDqNId2hmtWEMb0= 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=1714376431; x=1745912431; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Fctvahqr8Fe2t+ZOZdix6KMAyCqZUty2fCAiRWv/f80=; b=LES33fwFY4WK63WH3o+4t3jIz8PkcZerqDM2EvHvEnNJqv2n5tAtHIaL tRqdRYZmmRkksaJPONPZgGhnyX8gYj/wC3fuXEbtLrsA0gGP46V7SyVBB Xm0LTsdS2Utr34djCSZkmsPmIDOmHegVnttK0VVRG1kj9xZlSmUuQ5JPr SUI80fLNaRJH31SSRPbgJST0vBZ3KRlMklW+DsrgWZvUZ7w1HAxHU4+pV wSYFItmPVCQQ5TSTNK2732EbcbS7rB9J4NuwyfFH9EPsSRW1ZzsiB5i/S ysg9AWDGk5Pfevmm01BLnIMA+sdGIrrMezRK537/aG0HtjA+E0lR8TTG2 w==; X-CSE-ConnectionGUID: gbm50BCVS+KmFFByfCZkxQ== X-CSE-MsgGUID: yLaabUVuSVOYro2Fg45xsg== X-IronPort-AV: E=McAfee;i="6600,9927,11057"; a="10564257" X-IronPort-AV: E=Sophos;i="6.07,239,1708416000"; d="scan'208";a="10564257" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2024 00:40:20 -0700 X-CSE-ConnectionGUID: TDmFxTXlSc63zryL3aSzCg== X-CSE-MsgGUID: 4SVMFRzbQYGVxdQiw0JTBA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,239,1708416000"; d="scan'208";a="30833782" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by orviesa005.jf.intel.com with ESMTP; 29 Apr 2024 00:40:17 -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 242761007C38; Mon, 29 Apr 2024 15:40:16 +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 v2] RISC-V: Fix ICE for legitimize move on subreg const_poly_int [PR114885] Date: Mon, 29 Apr 2024 15:40:14 +0800 Message-Id: <20240429074014.1576154-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240428035321.283941-1-pan2.li@intel.com> References: <20240428035321.283941-1-pan2.li@intel.com> 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. PR target/114885 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 --- gcc/config/riscv/riscv.cc | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 0519e0679ed..0f62b295b96 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -2786,6 +2786,45 @@ 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. + (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 +2878,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