[PATCH] D46972: Propagate nonnull and dereferenceable throught launder
Piotr Padlewski via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 16 12:41:12 PDT 2018
Prazek created this revision.
Prazek added reviewers: rsmith, amharc, kuhar, xbolva00, hfinkel.
Herald added a subscriber: hiraditya.
invariant.group.launder should not stop propagation
of nonnull and dereferenceable, because e.g. we would not be
able to hoist loads speculatively.
Repository:
rL LLVM
https://reviews.llvm.org/D46972
Files:
llvm/lib/Analysis/Loads.cpp
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Analysis/ValueTracking/deref-bitcast-of-gep.ll
llvm/test/Analysis/ValueTracking/invariant.group.ll
Index: llvm/test/Analysis/ValueTracking/invariant.group.ll
===================================================================
--- /dev/null
+++ llvm/test/Analysis/ValueTracking/invariant.group.ll
@@ -0,0 +1,19 @@
+; RUN: opt -S -instsimplify -instcombine < %s | FileCheck %s
+
+; CHECK-LABEL: define void @checkNonnull()
+define void @checkNonnull() {
+; CHECK: %p = call i8* @llvm.launder.invariant.group.p0i8(i8* nonnull %0)
+; CHECK: %p2 = call i8* @llvm.launder.invariant.group.p0i8(i8* nonnull %p)
+; CHECK: call void @use(i8* nonnull %p2)
+entry:
+ %0 = alloca i8, align 8
+
+ %p = call i8* @llvm.launder.invariant.group.p0i8(i8* %0)
+ %p2 = call i8* @llvm.launder.invariant.group.p0i8(i8* %p)
+ call void @use(i8* %p2)
+
+ ret void
+}
+
+declare i8* @llvm.launder.invariant.group.p0i8(i8*)
+declare void @use(i8*)
Index: llvm/test/Analysis/ValueTracking/deref-bitcast-of-gep.ll
===================================================================
--- llvm/test/Analysis/ValueTracking/deref-bitcast-of-gep.ll
+++ llvm/test/Analysis/ValueTracking/deref-bitcast-of-gep.ll
@@ -80,3 +80,28 @@
leave:
ret void
}
+
+define void @checkLaunder(i8* align 4 dereferenceable(1024) %p) {
+; CHECK-LABEL: @checkLaunder(
+; CHECK: entry:
+; CHECK: %l = call i8* @llvm.launder.invariant.group.p0i8(i8* %p)
+; CHECK: %val = load i8, i8* %l
+; CHECK: br label %loop
+; CHECK: loop:
+; CHECK: call void @use(i32 0)
+; CHECK-NEXT: call void @use8(i8 %val)
+
+entry:
+ %l = call i8* @llvm.launder.invariant.group.p0i8(i8* %p)
+ br label %loop
+
+loop:
+ call void @use(i32 0)
+ %val = load i8, i8* %l, !invariant.load !{}
+ call void @use8(i8 %val)
+ br label %loop
+}
+
+declare i8* @llvm.launder.invariant.group.p0i8(i8*)
+
+declare void @use8(i8)
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -1953,9 +1953,12 @@
if (LI->getMetadata(LLVMContext::MD_nonnull))
return true;
- if (auto CS = ImmutableCallSite(V))
+ if (auto CS = ImmutableCallSite(V)) {
if (CS.isReturnNonNull())
return true;
+ if (CS.getIntrinsicID() == Intrinsic::ID::launder_invariant_group)
+ return isKnownNonZero(CS->getOperand(0), Depth + 1, Q);
+ }
}
// The remaining tests are all recursive, so bail out if we hit the limit.
Index: llvm/lib/Analysis/Loads.cpp
===================================================================
--- llvm/lib/Analysis/Loads.cpp
+++ llvm/lib/Analysis/Loads.cpp
@@ -107,11 +107,14 @@
return isDereferenceableAndAlignedPointer(ASC->getOperand(0), Align, Size,
DL, CtxI, DT, Visited);
- if (auto CS = ImmutableCallSite(V))
+ if (auto CS = ImmutableCallSite(V)) {
if (const Value *RV = CS.getReturnedArgOperand())
return isDereferenceableAndAlignedPointer(RV, Align, Size, DL, CtxI, DT,
Visited);
-
+ if (CS.getIntrinsicID() == Intrinsic::launder_invariant_group)
+ return isDereferenceableAndAlignedPointer(CS->getOperand(0), Align, Size,
+ DL, CtxI, DT, Visited);
+ }
// If we don't know, assume the worst.
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46972.147159.patch
Type: text/x-patch
Size: 3331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180516/1b2daafe/attachment.bin>
More information about the llvm-commits
mailing list