From patchwork Tue Sep 26 22:47:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "juzhe.zhong@rivai.ai" X-Patchwork-Id: 145063 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2239054vqu; Tue, 26 Sep 2023 15:47:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDLCyMDe0U//e2vQmAbv9+XrBYkyHSxufLyzI2XkT5wyaQKqsdVEssmQzMYHcOM/AgfdYV X-Received: by 2002:a05:6402:1e93:b0:534:2ee8:fd52 with SMTP id f19-20020a0564021e9300b005342ee8fd52mr6253628edf.12.1695768470233; Tue, 26 Sep 2023 15:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695768470; cv=none; d=google.com; s=arc-20160816; b=MR2dDmHAaTjsA81ctDTj88x1hW4FmAwuURC1t59K9gWIEqy4a1+HCQRjm/mMmXFFYg BU0cY/Zb9noh0O21PPkgkMHyP94PitNrbzRkHNlyZhfU1EdY0y4V5f/sQRxtfVmqd2T5 7kaHwjxgtRB8BUrnYC4V6kUUNQaH84RQWAnKW65sTJuwESo5O26YqEY2VTlNaD/FVsT0 lq9zNYFeolVK1SRlJKBZ9xZpR5TfEiivHpVfK6y2g33uR5O9kRvvxo1b5YkQ21YGKY9A bi1eeEhXRfqZyrKJ2oHElxx23qK88u/aKYFxlcO/Azgjr+878DgQAPF02SFrea4CazL6 QxGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dmarc-filter:delivered-to; bh=u38VS/hA++bsEUAL/DIhXYcDF7ahfScyaJOj5yoUxQI=; fh=W3C5Hc9FiSP2qarHs0G4ObKTyyHg2mIVLNx3HMr/PEc=; b=vclncNL275b1KS6iPRjNpL5/oECqJCIo/v1skdvtAVOvkXEK4d3OUBGlN+NU1Mohwm REOgiZFO3GD/6Vwa5qs4hX2HT8NWgiekLCU9kLgVRibKIKsBrIc8ssvaIDaPuYwI0iLe E3ljZwSd2BzuOtVZy1ce4rKbmEGWa8cme5ztpV1SMKUpcFn2gzrY8pB+43jBk3ycwuZP RNfclGhBWJe/oR8H9x6iUd2YcTvCeIZxiSIV4B8GES2vlQtSWNArUSpB+HehZpH0cGef w5p5wALsvWzo3jZTNOiWE3CldOh5nPuO77UZKgZxP9tIJhVBGbBL7eII4UehiVSl3i7v NgGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k21-20020aa7d8d5000000b005304db282f2si11569813eds.327.2023.09.26.15.47.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 15:47:50 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AFCD1385F000 for ; Tue, 26 Sep 2023 22:47:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbg151.qq.com (smtpbg151.qq.com [18.169.211.239]) by sourceware.org (Postfix) with ESMTPS id 5BB363858C27 for ; Tue, 26 Sep 2023 22:47:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5BB363858C27 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai X-QQ-mid: bizesmtp73t1695768435tg61pv0u Received: from rios-cad122.hadoop.rioslab.org ( [58.60.1.26]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 27 Sep 2023 06:47:13 +0800 (CST) X-QQ-SSF: 01400000002000G0V000B00A0000000 X-QQ-FEAT: HH6/KuQOBEaGlCfbkddzjKi3yzMnc2mht/2tFhNScZO9bFH8WdZZZ6igxXF5H GsijkkGjF5tNep/IRbXA44iPaeuZNcQeEPbmy8dWibSnMSn/Qnb6A52lDHuLhw0rCXZDf1/ LW/rfVXtjfjUg7LykWoZToJTfJ5+tuE9hbxdFW5rwl71tiPYSIz3bXt0TgGLeUy0+IO7SWQ nECzF3hb9obQgSDC8eZR5Wx2acgbju1O1W9IjBuwj7QkNvf+yvYn0I2A/WwULqKPV9zF6Vp usju0PBo+/ML5xENXCGeNuOVpYXrTLYIFZrY+pge1zIxVQFn5fzU5nwe7tx7svwx5/wRq1Q 67ojB9dndI806pxSmMOuAWJQc1pM1Zd94M8rGAYO4cc976I2b/Sui28w97oxw== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 11059668070761644867 From: Juzhe-Zhong To: gcc-patches@gcc.gnu.org Cc: richard.sandiford@arm.com, Juzhe-Zhong Subject: [PATCH] DSE: Fix ICE when the mode with access_size don't exist on the target[PR111590] Date: Wed, 27 Sep 2023 06:47:12 +0800 Message-Id: <20230926224712.3858055-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.3 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz7a-one-0 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778142119672345380 X-GMAIL-MSGID: 1778142119672345380 hen doing fortran test with 'V' extension enabled on RISC-V port. I saw multiple ICE: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111590 The root cause is on DSE: internal compiler error: in smallest_mode_for_size, at stor-layout.cc:356 0x1918f70 smallest_mode_for_size(poly_int<2u, unsigned long>, mode_class) ../../../../gcc/gcc/stor-layout.cc:356 0x11f75bb smallest_int_mode_for_size(poly_int<2u, unsigned long>) ../../../../gcc/gcc/machmode.h:916 0x3304141 find_shift_sequence ../../../../gcc/gcc/dse.cc:1738 0x3304f1a get_stored_val ../../../../gcc/gcc/dse.cc:1906 0x3305377 replace_read ../../../../gcc/gcc/dse.cc:2010 0x3306226 check_mem_read_rtx ../../../../gcc/gcc/dse.cc:2310 0x330667b check_mem_read_use ../../../../gcc/gcc/dse.cc:2415 After investigations, DSE is trying to do optimization like this following codes: (insn 86 85 87 9 (set (reg:V4DI 168) (mem/u/c:V4DI (reg/f:DI 171) [0 S32 A128])) "bug.f90":6:18 discrim 6 1167 {*movv4di} (expr_list:REG_EQUAL (const_vector:V4DI [ (const_int 4 [0x4]) (const_int 1 [0x1]) repeated x2 (const_int 3 [0x3]) ]) (nil))) (set (mem) (reg:V4DI 168)) Then it ICE on: auto new_mode = smallest_int_mode_for_size (access_size * BITS_PER_UNIT); The access_size may be 24 or 32. We don't have such integer modes with these size so it ICE. TODO: The better way maybe make DSE use native_encode_rtx/native_decode_rtx but I don't know how to do that. So let's quickly fix this issue, we can improve the fix later. gcc/ChangeLog: * dse.cc (find_shift_sequence): Check the mode with access_size exist on the target. Authored-By: Richard Sandiford --- gcc/dse.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/dse.cc b/gcc/dse.cc index 8b07be17674..1a85dae1f8c 100644 --- a/gcc/dse.cc +++ b/gcc/dse.cc @@ -1733,7 +1733,8 @@ find_shift_sequence (poly_int64 access_size, /* If a constant was stored into memory, try to simplify it here, otherwise the cost of the shift might preclude this optimization e.g. at -Os, even when no actual shift will be needed. */ - if (store_info->const_rhs) + if (store_info->const_rhs + && known_le (access_size, GET_MODE_SIZE (MAX_MODE_INT))) { auto new_mode = smallest_int_mode_for_size (access_size * BITS_PER_UNIT); auto byte = subreg_lowpart_offset (new_mode, store_mode);