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]

[wwwdocs] "Deficiencies of GCC's optimizer" correction



The final section of the optimizer deficiencies WWW page covers
"suboptimal code for complex conditionals".  Unfortunately, the x86
sequence suggested as optimal is incorrect.  The "testl %ecx, %edx"
instruction on IA-32 performs a bitwise-and not a truthwise-and, so
cannot be used to implement C's && operator.  As a counter-example,
"and(2,4)" will produce the incorrect value zero with the proposed
implementation instead of the expected value 1.

The patch below simply removes the erroneous bits.  Ok to apply?
[Patch to improve code for complex conditionals in preparation :>]


Index: optimize.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/projects/optimize.html,v
retrieving revision 1.5
diff -c -3 -p -r1.5 optimize.html
*** optimize.html	25 Jan 2002 09:57:30 -0000	1.5
--- optimize.html	16 May 2002 23:08:46 -0000
*************** or:
*** 752,785 ****
          ret
  </pre>

! <p>Yay - no branches!  But this code is still not perfect.  For one
! thing, we fail to take advantage of the ability to test two registers
! at once.  For another, what are those trailing <code>andl</code>
! instructions doing there?</p>
!
! <p>Optimal code for this example would look something like:</p>
!
! <pre>
! and:
! 	movl	4(%esp), %edx
! 	movl	8(%esp), %ecx
! 	xorl	%eax, %eax
! 	testl	%ecx, %edx
! 	setne	%al
! 	ret
!
! or:
! 	movl	4(%esp), %edx
! 	xorl	%eax, %eax
! 	movl	8(%esp), %ecx
! 	notl	%edx
! 	notl	%ecx
! 	testl	%ecx, %edx
! 	sete	%al
! 	ret
! </pre>
!
! <p>The 'or' example uses the rule that <code>(a || b) == !(!a &amp;&amp; !b)</code>.</p>

  <p>The important scheduling considerations, for PPro/PII anyway, are
  to separate loads from uses by at least one instruction (assuming top
--- 752,758 ----
          ret
  </pre>

! <p>Yay - no branches!</p>

  <p>The important scheduling considerations, for PPro/PII anyway, are
  to separate loads from uses by at least one instruction (assuming top


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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