cse.c patch for IA-64 abort on optimizable switch statement

Jim Wilson wilson@cygnus.com
Fri Aug 25 14:56:00 GMT 2000


This fixes an abort that shows up in the IA-64 compiler when compiling a
testcase with a switch statement that can be optimized away, and the
testcase uses a constant pool entry before the switch statment.  cse reduces
a switch table reference to (const (minus (label_ref) (label_ref))), then
passes it to force_const_mem, which eventually calls decode_rtx_const,
and that aborts because it doesn't handle constants of this form.

The same situation happens on the alpha, except that we never call
force_const_mem because we get (const (truncate ...)) which is rejected.
Thus a reasonable fix is to also reject the IA-64 case which doesn't have
the truncate.
	
2000-08-25  Jim Wilson  <wilson@cygnus.com>

	* cse.c (cse_insn): Don't pass label subtraction to force_const_mem.

Index: cse.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cse.c,v
retrieving revision 1.152
diff -p -r1.152 cse.c
*** cse.c	2000/08/23 07:59:06	1.152
--- cse.c	2000/08/25 21:49:16
*************** cse_insn (insn, libcall_insn)
*** 5328,5335 ****
--- 5328,5343 ----
  
  	  else if (constant_pool_entries_cost
  		   && CONSTANT_P (trial)
+ 		   /* Reject cases that will abort in decode_rtx_const.
+ 		      On the alpha when simplifying a switch, we get
+ 		      (const (truncate (minus (label_ref) (label_ref)))).  */
  		   && ! (GET_CODE (trial) == CONST
  			 && GET_CODE (XEXP (trial, 0)) == TRUNCATE)
+ 		   /* Likewise on IA-64, except without the truncate.  */
+ 		   && ! (GET_CODE (trial) == CONST
+ 			 && GET_CODE (XEXP (trial, 0)) == MINUS
+ 			 && GET_CODE (XEXP (XEXP (trial, 0), 0)) == LABEL_REF
+ 			 && GET_CODE (XEXP (XEXP (trial, 0), 1)) == LABEL_REF)
  		   && (src_folded == 0
  		       || (GET_CODE (src_folded) != MEM
  			   && ! src_folded_force_flag))

Testcase:

float d;

sub ()
{
  int i = 10;
  float e;

  e = 10.03;
  d = e;

  switch (i)
    {
    case 0:
    case 100:
      return 2;

    case 1:
    case 101:
      return 3;

    case 2:
    case 102:
      return 4;

    case 3:
    case 103:
      return 5;

    case 5:
    case 105:
      return 6;

    case 6:
    case 106:
      return 8;

    default:
      return 10;
    }
}


More information about the Gcc-patches mailing list