<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 - Miscompilation with `-jump-threading -correlated-propagation` and llvm.assume"
   href="https://bugs.llvm.org/show_bug.cgi?id=33917">33917</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Miscompilation with `-jump-threading -correlated-propagation` and llvm.assume
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>5.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>alex@crichton.co
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In upgrading rust-lang/rust to LLVM 5.0 we've discovered that the compiler
itself will segfault when compiled with LLVM 5.0. This looks like it's a
misoptimization during one of the `-jump-threading -correlated-propagation`
passes.

We used `bugpoint` to shorten the program from ~1 million lines of IR to just a
few:


; ModuleID = 'small.ll'
source_filename = "bugpoint-output-834ffe1.bc"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

declare i8* @foo()

declare i32 @rust_eh_personality() unnamed_addr

; Function Attrs: nounwind
declare void @llvm.assume(i1) #0

define void @bar() personality i32 ()* @rust_eh_personality {
bb9:
  %t9 = invoke i8* @foo()
          to label %good unwind label %bad

bad:                                              ; preds = %bb9
  %t10 = landingpad { i8*, i32 }
          cleanup
  resume { i8*, i32 } %t10

good:                                             ; preds = %bb9
  %t11 = icmp ne i8* %t9, null
  %t12 = zext i1 %t11 to i64
  %cond = icmp eq i64 %t12, 1
  br i1 %cond, label %if_true, label %done

if_true:                                          ; preds = %good
  call void @llvm.assume(i1 %t11)
  br label %done

done:                                             ; preds = %if_true, %good
  ret void
}

attributes #0 = { nounwind }




This was tested out locally via `opt -S -jump-threading -correlated-propagation
foo.ll`, and then the results from before/after were diffed, yielding:



--- before.ll   2017-07-24 15:52:48.364787248 -0700
+++ after.ll    2017-07-24 15:53:34.701537275 -0700
@@ -21,13 +21,12 @@
   resume { i8*, i32 } %t10

 good:                                             ; preds = %bb9
-  %t11 = icmp ne i8* %t9, null
-  %t12 = zext i1 %t11 to i64
+  %t12 = zext i1 true to i64
   %cond = icmp eq i64 %t12, 1
   br i1 %cond, label %if_true, label %done

 if_true:                                          ; preds = %good
-  call void @llvm.assume(i1 %t11)
+  call void @llvm.assume(i1 true)
   br label %done

 done:                                             ; preds = %if_true, %good




I think that the transformation here may be invalid? The `%t11` temporary is
inferred to being always `true` but that's not always the case coming out of
`@foo`</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>