<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><span class="vcard"><a class="email" href="mailto:chandlerc@gmail.com" title="Chandler Carruth <chandlerc@gmail.com>"> <span class="fn">Chandler Carruth</span></a>
</span> changed
          <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - cmp+store is not optimized to an unconditional store"
   href="https://bugs.llvm.org/show_bug.cgi?id=38450">bug 38450</a>
          <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - cmp+store is not optimized to an unconditional store"
   href="https://bugs.llvm.org/show_bug.cgi?id=38450#c1">Comment # 1</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - cmp+store is not optimized to an unconditional store"
   href="https://bugs.llvm.org/show_bug.cgi?id=38450">bug 38450</a>
              from <span class="vcard"><a class="email" href="mailto:chandlerc@gmail.com" title="Chandler Carruth <chandlerc@gmail.com>"> <span class="fn">Chandler Carruth</span></a>
</span></b>
        <pre>(In reply to Gonzalo BG from <a href="show_bug.cgi?id=38450#c0">comment #0</a>)
<span class="quote">> See <a href="https://godbolt.org/g/5W5q2K">https://godbolt.org/g/5W5q2K</a> , the following LLVM-IR:

> define void @foo(i32* noalias nocapture dereferenceable(4) %x) {
> start:
>   %0 = load i32, i32* %x, align 4
>   %1 = icmp eq i32 %0, 0
>   br i1 %1, label %bb2, label %bb1

> bb1:
>   store i32 0, i32* %x, align 4
>   br label %bb2

> bb2:
>   ret void
> }

> does not optimize to anything better with opt -O3. Using llc, it generates
> the following x86_64 assembly code (<a href="https://godbolt.org/g/RX81Sn">https://godbolt.org/g/RX81Sn</a>): 

>     cmpl    $0, (%rdi)
>     je      .LBB0_2
>     movl    $0, (%rdi)
> .LBB0_2:  
>     retq

> I would expect this to just generate "movl $0, (%rdi); retq".</span >

LLVM's memory model precludes this -- it would introduce a store along a code
path that didn't originally have one.

The routine could be called with other threads concurrently reading the data
which is fine as long as the data is zero and thus no thread writes to the
data.

The analogous constraint also exists in C++'s memory model FWIW.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>