[PATCH] D68492: [PATCH 09/38] [noalias] D9376: llvm.noalias - handling of dead intrinsics
Jeroen Dobbelaere via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 4 14:40:10 PDT 2019
jeroen.dobbelaere created this revision.
jeroen.dobbelaere added reviewers: hfinkel, jdoerfert.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
This is part of the series started by D68484 <https://reviews.llvm.org/D68484>.
Rebase of D9376 <https://reviews.llvm.org/D9376>
https://reviews.llvm.org/D68492
Files:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/Transforms/InstSimplify/noalias.ll
Index: llvm/test/Transforms/InstSimplify/noalias.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstSimplify/noalias.ll
@@ -0,0 +1,33 @@
+; 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: llvm/lib/Transforms/Utils/Local.cpp
===================================================================
--- llvm/lib/Transforms/Utils/Local.cpp
+++ llvm/lib/Transforms/Utils/Local.cpp
@@ -417,6 +417,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))
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5146,6 +5146,18 @@
Function *F = cast<Function>(Call->getCalledFunction());
Intrinsic::ID IID = F->getIntrinsicID();
+
+ // 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 = Call->getArgOperand(0);
+ if (isa<UndefValue>(Arg0) ||
+ (isa<ConstantPointerNull>(Arg0) &&
+ Arg0->getType()->getPointerAddressSpace() == 0))
+ return Arg0;
+ }
+
if (NumOperands == 1)
return simplifyUnaryIntrinsic(F, Call->getArgOperand(0), Q);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68492.223292.patch
Type: text/x-patch
Size: 2312 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191004/5c6e7da6/attachment.bin>
More information about the llvm-commits
mailing list