<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] failure to sink common function call below if/else"
   href="https://llvm.org/bugs/show_bug.cgi?id=28964">28964</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[SimplifyCFG] failure to sink common function call below if/else
          </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>Forking this off from <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - constant function parameter is set to existing value"
   href="show_bug.cgi?id=28957">bug 28957</a>:

extern int bar(int);
int foo(int x) {
  if (x == 1)
    return bar(1);
  else
    return bar(-1);
}

Or as optimized IR:

define i32 @foo(i32 %x) {
entry:
  %cmp = icmp eq i32 %x, 1
  br i1 %cmp, label %if.then, label %if.else

if.then:            
  %call = tail call i32 @bar(i32 1) #2
  br label %return

if.else:                 
  %call1 = tail call i32 @bar(i32 -1) #2
  br label %return

return:                 
  %retval.0 = phi i32 [ %call, %if.then ], [ %call1, %if.else ]
  ret i32 %retval.0
}

declare i32 @bar(i32)

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

I think SimplifyCFG should transform this to the equivalent of:

int goo(int x) {
  if (x == 1)
    x = 1;
  else
    x = -1;
  return bar(x);
}

which is this in IR:

define i32 @goo(i32 %x) local_unnamed_addr #0 {
  %cmp = icmp eq i32 %x, 1
  %sel = select i1 %cmp, i32 1, i32 -1
  %call = tail call i32 @bar(i32 %sel)
  ret i32 %call
}</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>