<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 - wrong result after MemCpy Optimization after r319482-319483"
   href="https://bugs.llvm.org/show_bug.cgi?id=35519">35519</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>wrong result after MemCpy Optimization after  r319482-319483
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </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>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>ilia.taraban@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This test fails with wrong result after MemCpy Optimization after
r319482-319483:

================= nice.c ==============
int main ()
{
    unsigned int i = 0, j = 0;
    unsigned int a [10] = {0}, s [10] = {0};
    a[0] = 1;
    for (i = 0; i < 6; ++i) 
        for (j = 1; j < i; ++j) 
            a[j - 1] = s[j];
    printf("%u\n", a[0]);
    return 0;
}

=======================================

------------------------------------------------------------------------
r319482 | djg | 2017-11-30 23:10:53 +0100 (Thu, 30 Nov 2017) | 10 lines

[memcpyopt] Teach memcpyopt to optimize across basic blocks

This teaches memcpyopt to make a non-local memdep query when a local query
indicates that the dependency is non-local. This notably allows it to
eliminate many more llvm.memcpy calls in common Rust code, often by 20-30%.

Fixes PR28958.

Differential Revision: <a href="https://reviews.llvm.org/D38374">https://reviews.llvm.org/D38374</a>

------------------------------------------------------------------------
------------------------------------------------------------------------
r319483 | djg | 2017-11-30 23:13:13 +0100 (Thu, 30 Nov 2017) | 5 lines

[memcpyopt] Commit file missed in r319482.

This change was meant to be included with r319482 but was accidentally
omitted.

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

<span class="quote">>>> clang -v</span >
clang version 6.0.0 (trunk 319481)
Target: x86_64-unknown-linux-gnu
Thread model: posix
...

<span class="quote">>>> clang -O2 -o nice.exe nice.c
>>> ./nice.exe</span >
0

<span class="quote">>>> clang -v</span >
clang version 6.0.0 (trunk 319483)
Target: x86_64-unknown-linux-gnu
Thread model: posix
...
<span class="quote">>>> clang -O2 -o nice.exe nice.c
>>> ./nice.exe</span >
1

<span class="quote">>>> clang -O2 -o nice.exe nice.c -mllvm -opt-bisect-limit=47</span >
...
BISECT: running pass (46) MergedLoadStoreMotion on function (main)
BISECT: running pass (47) Global Value Numbering on function (main)
BISECT: NOT running pass (48) MemCpy Optimization on function (main)
BISECT: NOT running pass (49) Sparse Conditional Constant Propagation on
function (main)
...
<span class="quote">>>> ./nice.exe</span >
0


<span class="quote">>>> clang -O2 -o nice.exe nice.c -mllvm -opt-bisect-limit=48</span >
...
BISECT: running pass (47) Global Value Numbering on function (main)
BISECT: running pass (48) MemCpy Optimization on function (main)
BISECT: NOT running pass (49) Sparse Conditional Constant Propagation on
function (main)
BISECT: NOT running pass (50) Bit-Tracking Dead Code Elimination on function
(main)
...
<span class="quote">>>> ./nice.exe</span >
1

IR before MemCpy:
<span class="quote">>>> clang -O2 -S -emit-llvm -o nice.before.ll nice.c -mllvm -opt-bisect-limit=47</span >
...
============= nice.before.ll ==========
...
for.body3.lr.ph.5:                                ; preds = %for.inc7.4
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* %scevgep25, i64 16, i32 4,
i1 false)
  br label %for.inc7.5

for.inc7.5:                                       ; preds =
%for.inc7.4.for.inc7.5_crit_edge, %for.body3.lr.ph.5
  %2 = load i32, i32* %arrayidx, align 16, !tbaa !2
  %call = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x
i8], [10 x i8]* @.str, i64 0, i64 0), i32 %2)
  call void @llvm.lifetime.end.p0i8(i64 40, i8* nonnull %1) #3
  call void @llvm.lifetime.end.p0i8(i64 40, i8* nonnull %0) #3
  ret i32 %2
}
...
=======================================
After optimization:
<span class="quote">>>> opt -S -o nice.after.ll -memcpyopt nice.before.ll</span >
...
============= nice.after.ll ===========
for.body3.lr.ph.5:                                ; preds = %for.inc7.4
  br label %for.inc7.5

for.inc7.5:                                       ; preds = %for.body3.lr.ph.5,
%for.inc7.4.for.inc7.5_crit_edge
  %2 = load i32, i32* %arrayidx, align 16, !tbaa !2
  %call = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x
i8], [10 x i8]* @.str, i64 0, i64 0), i32 %2)
  call void @llvm.lifetime.end.p0i8(i64 40, i8* nonnull %1) #3
  call void @llvm.lifetime.end.p0i8(i64 40, i8* nonnull %0) #3
  ret i32 %2
}

=======================================

So now there is no memcpy at all. And we receive init value instead of copied.</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>