<html>
    <head>
      <base href="http://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 --- - Two Addr Instruction pass could be improved further"
   href="http://llvm.org/bugs/show_bug.cgi?id=22689">22689</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Two Addr Instruction pass could be improved further
          </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>Linux
          </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>Common Code Generator Code
          </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>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>A problem was identified in TwoAddrInstruction pass and a patch was propsed in
<a href="http://reviews.llvm.org/D7806">http://reviews.llvm.org/D7806</a>.

However, there are other cases that the patch cannot handle currently. Like the
following one:

1.c:
int M, total;
int A[100], B[100], C[100];

volatile int g;
void goo(int);

void foo() {
  int i, a, b, x, y, z;
  a = 3;
  for (i = 0; i < M; i++) {
    b = i;
    z = g;
    y = b * a;
    x = y + z;
    a = g;
    goo(b);
    total += x;
  }


~/workarea/llvm-r230041/build/bin/clang -O2 -fno-vectorize -fno-unroll-loops -S
1.c

kernel loop in 1.s:
.LBB0_2:                                # %for.body
        movl    g(%rip), %eax
        imull   %ebx, %ebp
        addl    %eax, %ebp
        movl    g(%rip), %r14d
        movl    %ebx, %edi
        callq   goo
        addl    %ebp, total(%rip)
        incl    %ebx
        cmpl    M(%rip), %ebx
        movl    %r14d, %ebp      
        jl      .LBB0_2

The reg copy insn "movl    %r14d, %ebp" could be removed if we switch the
positions of "z = g;" and "y = b * a;" in 1.c

2.c:
int M, total;
int A[100], B[100], C[100];

volatile int g;
void goo(int);

void foo() {
  int i, a, b, x, y, z;
  a = 3;
  for (i = 0; i < M; i++) {
    b = i;
    y = b * a;       // here is the difference with 1.c
    z = g;           // here is the difference with 1.c
    x = y + z;       
    a = g;
    goo(b);
    total += x;
  }
}

~/workarea/llvm-r230041/build/bin/clang -O2 -fno-vectorize -fno-unroll-loops -S
2.c

kernel loop in 2.s:
.LBB0_2:                                # %for.body
        imull   %ebx, %ebp
        movl    g(%rip), %r14d
        addl    %ebp, %r14d
        movl    g(%rip), %ebp
        movl    %ebx, %edi
        callq   goo
        addl    %r14d, total(%rip)
        incl    %ebx
        cmpl    M(%rip), %ebx
        jl      .LBB0_2

The bug is better to be fixed incrementally, so filed this bug to track the
problem.</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>