public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] DSE: Fix ICE when the mode with access_size don't exist on the target[PR111590]
@ 2023-09-26 22:47 Juzhe-Zhong
  2023-09-27  8:23 ` Richard Sandiford
  0 siblings, 1 reply; 2+ messages in thread
From: Juzhe-Zhong @ 2023-09-26 22:47 UTC (permalink / raw)
  To: gcc-patches; +Cc: richard.sandiford, Juzhe-Zhong

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 <richard.sandiford@arm.com>

---
 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);
-- 
2.36.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] DSE: Fix ICE when the mode with access_size don't exist on the target[PR111590]
  2023-09-26 22:47 [PATCH] DSE: Fix ICE when the mode with access_size don't exist on the target[PR111590] Juzhe-Zhong
@ 2023-09-27  8:23 ` Richard Sandiford
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Sandiford @ 2023-09-27  8:23 UTC (permalink / raw)
  To: Juzhe-Zhong; +Cc: gcc-patches

Juzhe-Zhong <juzhe.zhong@rivai.ai> writes:
> 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.

OK, thanks, but...

> Authored-By: Richard Sandiford <richard.sandiford@arm.com>

...it was just a review comment.  I didn't write the patch.

Richard

>
> ---
>  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);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-09-27  8:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-26 22:47 [PATCH] DSE: Fix ICE when the mode with access_size don't exist on the target[PR111590] Juzhe-Zhong
2023-09-27  8:23 ` Richard Sandiford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).