[llvm-bugs] [Bug 35519] New: wrong result after MemCpy Optimization after r319482-319483

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Dec 4 06:50:56 PST 2017


https://bugs.llvm.org/show_bug.cgi?id=35519

            Bug ID: 35519
           Summary: wrong result after MemCpy Optimization after
                    r319482-319483
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: ilia.taraban at intel.com
                CC: llvm-bugs at lists.llvm.org

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: https://reviews.llvm.org/D38374

------------------------------------------------------------------------
------------------------------------------------------------------------
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.

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

>>> clang -v
clang version 6.0.0 (trunk 319481)
Target: x86_64-unknown-linux-gnu
Thread model: posix
...

>>> clang -O2 -o nice.exe nice.c
>>> ./nice.exe
0

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

>>> clang -O2 -o nice.exe nice.c -mllvm -opt-bisect-limit=47
...
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)
...
>>> ./nice.exe
0


>>> clang -O2 -o nice.exe nice.c -mllvm -opt-bisect-limit=48
...
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)
...
>>> ./nice.exe
1

IR before MemCpy:
>>> clang -O2 -S -emit-llvm -o nice.before.ll nice.c -mllvm -opt-bisect-limit=47
...
============= 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:
>>> opt -S -o nice.after.ll -memcpyopt nice.before.ll
...
============= 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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171204/a56406ce/attachment.html>


More information about the llvm-bugs mailing list