<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - failed to eliminate conditional memops"
   href="https://bugs.llvm.org/show_bug.cgi?id=39603">39603</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>failed to eliminate conditional memops
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This probably doesn't do anything for <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - vectorization differences"
   href="show_bug.cgi?id=39597">bug 39597</a>, but we're missing some
fundamental transforms before we get to anything more complicated:

void always_store(int* x, int exchangeVal) {
  *x = (*x != exchangeVal) ? exchangeVal : *x;
}

void never_store(int* x, int exchangeVal) {
  *x = (*x == exchangeVal) ? exchangeVal : *x;
}

void conditional_always_store(int* x, int exchangeVal) {
  if (*x != exchangeVal)
    *x = exchangeVal;
}

void conditional_never_store(int* x, int exchangeVal) {
  if (*x == exchangeVal)
    *x = exchangeVal;
}

<a href="https://godbolt.org/z/En099n">https://godbolt.org/z/En099n</a>

As optimized IR:

define void @always_store(i32* nocapture %x, i32 %exchangeVal) {
  store i32 %exchangeVal, i32* %x, align 4
  ret void
}


define void @never_store(i32* nocapture %x, i32 %exchangeVal) {
  ret void
}

define void @conditional_always_store(i32* nocapture %x, i32 %exchangeVal) {
entry:
  %0 = load i32, i32* %x, align 4
  %cmp = icmp eq i32 %0, %exchangeVal
  br i1 %cmp, label %if.end, label %if.then

if.then:                              
  store i32 %exchangeVal, i32* %x, align 4
  br label %if.end

if.end:                      
  ret void
}

define void @conditional_never_store(i32* nocapture %x, i32 %exchangeVal) {
entry:
  %0 = load i32, i32* %x, align 4
  %cmp = icmp eq i32 %0, %exchangeVal
  br i1 %cmp, label %if.then, label %if.end

if.then:       
  store i32 %exchangeVal, i32* %x, align 4
  br label %if.end

if.end:                   
  ret void
}</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>