Index: lib/Analysis/GlobalsModRef.cpp =================================================================== --- lib/Analysis/GlobalsModRef.cpp +++ lib/Analysis/GlobalsModRef.cpp @@ -516,7 +516,7 @@ if (F->isDeclaration()) { // Try to get mod/ref behaviour from function attributes. - if (F->doesNotAccessMemory() || F->onlyAccessesInaccessibleMemory()) { + if (F->doesNotAccessMemory()) { // Can't do better than that! } else if (F->onlyReadsMemory()) { FI.addModRefInfo(MRI_Ref); @@ -525,9 +525,11 @@ // consider every global as possibly being read by this function. FI.setMayReadAnyGlobal(); } else if (F->onlyAccessesArgMemory() || + F->onlyAccessesInaccessibleMemory() || F->onlyAccessesInaccessibleMemOrArgMem()) { - // This function may only access (read/write) memory pointed to by its - // arguments. If this pointer is to a global, this escaping use of the + // This function may at most access (read/write) memory pointed to by its + // arguments (i.e., it may not read any globals in this module directly). + // If an argument points to a global, this escaping use of the // pointer is captured in AnalyzeUsesOfPointer(). FI.addModRefInfo(MRI_ModRef); } else { Index: test/Analysis/GlobalsModRef/modreftest2.ll =================================================================== --- /dev/null +++ test/Analysis/GlobalsModRef/modreftest2.ll @@ -0,0 +1,25 @@ +; RUN: opt < %s -basicaa -globals-aa -gvn -licm -S | FileCheck %s + +@X = internal global i32 4 + +declare void @InaccessibleMemOnlyFunc( ) #0 + +attributes #0 = { inaccessiblememonly } + +define i32 @test3( ) { +entry: + br label %for.body7 + +for.body7: +; CHECK: for.body7 +; CHECK: call void @InaccessibleMemOnlyFunc() + %XB = bitcast i32* @X to i1* + %x = load i1, i1* %XB + call void @InaccessibleMemOnlyFunc( ) + br i1 %x, label %for.body7, label %for.end12 + +for.end12: + ret i32 0 +} + +