<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 --- - LICM incorrectly hoists load because Instruction::mayThrow does not correctly handle invokes" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24185&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=BPIem4qSzf9X_-q3qFddA3vjvEUGdTj_gmH1DUaP6i0&s=EhTH1lrGkoYyUWB2ExgQ6biGBlUzuz5MeSWTQdFr0Gw&e=">24185</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LICM incorrectly hoists load because Instruction::mayThrow does not correctly handle invokes
          </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>normal
          </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>sanjoy@playingwithpointers.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Running -licm on the following IR hoists the load of `%m` outside the loop. 
This is incorrect because it is possible that @f throws something that does not
unwind to `%right` (because the exception's type does not match `@_ZTIi`). 
Such a throw will exit the frame.  Thus, the load from %ptr is not executed on
all paths through the loop and cannot be safely speculated.

As far as I can tell, the bug is in Instruction::mayThrow -- LLVM cannot
certify that an `invoke` does not throw without analyzing all of its
landingpads.


target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.10.0"

@_ZTIi = external constant i8*

declare i32 @__gxx_personality_v0(...)

declare i32 @f(i32) readnone

define i32 @g(i32* %ptr) personality i8* bitcast (i32 (...)*
@__gxx_personality_v0 to i8*) {
 entry:
  br label %loop

 loop:
  %acc = phi i32  [ 0, %entry ], [ %acc.next, %merge ]
  %x = invoke i32 @f(i32 %acc) to label %left unwind label %right

 left:
  br label %merge

 right:
  %v = landingpad { i8*, i32 } catch i8* bitcast (i8** @_ZTIi to i8*)
  br label %merge

 merge:
  %vv = phi i32 [ %x, %left ], [ 0, %right]
  %m = load i32, i32* %ptr
  %acc.next = add i32 %m, %acc
  %c = icmp eq i32 %vv, 0
  br i1 %c, label %loop, label %exit

 exit:
  ret i32 %acc
}</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>