fix target/18841

Richard Henderson rth@twiddle.net
Sun Dec 5 20:10:00 GMT 2004


There's a bit of commentary about the bug in the pr.  Basically,
the solution is to delay splitting of these receivers until after
reload, when the rest of the uses of $gp are exposed.


r~


        * config/alpha/alpha.md (UNSPECV_SETJMPR_ER): New.
        (builtin_setjmp_receiver_er_sl_1): Use it.
        (builtin_setjmp_receiver_er_1): Likewise.
        (builtin_setjmp_receiver_er, exception_receiver_er): Remove.
        (builtin_setjmp_receiver): Don't split for explicit relocs until
        after reload.
        (exception_receiver): Likewise.

Index: config/alpha/alpha.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/alpha/alpha.md,v
retrieving revision 1.228
diff -c -p -d -r1.228 alpha.md
*** config/alpha/alpha.md	24 Nov 2004 19:45:07 -0000	1.228
--- config/alpha/alpha.md	5 Dec 2004 19:44:38 -0000
***************
*** 77,82 ****
--- 77,83 ----
     (UNSPECV_PLDGP2	11)	; prologue ldgp
     (UNSPECV_SET_TP	12)
     (UNSPECV_RPCC	13)
+    (UNSPECV_SETJMPR_ER	14)	; builtin_setjmp_receiver fragment
    ])
  
  ;; Where necessary, the suffixes _le and _be are used to distinguish between
***************
*** 6780,6849 ****
    "jmp $31,(%0),0"
    [(set_attr "type" "ibr")])
  
! (define_insn "*builtin_setjmp_receiver_er_sl_1"
!   [(unspec_volatile [(label_ref (match_operand 0 "" ""))] UNSPECV_SETJMPR)]
!   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF && TARGET_AS_CAN_SUBTRACT_LABELS"
!   "lda $27,$LSJ%=-%l0($27)\n$LSJ%=:")
!   
! (define_insn "*builtin_setjmp_receiver_er_1"
!   [(unspec_volatile [(label_ref (match_operand 0 "" ""))] UNSPECV_SETJMPR)]
!   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF"
!   "br $27,$LSJ%=\n$LSJ%=:"
!   [(set_attr "type" "ibr")])
! 
! (define_split
!   [(unspec_volatile [(label_ref (match_operand 0 "" ""))] UNSPECV_SETJMPR)]
!   "TARGET_EXPLICIT_RELOCS && TARGET_ABI_OSF
!    && prev_nonnote_insn (insn) == operands[0]"
!   [(const_int 0)]
!   "
! {
!   emit_note (NOTE_INSN_DELETED);
!   DONE;
! }")
! 
! (define_insn "*builtin_setjmp_receiver_1"
    [(unspec_volatile [(label_ref (match_operand 0 "" ""))] UNSPECV_SETJMPR)]
    "TARGET_ABI_OSF"
!   "br $27,$LSJ%=\n$LSJ%=:\;ldgp $29,0($27)"
!   [(set_attr "length" "12")
!    (set_attr "type" "multi")])
  
! (define_expand "builtin_setjmp_receiver_er"
!   [(unspec_volatile [(label_ref (match_operand 0 "" ""))] UNSPECV_SETJMPR)
!    (set (match_dup 1)
  	(unspec_volatile:DI [(match_dup 2) (match_dup 3)] UNSPECV_LDGP1))
     (set (match_dup 1)
  	(unspec:DI [(match_dup 1) (match_dup 3)] UNSPEC_LDGP2))]
-   ""
  {
    operands[1] = pic_offset_table_rtx;
    operands[2] = gen_rtx_REG (Pmode, 27);
    operands[3] = GEN_INT (alpha_next_sequence_number++);
! })
! 
! (define_expand "builtin_setjmp_receiver"
!   [(unspec_volatile [(label_ref (match_operand 0 "" ""))] UNSPECV_SETJMPR)]
!   "TARGET_ABI_OSF"
! {
!   if (TARGET_EXPLICIT_RELOCS)
!     {
!       emit_insn (gen_builtin_setjmp_receiver_er (operands[0]));
!       DONE;
!     }
! })
  
! (define_expand "exception_receiver_er"
!   [(set (match_dup 0)
! 	(unspec_volatile:DI [(match_dup 1) (match_dup 2)] UNSPECV_LDGP1))
!    (set (match_dup 0)
! 	(unspec:DI [(match_dup 0) (match_dup 2)] UNSPEC_LDGP2))]
!   ""
! {
!   operands[0] = pic_offset_table_rtx;
!   operands[1] = gen_rtx_REG (Pmode, 26);
!   operands[2] = GEN_INT (alpha_next_sequence_number++);
! })
  
  (define_expand "exception_receiver"
    [(unspec_volatile [(match_dup 0)] UNSPECV_EHR)]
--- 6781,6826 ----
    "jmp $31,(%0),0"
    [(set_attr "type" "ibr")])
  
! (define_expand "builtin_setjmp_receiver"
    [(unspec_volatile [(label_ref (match_operand 0 "" ""))] UNSPECV_SETJMPR)]
    "TARGET_ABI_OSF"
!   "")
  
! (define_insn_and_split "*builtin_setjmp_receiver_1"
!   [(unspec_volatile [(match_operand 0 "" "")] UNSPECV_SETJMPR)]
!   "TARGET_ABI_OSF"
! {
!   if (TARGET_EXPLICIT_RELOCS)
!     return "#";
!   else
!     return "br $27,$LSJ%=\n$LSJ%=:\;ldgp $29,0($27)";
! }
!   "&& TARGET_EXPLICIT_RELOCS && reload_completed"
!   [(set (match_dup 1)
  	(unspec_volatile:DI [(match_dup 2) (match_dup 3)] UNSPECV_LDGP1))
     (set (match_dup 1)
  	(unspec:DI [(match_dup 1) (match_dup 3)] UNSPEC_LDGP2))]
  {
+   if (prev_nonnote_insn (curr_insn) != XEXP (operands[0], 0))
+     emit_insn (gen_rtx_UNSPEC_VOLATILE (VOIDmode, gen_rtvec (1, operands[0]),
+ 					UNSPECV_SETJMPR_ER));
    operands[1] = pic_offset_table_rtx;
    operands[2] = gen_rtx_REG (Pmode, 27);
    operands[3] = GEN_INT (alpha_next_sequence_number++);
! }
!   [(set_attr "length" "12")
!    (set_attr "type" "multi")])
  
! (define_insn "*builtin_setjmp_receiver_er_sl_1"
!   [(unspec_volatile [(match_operand 0 "" "")] UNSPECV_SETJMPR_ER)]
!   "TARGET_ABI_OSF && TARGET_EXPLICIT_RELOCS && TARGET_AS_CAN_SUBTRACT_LABELS"
!   "lda $27,$LSJ%=-%l0($27)\n$LSJ%=:")
!   
! (define_insn "*builtin_setjmp_receiver_er_1"
!   [(unspec_volatile [(match_operand 0 "" "")] UNSPECV_SETJMPR_ER)]
!   "TARGET_ABI_OSF && TARGET_EXPLICIT_RELOCS"
!   "br $27,$LSJ%=\n$LSJ%=:"
!   [(set_attr "type" "ibr")])
  
  (define_expand "exception_receiver"
    [(unspec_volatile [(match_dup 0)] UNSPECV_EHR)]
***************
*** 6851,6878 ****
  {
    if (TARGET_LD_BUGGY_LDGP)
      operands[0] = alpha_gp_save_rtx ();
-   else if (TARGET_EXPLICIT_RELOCS)
-     {
-       emit_insn (gen_exception_receiver_er ());
-       DONE;
-     }
    else
      operands[0] = const0_rtx;
  })
  
- (define_insn "*exception_receiver_1"
-   [(unspec_volatile [(const_int 0)] UNSPECV_EHR)]
-   "! TARGET_LD_BUGGY_LDGP"
-   "ldgp $29,0($26)"
-   [(set_attr "length" "8")
-    (set_attr "type" "multi")])
- 
  (define_insn "*exception_receiver_2"
    [(unspec_volatile [(match_operand:DI 0 "memory_operand" "m")] UNSPECV_EHR)]
!   "TARGET_LD_BUGGY_LDGP"
    "ldq $29,%0"
    [(set_attr "type" "ild")])
  
  (define_expand "nonlocal_goto_receiver"
    [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
     (set (reg:DI 27) (mem:DI (reg:DI 29)))
--- 6828,6865 ----
  {
    if (TARGET_LD_BUGGY_LDGP)
      operands[0] = alpha_gp_save_rtx ();
    else
      operands[0] = const0_rtx;
  })
  
  (define_insn "*exception_receiver_2"
    [(unspec_volatile [(match_operand:DI 0 "memory_operand" "m")] UNSPECV_EHR)]
!   "TARGET_ABI_OSF && TARGET_LD_BUGGY_LDGP"
    "ldq $29,%0"
    [(set_attr "type" "ild")])
  
+ (define_insn_and_split "*exception_receiver_1"
+   [(unspec_volatile [(const_int 0)] UNSPECV_EHR)]
+   "TARGET_ABI_OSF"
+ {
+   if (TARGET_EXPLICIT_RELOCS)
+     return "ldah $29,0($26)\t\t!gpdisp!%*\;lda $29,0($29)\t\t!gpdisp!%*";
+   else
+     return "ldgp $29,0($26)";
+ }
+   "&& TARGET_EXPLICIT_RELOCS && reload_completed"
+   [(set (match_dup 0)
+ 	(unspec_volatile:DI [(match_dup 1) (match_dup 2)] UNSPECV_LDGP1))
+    (set (match_dup 0)
+ 	(unspec:DI [(match_dup 0) (match_dup 2)] UNSPEC_LDGP2))]
+ {
+   operands[0] = pic_offset_table_rtx;
+   operands[1] = gen_rtx_REG (Pmode, 26);
+   operands[2] = GEN_INT (alpha_next_sequence_number++);
+ }
+   [(set_attr "length" "8")
+    (set_attr "type" "multi")])
+ 
  (define_expand "nonlocal_goto_receiver"
    [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
     (set (reg:DI 27) (mem:DI (reg:DI 29)))
Index: testsuite/g++.dg/opt/eh3.C
===================================================================
RCS file: testsuite/g++.dg/opt/eh3.C
diff -N testsuite/g++.dg/opt/eh3.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/opt/eh3.C	5 Dec 2004 20:03:48 -0000
***************
*** 0 ****
--- 1,33 ----
+ // PR target/18841
+ // { dg-do run }
+ // { dg-options "-O2" }
+ 
+ extern "C" void abort ();
+ 
+ int r, i1 = 1, i2 = 2, i3 = 3, i4 = 4, i5 = 5;
+ 
+ struct S
+ {
+   ~S() { r = i1 + i2 + i3 + i4 + i5; }
+ };
+ 
+ void foo()
+ {
+   S s;
+   throw 1;
+ }
+ 
+ void bar()
+ {
+   try {
+     foo();
+   } catch (...) {
+   }
+ }
+ 
+ int main()
+ {
+   bar();
+   if (r != 1 + 2 + 3 + 4 + 5)
+     abort ();
+ }



More information about the Gcc-patches mailing list