This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Latent bug in simplify_unary_operation_1


While testing a change in gen_lowpart_or_truncate to call
simplify_gen_unary(TRUNCATE) instead of gen_rtx_TRUNCATE, I found a
latent bug.

If simplify_unary_operation_1 is invoked with TRUNCATE, SImode and
(subreg:DI (truncate:HI ...)) it returns (truncate:HI ...) which is
not in the requested mode.

The fix is to return the TRUNCATE expression in the requested mode.

I tested the patch by itself first and then with the other change
together initially triggering the problem.  The testing was done on
mipsisa64-elf and i686-pc-linux-gnu.

Is it OK to apply?

Adam

:ADDPATCH middle-end:

	* simplify-rtx.c (simplify_unary_operation_1 <TRUNCATE>): Return
	new expression in the requeted machine mode.

Index: simplify-rtx.c
===================================================================
*** simplify-rtx.c	(revision 110871)
--- simplify-rtx.c	(working copy)
*************** simplify_unary_operation_1 (enum rtx_cod
*** 609,620 ****
  	return simplify_gen_unary (GET_CODE (op), mode,
  				   XEXP (XEXP (op, 0), 0), mode);
  
!       /* (truncate:SI (subreg:DI (truncate:SI X) 0)) is
! 	 (truncate:SI x).  */
        if (GET_CODE (op) == SUBREG
  	  && GET_CODE (SUBREG_REG (op)) == TRUNCATE
  	  && subreg_lowpart_p (op))
! 	return SUBREG_REG (op);
  
        /* If we know that the value is already truncated, we can
           replace the TRUNCATE with a SUBREG if TRULY_NOOP_TRUNCATION
--- 609,621 ----
  	return simplify_gen_unary (GET_CODE (op), mode,
  				   XEXP (XEXP (op, 0), 0), mode);
  
!       /* (truncate:A (subreg:B (truncate:C X) 0)) is
! 	 (truncate:A X).  */
        if (GET_CODE (op) == SUBREG
  	  && GET_CODE (SUBREG_REG (op)) == TRUNCATE
  	  && subreg_lowpart_p (op))
! 	return simplify_gen_unary (TRUNCATE, mode, XEXP (SUBREG_REG (op), 0),
! 				   GET_MODE (XEXP (SUBREG_REG (op), 0)));
  
        /* If we know that the value is already truncated, we can
           replace the TRUNCATE with a SUBREG if TRULY_NOOP_TRUNCATION


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]