[PATCH] llvm.noalias - handling of dead intrinsics

hfinkel at anl.gov hfinkel at anl.gov
Thu Apr 30 08:07:45 PDT 2015


Hi chandlerc, reames,

This part of the series started by D9375, and adds some code to clean-up dead llvm.noalias intrinsics. Specifically:

 1. The intrinsic is dead if it has no users

 2. If the pointer argument is undef, the intrinsic can be removed (replaced by the undef).

http://reviews.llvm.org/D9376

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

Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -3561,6 +3561,11 @@
 template <typename IterTy>
 static Value *SimplifyIntrinsic(Intrinsic::ID IID, IterTy ArgBegin, IterTy ArgEnd,
                                 const Query &Q, unsigned MaxRecurse) {
+  // We can remove a noalias intrinsic if the pointer value is undef (by
+  // forwarding the undef).
+  if (IID == Intrinsic::noalias && isa<UndefValue>(*ArgBegin))
+    return *ArgBegin;
+
   // Perform idempotent optimizations
   if (!IsIdempotent(IID))
     return nullptr;
Index: lib/Transforms/Utils/Local.cpp
===================================================================
--- lib/Transforms/Utils/Local.cpp
+++ lib/Transforms/Utils/Local.cpp
@@ -319,6 +319,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: test/Transforms/InstSimplify/noalias.ll
===================================================================
--- /dev/null
+++ test/Transforms/InstSimplify/noalias.ll
@@ -0,0 +1,25 @@
+; 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* @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"}
+

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9376.24710.patch
Type: text/x-patch
Size: 1960 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150430/a4c6c58b/attachment.bin>


More information about the llvm-commits mailing list