<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Better optimize 'if' with ternaries conditional tests."
   href="https://bugs.webkit.org/show_bug.cgi?id=144136#c5">Comment # 5</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Better optimize 'if' with ternaries conditional tests."
   href="https://bugs.webkit.org/show_bug.cgi?id=144136">bug 144136</a>
              from <span class="vcard"><a class="email" href="mailto:fpizlo&#64;apple.com" title="Filip Pizlo &lt;fpizlo&#64;apple.com&gt;"> <span class="fn">Filip Pizlo</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=144136#c4">comment #4</a>)
<span class="quote">&gt; (In reply to <a href="show_bug.cgi?id=144136#c1">comment #1</a>)
&gt; &gt; This might be a hole in LLVM's CFG transforms.  It might also just be a
&gt; &gt; matter of running some LLVM phase that we currently fail to run.
&gt; &gt; 
&gt; &gt; What about the generated machine code for &quot;if (a?b:0)&quot; is better than the
&gt; &gt; code for &quot;if (a &amp;&amp; b)&quot;?
&gt; 
&gt; The main loops for the two attached examples:
&gt; 
&gt; slow:
&gt;       0x7f198a000330: movzbl  %bl, %eax
&gt;       0x7f198a000333: movzbl  (%rax,%r15), %ecx
&gt;       0x7f198a000338: cmpl    $1, %ecx
&gt;       0x7f198a00033b: jne     0x7f198a000370
&gt;       0x7f198a00033d: movzbl  1(%rax,%r15), %ecx
&gt;       0x7f198a000343: cmpl    $2, %ecx
&gt;       0x7f198a000346: jne     0x7f198a000370
&gt;       0x7f198a000348: movzbl  2(%rax,%r15), %ecx
&gt;       0x7f198a00034e: cmpl    $3, %ecx
&gt;       0x7f198a000351: jne     0x7f198a000370
&gt;       0x7f198a000353: movzbl  3(%rax,%r15), %eax
&gt;       0x7f198a000359: cmpl    $4, %eax
&gt;       0x7f198a00035c: sete    %al
&gt;       0x7f198a00035f: movzbl  %al, %eax</span >

Oh wow, this sequence is really dumb.

<span class="quote">&gt;       0x7f198a000362: jmp     0x7f198a000390
&gt;       0x7f198a000364: nopw    %cs:(%rax,%rax)
&gt;       0x7f198a000370: movl    $2147483648, 36(%rbp)
&gt;       0x7f198a000377: leaq    131779232(%r15), %rax
&gt;       0x7f198a00037e: movq    %rbp, %rdi
&gt;       0x7f198a000381: movq    %r14, %rsi
&gt;       0x7f198a000384: callq   *%rax
&gt;       0x7f198a000386: cmpq    $0, -2216120(%r15)
&gt;       0x7f198a00038e: jne     0x7f198a0003b6
&gt;       0x7f198a000390: testq   %rax, %rax
&gt;       0x7f198a000393: cmovnel %r13d, %r12d</span >

Yuck!

<span class="quote">&gt;       0x7f198a000397: incl    %ebx
&gt;       0x7f198a000399: cmpl    $1000000000, %ebx
&gt;       0x7f198a00039f: jl      0x7f198a000330
&gt; 
&gt; fast:
&gt;       0x7f81720002e0: movzbl  %cl, %edi
&gt;       0x7f81720002e3: movzbl  (%rdi,%rax), %esi
&gt;       0x7f81720002e7: cmpl    $1, %esi
&gt;       0x7f81720002ea: jne     0x7f8172000320
&gt;       0x7f81720002ec: movzbl  1(%rdi,%rax), %esi
&gt;       0x7f81720002f1: cmpl    $2, %esi
&gt;       0x7f81720002f4: jne     0x7f8172000320
&gt;       0x7f81720002f6: movzbl  2(%rdi,%rax), %esi
&gt;       0x7f81720002fb: cmpl    $3, %esi
&gt;       0x7f81720002fe: jne     0x7f8172000320
&gt;       0x7f8172000300: movzbl  3(%rdi,%rax), %esi
&gt;       0x7f8172000305: movl    $1, %edi
&gt;       0x7f817200030a: cmpl    $4, %esi
&gt;       0x7f817200030d: je      0x7f8172000311
&gt;       0x7f817200030f: movl    %edx, %edi
&gt;       0x7f8172000311: movl    %edi, %edx
&gt;       0x7f8172000313: nopw    %cs:(%rax,%rax)
&gt;       0x7f8172000320: incl    %ecx
&gt;       0x7f8172000322: cmpl    $1000000000, %ecx
&gt;       0x7f8172000328: jl      0x7f81720002e0</span >

Yup, LLVM bug.  Maybe we can work around it - but it seems that this should be fixed in LLVM.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>