<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 --- - [SimplifyCFG] branch weights are not preserved when forming select"
   href="https://llvm.org/bugs/show_bug.cgi?id=26636">26636</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[SimplifyCFG] branch weights are not preserved when forming select
          </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>Transformation Utilities
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>spatel+llvm@rotateright.com
          </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>The conditional branch has profile weight metadata:

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

define i32 @foo(i32 %x) #0 {
entry:
  %cmp = icmp sgt i32 %x, 4
  br i1 %cmp, label %if.then, label %if.end, !prof !0

if.then:
  %add = add nsw i32 %x, 7
  br label %return

if.end:
  %mul = mul nsw i32 %x, 17
  br label %return

return:
  %retval.0 = phi i32 [ %add, %if.then ], [ %mul, %if.end ]
  ret i32 %retval.0
}

!0 = !{!"branch_weights", i32 676, i32 207}

-------------------------------------------------------------------------------

But after -simplifycfg, the metadata is gone:

$ ./opt -simplifycfg selbrweight.ll -S
; ModuleID = 'selbrweight.ll'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.11.0"

define i32 @foo(i32 %x) {
entry:
  %cmp = icmp sgt i32 %x, 4
  %add = add nsw i32 %x, 7
  %mul = mul nsw i32 %x, 17
  %retval.0 = select i1 %cmp, i32 %add, i32 %mul
  ret i32 %retval.0
}

-------------------------------------------------------------------------------

I don't know if weight metadata can currently be applied to selects, but the
select instruction should propagate the weight info that was on the branch.

This was noted by Benjamin Kramer in:
<a href="http://reviews.llvm.org/D16836">http://reviews.llvm.org/D16836</a></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>