<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 - Regression caused by CodeGenPrepare patch rL354298"
   href="https://bugs.llvm.org/show_bug.cgi?id=41129">41129</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Regression caused by CodeGenPrepare patch rL354298
          </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>Scalar Optimizations
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Compile following code with 

opt -codegenprepare -mtriple=x86_64-unknown-linux-gnu -S test3.ll

define void @foo(i64* %p64) {
entry:
  %key = load i64, i64* %p64, align 8
  %cond17 = icmp eq i64 %key, 0
  br i1 %cond17, label %true, label %false

false:
  %andval = and i64 %key, 7
  store i64 %andval, i64* %p64
  br label %exit

true:
  %svalue = add i64 %key, -1
  store i64 %svalue, i64* %p64
  br label %exit

exit:
  ret void
}


Then generate code for x86, then I can get


foo:                                    # @foo
        .cfi_startproc
# %bb.0:                                # %entry
        movq    (%rdi), %rax
        movq    %rax, %rcx                        // Extra copy
        subq    $1, %rcx
        jae     .LBB0_1
# %bb.2:                                # %true
        movq    %rcx, (%rdi)
        retq
.LBB0_1:                                # %false
        andl    $7, %eax
        movq    %rax, (%rdi)
        retq
.Lfunc_end0:
        .size   foo, .Lfunc_end0-foo

An extra copy is generated in the entry block. It is needed for a 2-address ISA
like x86, and the operand has other uses. In this case, the extra COPY is
inserted in BB entry, a SUB is eliminated in BB true, BB entry is executed more
times than BB true, so it is always a lose.</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>