From 24ae77eebffbf14ece11061cd4365f056fdaf426 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Mon, 27 Jan 2020 22:19:11 -0600 Subject: [PATCH] [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. --- llvm/lib/Transforms/IPO/Attributor.cpp | 10 ++++++++-- llvm/test/Transforms/Attributor/value-simplify.ll | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 0598bca..306bfc4 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(Val)) indicateOptimisticFixpoint(); - if (isa(Val) && - Val.getType()->getPointerAddressSpace() == 0) + else if (isa(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(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 b2563ad..dff06e5 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) -- 2.7.4