[CodeGen] Fix noalias annotations for memcpy/memmove.

Memory transfer instructions take two pointers. It is not defined to
which of those a noalias annotation applies. To ensure correctness,
do not add noalias annotations to memcpy/memmove instructions anymore.

The caused a miscompile with test-suite's MultiSource/Applications/obsequi.
Since r321138, the MemCpyOpt pass would remove memcpy/memmove calls if
known to copy uninitialized memory. In that case, it was initialized
by another memcpy, but the annotation for the target pointer said
it would not alias. The annotation was actually meant for the source
pointer, which was was an alloca and could not alias with the target
pointer.

llvm-svn: 321371
This commit is contained in:
Michael Kruse 2017-12-22 17:44:53 +00:00
parent b2368fbdf4
commit 271deb17b0
2 changed files with 47 additions and 0 deletions

View File

@ -201,6 +201,12 @@ void ScopAnnotator::annotate(Instruction *Inst) {
if (!AliasScopeDomain)
return;
// Do not apply annotations on memory operations that take more than one
// pointer. It would be ambiguous to which pointer the annotation applies.
// FIXME: How can we specify annotations for all pointer arguments?
if (isa<CallInst>(Inst) && !isa<MemSetInst>(Inst))
return;
auto *Ptr = getMemAccInstPointerOperand(Inst);
if (!Ptr)
return;

View File

@ -0,0 +1,41 @@
; RUN: opt %loadPolly -polly-codegen -S < %s | FileCheck %s
;
; Verify that @llvm.memcpy does not get a !alias.scope annotation.
; @llvm.memcpy takes two pointers, it is ambiguous to which the
; annotation applies.
;
; for (int j = 0; j < n; j += 1) {
; memcpy(A, B, 8);
; }
;
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1)
define void @func(i32 %n, i8* noalias nonnull %A, i8* noalias nonnull %B) {
entry:
br label %for
for:
%j = phi i32 [0, %entry], [%j.inc, %inc]
%j.cmp = icmp slt i32 %j, %n
br i1 %j.cmp, label %body, label %exit
body:
call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %A, i8* %B, i64 8, i32 4, i1 false)
br label %inc
inc:
%j.inc = add nuw nsw i32 %j, 1
br label %for
exit:
br label %return
return:
ret void
}
; CHECK-LABEL: polly.start:
; CHECK: call void @llvm.memcpy
; CHECK-NOT: !alias.scope