<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 --- - GVN hoists a store across a load"
   href="https://llvm.org/bugs/show_bug.cgi?id=28874">28874</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>GVN hoists a store across a load
          </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>kparzysz@codeaurora.org
          </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>Run with:
opt -mtriple=hexagon -gvn-hoist -S < gvnhoist.ll


Before GVN hoist, if.then468 contains these instructions (abbreviated):
  %arrayidx473 = ...
  %.t104 = load i32, i32* %arrayidx473, align 4, !tbaa !7
  ...
  store i32 0, i32* %arrayidx473, align 4, !tbaa !7

That is, the load happens before the store. There is another store that happens
on the other side of the conditional branch so the fact that is moves a store
from a side node is not a problem.  After GVN hoist, the store is moved up to
for.body463 and now happens before the load.



Code before GVN hoist:

for.body463:                                      ; preds = %for.cond460
  %.t464 = getelementptr inbounds %struct.s0, %struct.s0* %s0, i32 0, i32 20
  %arrayidx465 = getelementptr inbounds [6 x i32], [6 x i32]* %.t464, i32 0,
i32 %n.4
  %.t102 = load i32, i32* %arrayidx465, align 4, !tbaa !7
  %and466 = and i32 %.t102, 32768
  %tobool467 = icmp ne i32 %and466, 0
  br i1 %tobool467, label %if.then468, label %if.else573

if.then468:                                       ; preds = %for.body463
  %.d1 = getelementptr inbounds %struct.s0, %struct.s0* %s0, i32 0, i32 125
  %.t103 = load i16, i16* %.d1, align 4, !tbaa !31
  %conv469 = sext i16 %.t103 to i32
  %arrayidx470 = getelementptr inbounds [6 x %struct.s1], [6 x %struct.s1]*
@s1, i32 0, i32 %n.4
  %.t471 = getelementptr inbounds %struct.s1, %struct.s1* %arrayidx470, i32 0,
i32 62
  %arrayidx472 = getelementptr inbounds [7 x [32 x i32]], [7 x [32 x i32]]*
%.t471, i32 0, i32 1
  %arrayidx473 = getelementptr inbounds [32 x i32], [32 x i32]* %arrayidx472,
i32 0, i32 %.t2
  %.t104 = load i32, i32* %arrayidx473, align 4, !tbaa !7
  %mul474 = mul nsw i32 %conv469, %.t104
  %arrayidx479 = getelementptr inbounds [7 x [32 x i32]], [7 x [32 x i32]]*
%.t471, i32 0, i32 2
  %arrayidx480 = getelementptr inbounds [32 x i32], [32 x i32]* %arrayidx479,
i32 0, i32 %.t2
  %.t105 = load i32, i32* %arrayidx480, align 4, !tbaa !7
  %mul481 = mul nsw i32 %conv469, %.t105
  store i32 0, i32* %arrayidx473, align 4, !tbaa !7
  store i32 0, i32* %arrayidx480, align 4, !tbaa !7
  %.q1 = getelementptr inbounds %struct.s0, %struct.s0* %s0, i32 0, i32 126
  %.t106 = load i16, i16* %.q1, align 2, !tbaa !32
  %conv490 = sext i16 %.t106 to i32
  %or491 = or i32 16, %.t2


After GVN hoist:

for.body463:                                      ; preds = %for.cond460
  %.t464 = getelementptr inbounds %struct.s0, %struct.s0* %s0, i32 0, i32 20
  %arrayidx465 = getelementptr inbounds [6 x i32], [6 x i32]* %.t464, i32 0,
i32 %n.4
  %.t102 = load i32, i32* %arrayidx465, align 4, !tbaa !6
  %and466 = and i32 %.t102, 32768
  %tobool467 = icmp ne i32 %and466, 0
  %or491 = or i32 16, %.t2
  %0 = getelementptr inbounds [6 x %struct.s1], [6 x %struct.s1]* @s1, i32 0,
i32 %n.4
  %1 = getelementptr inbounds %struct.s1, %struct.s1* %0, i32 0, i32 62
  %2 = getelementptr inbounds [7 x [32 x i32]], [7 x [32 x i32]]* %1, i32 0,
i32 1
  %3 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i32 0, i32 %.t2
  store i32 0, i32* %3, align 4, !tbaa !6
  br i1 %tobool467, label %if.then468, label %if.else573

if.then468:                                       ; preds = %for.body463
  %.d1 = getelementptr inbounds %struct.s0, %struct.s0* %s0, i32 0, i32 125
  %.t103 = load i16, i16* %.d1, align 4, !tbaa !7
  %conv469 = sext i16 %.t103 to i32
  %arrayidx470 = getelementptr inbounds [6 x %struct.s1], [6 x %struct.s1]*
@s1, i32 0, i32 %n.4
  %.t471 = getelementptr inbounds %struct.s1, %struct.s1* %arrayidx470, i32 0,
i32 62
  %arrayidx472 = getelementptr inbounds [7 x [32 x i32]], [7 x [32 x i32]]*
%.t471, i32 0, i32 1
  %arrayidx473 = getelementptr inbounds [32 x i32], [32 x i32]* %arrayidx472,
i32 0, i32 %.t2
  %.t104 = load i32, i32* %arrayidx473, align 4, !tbaa !6
  %mul474 = mul nsw i32 %conv469, %.t104
  %arrayidx479 = getelementptr inbounds [7 x [32 x i32]], [7 x [32 x i32]]*
%.t471, i32 0, i32 2
  %arrayidx480 = getelementptr inbounds [32 x i32], [32 x i32]* %arrayidx479,
i32 0, i32 %.t2
  %.t105 = load i32, i32* %arrayidx480, align 4, !tbaa !6
  %mul481 = mul nsw i32 %conv469, %.t105
  store i32 0, i32* %arrayidx480, align 4, !tbaa !6
  %.q1 = getelementptr inbounds %struct.s0, %struct.s0* %s0, i32 0, i32 126
  %.t106 = load i16, i16* %.q1, align 2, !tbaa !8
  %conv490 = sext i16 %.t106 to i32</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>