<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 - false positive: MD_misexpect is not updated after the branch condition is flipped"
   href="https://bugs.llvm.org/show_bug.cgi?id=45073">45073</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>false positive: MD_misexpect is not updated after the branch condition is flipped
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Transformation Utilities
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>wmi@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>We turned on -Wmisexpect and found some false positive warning. Here is a
testcase to show the problem. The cause is that MD_misexpect is not updated
after the branch condition is flipped. This looks like a general issue of
MD_misexpect. 

---------------- 1.ll --------------------
declare void @goo()
declare i64 @llvm.expect.i64(i64, i64)

define void @foo(i1 %t0) {
  %t1 = xor i1 %t0, true
  %t2 = zext i1 %t1 to i64
  %t4 = call i64 @llvm.expect.i64(i64 %t2, i64 0)
  %t3 = icmp ne i64 %t2, 0
  br i1 %t3, label %true, label %false, !prof !0, !misexpect !1

true:
  call void @goo()
  br label %false

false:
  ret void
}

!0 = !{!"branch_weights", i32 1, i32 2000}
!1 = !{!"misexpect", i64 1, i64 2000, i64 1} ====> misexpect predicts else
branch is hot, which matches with !prof !0.
------------------------------------------

~/workarea/llvm/build/d20200121/bin/opt -instcombine -S 1.ll

Note that the branch condition is flipped after instcombine.

; ModuleID = '1.ll'
source_filename = "1.ll"
declare void @goo()
; Function Attrs: nounwind readnone willreturn
declare i64 @llvm.expect.i64(i64, i64) #0
define void @foo(i1 %t0) {
  br i1 %t0, label %false, label %true, !prof !0, !misexpect !1

true:                                             ; preds = %0
  call void @goo()
  br label %false

false:                                            ; preds = %0, %true
  ret void
}

attributes #0 = { nounwind readnone willreturn }

!0 = !{!"branch_weights", i32 2000, i32 1}
!1 = !{!"misexpect", i64 1, i64 2000, i64 1} ====> misexpect still predicts
else branch is hot, which contradicts with !prof !0.</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>