[PATCH] D9376: llvm.noalias - handling of dead intrinsics

Hal Finkel via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 10 16:12:44 PDT 2016


hfinkel updated this revision to Diff 63444.
hfinkel added a comment.

Updated per review comments (handle the null pointer in AS-0 case).


http://reviews.llvm.org/D9376

Files:
  lib/Analysis/InstructionSimplify.cpp
  lib/Transforms/Utils/Local.cpp
  test/Transforms/InstSimplify/noalias.ll

Index: test/Transforms/InstSimplify/noalias.ll
===================================================================
--- /dev/null
+++ test/Transforms/InstSimplify/noalias.ll
@@ -0,0 +1,34 @@
+; RUN: opt -instsimplify -S < %s | FileCheck %s
+
+define void @test1(i8* %ptr) {
+  call i8* @llvm.noalias.p0i8(i8* %ptr, metadata !1)
+  ret void
+
+; CHECK-LABEL: @test1
+; CHECK-NOT: llvm.noalias.p0i8
+; CHECK: ret void
+}
+
+define i8* @test2a() {
+  %v = call i8* @llvm.noalias.p0i8(i8* null, metadata !1)
+  ret i8* %v
+
+; CHECK-LABEL: @test2a
+; CHECK-NOT: llvm.noalias.p0i8
+; CHECK: ret i8* null
+}
+
+define i8* @test2() {
+  %v = call i8* @llvm.noalias.p0i8(i8* undef, metadata !1)
+  ret i8* %v
+
+; CHECK-LABEL: @test2
+; CHECK-NOT: llvm.noalias.p0i8
+; CHECK: ret i8* undef
+}
+
+declare i8* @llvm.noalias.p0i8(i8*, metadata) nounwind
+
+!0 = !{!0, !"some domain"}
+!1 = !{!1, !0, !"some scope"}
+
Index: lib/Transforms/Utils/Local.cpp
===================================================================
--- lib/Transforms/Utils/Local.cpp
+++ lib/Transforms/Utils/Local.cpp
@@ -332,6 +332,12 @@
 
       return false;
     }
+
+    // noalias intrinsics are dead if they have no uses (they're tagged as
+    // writing, but that is only to maintain control dependencies, not because
+    // they actually write anything).
+    if (II->getIntrinsicID() == Intrinsic::noalias)
+      return II->use_empty();
   }
 
   if (isAllocLikeFn(I, TLI)) return true;
Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -3946,6 +3946,17 @@
   unsigned NumOperands = std::distance(ArgBegin, ArgEnd);
   Type *ReturnType = F->getReturnType();
 
+  // We can remove a noalias intrinsic if the pointer value is undef (by
+  // forwarding the undef). The same goes for an address-space-zero null
+  // pointer.
+  if (IID == Intrinsic::noalias) {
+    Value *Arg0 = *ArgBegin;
+    if (isa<UndefValue>(Arg0) ||
+        (isa<ConstantPointerNull>(Arg0) &&
+         Arg0->getType()->getPointerAddressSpace() == 0))
+      return *ArgBegin;
+  }
+
   // Binary Ops
   if (NumOperands == 2) {
     Value *LHS = *ArgBegin;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9376.63444.patch
Type: text/x-patch
Size: 2254 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160710/e923eff4/attachment.bin>


More information about the llvm-commits mailing list