]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
x86: Handle REG_EH_REGION note in DEF_INSN
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 25 Jun 2025 04:50:53 +0000 (12:50 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 26 Jun 2025 06:01:04 +0000 (14:01 +0800)
For tcpsock_test.go in libgo tests,

commit aba3b9d3a48a0703fd565f7c5f0caf604f59970b
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri May 9 07:17:07 2025 +0800

    x86: Extend the remove_redundant_vector pass

added an instruction:

(insn 501 101 102 21 (set (reg:V2DI 234)
        (vec_duplicate:V2DI (reg:DI 111 [ _46 ]))) "tcpsock_test.go":691:12 discrim 1 -1
     (nil))

after

(insn 101 100 501 21 (set (reg:DI 111 [ _46 ])
        (mem:DI (reg/f:DI 110 [ _45 ]) [5 *_45+0 S8 A64])) "tcpsock_test.go":691:12 discrim 1 99 {*movdi_internal}
     (expr_list:REG_DEAD (reg/f:DI 110 [ _45 ])
        (expr_list:REG_EH_REGION (const_int 1 [0x1])
            (nil))))

which resulted in

(insn 101 100 501 21 (set (reg:DI 111 [ _46 ])
        (mem:DI (reg/f:DI 110 [ _45 ]) [5 *_45+0 S8 A64])) "tcpsock_test.go":691:12 discrim 1 99 {*movdi_internal}
     (expr_list:REG_DEAD (reg/f:DI 110 [ _45 ])
        (expr_list:REG_EH_REGION (const_int 1 [0x1])
            (nil))))
(insn 501 101 102 21 (set (reg:V2DI 234)
        (vec_duplicate:V2DI (reg:DI 111 [ _46 ]))) "tcpsock_test.go":691:12 discrim 1 -1
     (nil))

and caused:

tcpsock_test.go: In function 'net.TestTCPBig..func2':
tcpsock_test.go:684:28: error: in basic block 21:
  684 |                         go func() {
      |                            ^
tcpsock_test.go:684:28: error: flow control insn inside a basic block
(insn 101 100 501 21 (set (reg:DI 111 [ _46 ])
        (mem:DI (reg/f:DI 110 [ _45 ]) [5 *_45+0 S8 A64])) "tcpsock_test.go":691:12 discrim 1 99 {*movdi_internal}
     (expr_list:REG_DEAD (reg/f:DI 110 [ _45 ])
        (expr_list:REG_EH_REGION (const_int 1 [0x1])
            (nil))))
during RTL pass: rrvl
tcpsock_test.go:684:28: internal compiler error: in rtl_verify_bb_insns, at cfgrtl.cc:2834

Copy the REG_EH_REGION note to the newly added instruction and split the
block after the previous instruction.

PR target/120816
* config/i386/i386-features.cc (remove_redundant_vector_load):
Handle REG_EH_REGION note in DEF_INSN.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
gcc/config/i386/i386-features.cc

index be2ce3103dde6d4316927c8d00d6eaafeeaf0d89..d942bf08b56f0bcd9500ac7cc31490609bb0f622 100644 (file)
@@ -3820,6 +3820,8 @@ remove_redundant_vector_load (void)
 
   if (replaced)
     {
+      auto_vec<rtx_insn *> control_flow_insns;
+
       /* (Re-)discover loops so that bb->loop_father can be used in the
         analysis below.  */
       calculate_dominance_info (CDI_DOMINATORS);
@@ -3835,6 +3837,20 @@ remove_redundant_vector_load (void)
                rtx set = gen_rtx_SET (load->broadcast_reg,
                                       load->broadcast_source);
                insn = emit_insn_after (set, load->def_insn);
+
+               if (cfun->can_throw_non_call_exceptions)
+                 {
+                   /* Handle REG_EH_REGION note in DEF_INSN.  */
+                   rtx note = find_reg_note (load->def_insn,
+                                             REG_EH_REGION, nullptr);
+                   if (note)
+                     {
+                       control_flow_insns.safe_push (load->def_insn);
+                       add_reg_note (insn, REG_EH_REGION,
+                                     XEXP (note, 0));
+                     }
+                 }
+
                if (dump_file)
                  {
                    fprintf (dump_file, "\nAdd:\n\n");
@@ -3855,6 +3871,22 @@ remove_redundant_vector_load (void)
 
       loop_optimizer_finalize ();
 
+      if (!control_flow_insns.is_empty ())
+       {
+         free_dominance_info (CDI_DOMINATORS);
+
+         FOR_EACH_VEC_ELT (control_flow_insns, i, insn)
+           if (control_flow_insn_p (insn))
+             {
+               /* Split the block after insn.  There will be a fallthru
+                  edge, which is OK so we keep it.  We have to create
+                  the exception edges ourselves.  */
+               bb = BLOCK_FOR_INSN (insn);
+               split_block (bb, insn);
+               rtl_make_eh_edge (NULL, bb, BB_END (bb));
+             }
+       }
+
       df_process_deferred_rescans ();
     }