[llvm] 24ae77e - [Attributor] Mark a non-defined `null` pointer as `noalias`
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 28 21:40:51 PST 2020
Author: Johannes Doerfert
Date: 2020-01-28T23:09:37-06:00
New Revision: 24ae77eebffbf14ece11061cd4365f056fdaf426
URL: https://github.com/llvm/llvm-project/commit/24ae77eebffbf14ece11061cd4365f056fdaf426
DIFF: https://github.com/llvm/llvm-project/commit/24ae77eebffbf14ece11061cd4365f056fdaf426.diff
LOG: [Attributor] Mark a non-defined `null` pointer as `noalias`
If `null` is not defined we cannot access it, hence the pointer is
`noalias`. While this is not helpful on it's own it simplifies later
deductions that can skip over already known `noalias` pointers in
certain situations.
Added:
Modified:
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/test/Transforms/Attributor/value-simplify.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 0598bca17ce7..306bfc43dce4 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -2417,8 +2417,9 @@ struct AANoAliasFloating final : AANoAliasImpl {
Value &Val = getAssociatedValue();
if (isa<AllocaInst>(Val))
indicateOptimisticFixpoint();
- if (isa<ConstantPointerNull>(Val) &&
- Val.getType()->getPointerAddressSpace() == 0)
+ else if (isa<ConstantPointerNull>(Val) &&
+ !NullPointerIsDefined(getAnchorScope(),
+ Val.getType()->getPointerAddressSpace()))
indicateOptimisticFixpoint();
}
@@ -2496,6 +2497,11 @@ struct AANoAliasCallSiteArgument final : AANoAliasImpl {
ImmutableCallSite ICS(&getAnchorValue());
if (ICS.paramHasAttr(getArgNo(), Attribute::NoAlias))
indicateOptimisticFixpoint();
+ Value &Val = getAssociatedValue();
+ if (isa<ConstantPointerNull>(Val) &&
+ !NullPointerIsDefined(getAnchorScope(),
+ Val.getType()->getPointerAddressSpace()))
+ indicateOptimisticFixpoint();
}
/// See AbstractAttribute::updateImpl(...).
diff --git a/llvm/test/Transforms/Attributor/value-simplify.ll b/llvm/test/Transforms/Attributor/value-simplify.ll
index b2563ad09be9..dff06e5262a4 100644
--- a/llvm/test/Transforms/Attributor/value-simplify.ll
+++ b/llvm/test/Transforms/Attributor/value-simplify.ll
@@ -210,7 +210,7 @@ define i32* @complicated_args_inalloca() {
define internal void @test_sret(%struct.X* sret %a, %struct.X** %b) {
; CHECK-LABEL: define {{[^@]+}}@test_sret
-; CHECK-SAME: (%struct.X* nofree sret writeonly align 536870912 [[A:%.*]], %struct.X** nocapture nofree nonnull writeonly dereferenceable(8) [[B:%.*]])
+; CHECK-SAME: (%struct.X* noalias nofree sret writeonly align 536870912 [[A:%.*]], %struct.X** nocapture nofree nonnull writeonly dereferenceable(8) [[B:%.*]])
; CHECK-NEXT: store %struct.X* [[A]], %struct.X** [[B]]
; CHECK-NEXT: ret void
;
@@ -220,7 +220,7 @@ define internal void @test_sret(%struct.X* sret %a, %struct.X** %b) {
define void @complicated_args_sret(%struct.X** %b) {
; CHECK-LABEL: define {{[^@]+}}@complicated_args_sret
; CHECK-SAME: (%struct.X** nocapture nofree writeonly [[B:%.*]])
-; CHECK-NEXT: call void @test_sret(%struct.X* nofree writeonly align 536870912 null, %struct.X** nocapture nofree writeonly [[B]])
+; CHECK-NEXT: call void @test_sret(%struct.X* noalias nofree writeonly align 536870912 null, %struct.X** nocapture nofree writeonly [[B]])
; CHECK-NEXT: ret void
;
call void @test_sret(%struct.X* null, %struct.X** %b)
More information about the llvm-commits
mailing list