<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - The LoadCombine pass wrongly reorder load and store"
   href="https://llvm.org/bugs/show_bug.cgi?id=31517">31517</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>The LoadCombine pass wrongly reorder load and store
          </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>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </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>karl-johan.karlsson@ericsson.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=17800" name="attach_17800" title="opt -S -load-combine -adce -o - loadcombine.ll | FileCheck loadcombine.ll">attachment 17800</a> <a href="attachment.cgi?id=17800&action=edit" title="opt -S -load-combine -adce -o - loadcombine.ll | FileCheck loadcombine.ll">[details]</a></span>
opt -S -load-combine -adce -o - loadcombine.ll | FileCheck loadcombine.ll

Input code:

define i16 @bazinga() {
  %_tmp9 = getelementptr %rec11, %rec11* @str, i16 0, i32 1
  %_tmp10 = load i16, i16* %_tmp9
  %_tmp12 = getelementptr %rec11, %rec11* @str, i16 0, i32 0
  store i16 %_tmp10, i16* %_tmp12
  %_tmp13 = getelementptr %rec11, %rec11* @str, i16 0, i32 0
  %_tmp14 = load i16, i16* %_tmp13
  %_tmp15 = icmp eq i16 %_tmp14, 3
  %_tmp16 = select i1 %_tmp15, i16 1, i16 0
  br label %bb1

bb1:
  ret i16 %_tmp16
}

The load combiner can not reorder the three memory operations above (load,
store, load) as the first load will load the value from the second location in
the struct, the store will write the loaded value in the first location in the
struct and the last load will load a value from the second location in the
struct.

Output code:

define i16 @bazinga() {
  %_tmp14.combined = load i32, i32* bitcast (%rec11* @str to i32*)
  %combine.extract.shift = lshr i32 %_tmp14.combined, 16
  %combine.extract.trunc1 = trunc i32 %combine.extract.shift to i16
  %_tmp12 = getelementptr %rec11, %rec11* @str, i16 0, i32 0
  store i16 %combine.extract.trunc1, i16* %_tmp12
  %combine.extract.trunc = trunc i32 %_tmp14.combined to i16
  %_tmp15 = icmp eq i16 %combine.extract.trunc, 3
  %_tmp16 = select i1 %_tmp15, i16 1, i16 0
  br label %bb1

bb1:
  ret i16 %_tmp16
}

The load combine pass have combined the two loads and thereby reordered the
instructions as the store is done afterwards. Result is that the input value to
the icmp do not get the updated value written by the store.</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>