[polly] r321371 - [CodeGen] Fix noalias annotations for memcpy/memmove.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 22 09:44:53 PST 2017


Author: meinersbur
Date: Fri Dec 22 09:44:53 2017
New Revision: 321371

URL: http://llvm.org/viewvc/llvm-project?rev=321371&view=rev
Log:
[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.

Added:
    polly/trunk/test/Isl/CodeGen/memcpy_annotations.ll
Modified:
    polly/trunk/lib/CodeGen/IRBuilder.cpp

Modified: polly/trunk/lib/CodeGen/IRBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IRBuilder.cpp?rev=321371&r1=321370&r2=321371&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IRBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IRBuilder.cpp Fri Dec 22 09:44:53 2017
@@ -201,6 +201,12 @@ void ScopAnnotator::annotate(Instruction
   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;

Added: polly/trunk/test/Isl/CodeGen/memcpy_annotations.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/memcpy_annotations.ll?rev=321371&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/memcpy_annotations.ll (added)
+++ polly/trunk/test/Isl/CodeGen/memcpy_annotations.ll Fri Dec 22 09:44:53 2017
@@ -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




More information about the llvm-commits mailing list