From d53277a4349d301db7689b490a6a3d4512a746ce Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Thu, 22 Oct 2015 03:12:51 +0000 Subject: [PATCH] [OperandBundles] Teach AliasAnalysis about operand bundles Summary: If a `CallSite` has operand bundles, then do not peek into the called function to get a more precise `ModRef` answer. This is tested using `argmemonly`, `-basicaa` and `-gvn`; but the functionality is not specific to any of these. Depends on D13961 Reviewers: reames, chandlerc Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D13962 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250974 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/AliasAnalysis.h | 8 ++++-- include/llvm/IR/InstrTypes.h | 7 +++-- .../OperandBundles/basic-aa-argmemonly.ll | 28 +++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 test/Feature/OperandBundles/basic-aa-argmemonly.ll diff --git a/include/llvm/Analysis/AliasAnalysis.h b/include/llvm/Analysis/AliasAnalysis.h index 781ab25b391..2f4722fb964 100644 --- a/include/llvm/Analysis/AliasAnalysis.h +++ b/include/llvm/Analysis/AliasAnalysis.h @@ -759,8 +759,12 @@ public: } FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS) { - if (const Function *F = CS.getCalledFunction()) - return getBestAAResults().getModRefBehavior(F); + if (!CS.hasOperandBundles()) + // If CS has operand bundles then aliasing attributes from the function it + // calls do not directly apply to the CallSite. This can be made more + // precise in the future. + if (const Function *F = CS.getCalledFunction()) + return getBestAAResults().getModRefBehavior(F); return FMRB_UnknownModRefBehavior; } diff --git a/include/llvm/IR/InstrTypes.h b/include/llvm/IR/InstrTypes.h index 136a6c3f457..207b5b42d50 100644 --- a/include/llvm/IR/InstrTypes.h +++ b/include/llvm/IR/InstrTypes.h @@ -1255,8 +1255,8 @@ protected: /// \brief Is the function attribute S disallowed by some operand bundle on /// this operand bundle user? bool isFnAttrDisallowedByOpBundle(StringRef S) const { - // Operand bundles only possibly disallow readnone and readonly attributes. - // All String attributes are fine. + // Operand bundles only possibly disallow readnone, readonly and argmenonly + // attributes. All String attributes are fine. return false; } @@ -1267,6 +1267,9 @@ protected: default: return false; + case Attribute::ArgMemOnly: + return hasReadingOperandBundles(); + case Attribute::ReadNone: return hasReadingOperandBundles(); diff --git a/test/Feature/OperandBundles/basic-aa-argmemonly.ll b/test/Feature/OperandBundles/basic-aa-argmemonly.ll new file mode 100644 index 00000000000..1f3b378868e --- /dev/null +++ b/test/Feature/OperandBundles/basic-aa-argmemonly.ll @@ -0,0 +1,28 @@ +; RUN: opt -S -basicaa -gvn < %s | FileCheck %s + +declare void @argmemonly_function(i32 *) argmemonly + +define i32 @test0(i32* %P, i32* noalias %P2) { +; CHECK-LABEL: @test0( + %v1 = load i32, i32* %P +; CHECK: %v1 = load i32, i32* %P + call void @argmemonly_function(i32* %P2) [ "tag"() ] +; CHECK: call void @argmemonly_function( + %v2 = load i32, i32* %P +; CHECK: %v2 = load i32, i32* %P + %diff = sub i32 %v1, %v2 +; CHECK: %diff = sub i32 %v1, %v2 + ret i32 %diff +; CHECK: ret i32 %diff +} + +define i32 @test1(i32* %P, i32* noalias %P2) { +; CHECK-LABEL: @test1( + %v1 = load i32, i32* %P + call void @argmemonly_function(i32* %P2) argmemonly [ "tag"() ] +; CHECK: call void @argmemonly_function( + %v2 = load i32, i32* %P + %diff = sub i32 %v1, %v2 + ret i32 %diff +; CHECK: ret i32 0 +} -- 2.34.1