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]

Re: [bugs] a gcc sign bug?


> gcc will generate:
> 
> itsabug:
> .LFB1:
>         pushq   %rbp
> .LCFI0:
>         movq    %rsp, %rbp
> .LCFI1:
>         movq    kva_start(%rip), %rsi
>         subq    $2147483648, %rsi
> 		^^^^^^^^^^^
>         movl    $.LC0, %edi
>         movb    $0, %al
>         call    printf
>         popq    %rbp
> .LCFI2:
>         ret
the patch fixes it by converting subq to addq, in same way as we keep -128
as addq.

Thu May 31 12:52:38 CEST 2001  Jan Hubicka  <jh@suse.cz>

	* i386.md (addqi* output templates): Avoid possible overflow
	when converting add to sub.

Index: i386.md
===================================================================
RCS file: /home/cvs/Repository/gcc/gcc/config/i386/i386.md,v
retrieving revision 1.72
diff -c -3 -p -r1.72 i386.md
*** i386.md	2001/05/26 00:00:57	1.72
--- i386.md	2001/05/31 09:51:30
***************
*** 5618,5623 ****
--- 5618,5625 ----
        /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
  	 Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
        if (GET_CODE (operands[2]) == CONST_INT
+ 	  /* Avoid overflows.  */
+ 	  && ((INTVAL (operands[2]) & ((1 << 31) - 1)))
            && (INTVAL (operands[2]) == 128
  	      || (INTVAL (operands[2]) < 0
  		  && INTVAL (operands[2]) != -128)))
***************
*** 5689,5694 ****
--- 5691,5698 ----
        /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
  	 Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
        if (GET_CODE (operands[2]) == CONST_INT
+ 	  /* Avoid overflows.  */
+ 	  && ((INTVAL (operands[2]) & ((1 << 31) - 1)))
            && (INTVAL (operands[2]) == 128
  	      || (INTVAL (operands[2]) < 0
  		  && INTVAL (operands[2]) != -128)))
***************
*** 5738,5743 ****
--- 5742,5749 ----
        /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
  	 Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
        if (GET_CODE (operands[2]) == CONST_INT
+ 	  /* Avoid overflows.  */
+ 	  && ((INTVAL (operands[2]) & ((1 << 31) - 1)))
            && (INTVAL (operands[2]) == 128
  	      || (INTVAL (operands[2]) < 0
  		  && INTVAL (operands[2]) != -128)))
***************
*** 5788,5794 ****
  	 Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
        if ((INTVAL (operands[2]) == -128
  	   || (INTVAL (operands[2]) > 0
! 	       && INTVAL (operands[2]) != 128)))
  	return \"sub{q}\\t{%2, %0|%0, %2}\";
        operands[2] = GEN_INT (-INTVAL (operands[2]));
        return \"add{q}\\t{%2, %0|%0, %2}\";
--- 5794,5802 ----
  	 Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
        if ((INTVAL (operands[2]) == -128
  	   || (INTVAL (operands[2]) > 0
! 	       && INTVAL (operands[2]) != 128))
! 	  /* Avoid overflows.  */
! 	  && ((INTVAL (operands[2]) & ((1 << 31) - 1))))
  	return \"sub{q}\\t{%2, %0|%0, %2}\";
        operands[2] = GEN_INT (-INTVAL (operands[2]));
        return \"add{q}\\t{%2, %0|%0, %2}\";
***************
*** 5833,5838 ****
--- 5841,5848 ----
        /* Make things pretty and `subl $4,%eax' rather than `addl $-4, %eax'.
  	 Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
        if (GET_CODE (operands[2]) == CONST_INT
+ 	  /* Avoid overflows.  */
+ 	  && ((INTVAL (operands[2]) & ((1 << 31) - 1)))
            && (INTVAL (operands[2]) == 128
  	      || (INTVAL (operands[2]) < 0
  		  && INTVAL (operands[2]) != -128)))


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