<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 - [licm] LICM cannot hoist load of global with llvm.invariant.start"
   href="https://bugs.llvm.org/show_bug.cgi?id=38933">38933</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[licm] LICM cannot hoist load of global with llvm.invariant.start
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Loop Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>mpfergu@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I have a global variable and have marked it with llvm.invariant.start.
I would expect LICM to hoist the load of the global variable out of a loop
under these conditions, but it does not.

One potential issue is that isLoadInvariantInLoop only handles the case when
the load address refers one or more bitcast instructions, which is not true in
this example.

Try this with opt test.ll -licm -S


@chpl_privateObjects = external dso_local global i8**, align 8

declare void @foo()

declare {}* @llvm.invariant.start.p0i8(i64, i8* nocapture) nounwind readonly
declare void @llvm.invariant.end.p0i8({}*, i64, i8* nocapture) nounwind

define i8 @test_licm_global(i32 %n) {

entry:
  %invst = tail call {}* @llvm.invariant.start.p0i8(i64 8, i8* bitcast (i8***
@chpl_privateObjects to i8*)) #4
  br label %loop

loop:
  %indvar = phi i32 [ %indvar.next, %loop ], [ 0, %entry ]
  %sum = phi i8 [ %sum.next, %loop ], [ 0, %entry ]

  %g = load i8**, i8*** @chpl_privateObjects, align 8
  %p = load i8*, i8** %g, align 8
  %v = load i8, i8* %p, align 8

  call void @foo()

  %sum.next = add i8 %v, %sum
  %indvar.next = add i32 %indvar, 1
  %cond = icmp slt i32 %indvar.next, %n
  br i1 %cond, label %loop, label %loopexit

loopexit:
  ret i8 %sum
}

attributes #4 = { nounwind }</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>