Index: lib/Analysis/BasicAliasAnalysis.cpp =================================================================== --- lib/Analysis/BasicAliasAnalysis.cpp +++ lib/Analysis/BasicAliasAnalysis.cpp @@ -580,20 +580,11 @@ /// Returns the behavior when calling the given function. For use when the call /// site is not known. -/// NOTE: Because of the special case handling of llvm.assume below, the result -/// of this function may not match similar results derived from function -/// attributes (e.g. "readnone"). FunctionModRefBehavior BasicAAResult::getModRefBehavior(const Function *F) { // If the function declares it doesn't access memory, we can't do better. if (F->doesNotAccessMemory()) return FMRB_DoesNotAccessMemory; - // While the assume intrinsic is marked as arbitrarily writing so that - // proper control dependencies will be maintained, it never aliases any - // actual memory locations. - if (F->getIntrinsicID() == Intrinsic::assume) - return FMRB_DoesNotAccessMemory; - FunctionModRefBehavior Min = FMRB_UnknownModRefBehavior; // If the function declares it only reads memory, go with that. Index: lib/Transforms/Utils/MemorySSA.cpp =================================================================== --- lib/Transforms/Utils/MemorySSA.cpp +++ lib/Transforms/Utils/MemorySSA.cpp @@ -354,6 +354,14 @@ /// \brief Helper function to create new memory accesses MemoryUseOrDef *MemorySSA::createNewAccess(Instruction *I) { + // The assume intrinsic has a control dependency which we model by claiming + // that it writes arbitrarily. Ignore that fake memory dependency here. + // FIXME: Replace this special casing with a more accurate modelling of + // assume's control dependency. + if (IntrinsicInst *II = dyn_cast(I)) + if (II->getIntrinsicID() == Intrinsic::assume) + return nullptr; + // Find out what affect this instruction has on memory. ModRefInfo ModRef = AA->getModRefInfo(I); bool Def = bool(ModRef & MRI_Mod); Index: test/Transforms/FunctionAttrs/assume.ll =================================================================== --- /dev/null +++ test/Transforms/FunctionAttrs/assume.ll @@ -0,0 +1,4 @@ +; RUN: opt -S -o - -functionattrs %s | FileCheck %s + +; CHECK-NOT: readnone +declare void @llvm.assume(i1) Index: test/Transforms/LICM/assume.ll =================================================================== --- /dev/null +++ test/Transforms/LICM/assume.ll @@ -0,0 +1,34 @@ +; RUN: opt -licm -basicaa < %s -S | FileCheck %s + +define void @f(i1 %p) nounwind ssp { +entry: + br label %for.body + +for.body: + br i1 undef, label %if.then, label %for.cond.backedge + +for.cond.backedge: + br i1 undef, label %for.end104, label %for.body + +if.then: + br i1 undef, label %if.then27, label %if.end.if.end.split_crit_edge.critedge + +if.then27: +; CHECK: tail call void @llvm.assume + tail call void @llvm.assume(i1 %p) + br label %for.body61.us + +if.end.if.end.split_crit_edge.critedge: + br label %for.body61 + +for.body61.us: + br i1 undef, label %for.cond.backedge, label %for.body61.us + +for.body61: + br i1 undef, label %for.cond.backedge, label %for.body61 + +for.end104: + ret void +} + +declare void @llvm.assume(i1) Index: test/Transforms/Util/MemorySSA/assume.ll =================================================================== --- test/Transforms/Util/MemorySSA/assume.ll +++ test/Transforms/Util/MemorySSA/assume.ll @@ -8,6 +8,7 @@ ; CHECK: 1 = MemoryDef(liveOnEntry) ; CHECK-NEXT: store i32 4 store i32 4, i32* %a, align 4 +; CHECK-NOT: MemoryDef ; CHECK: call void @llvm.assume call void @llvm.assume(i1 %c) ; CHECK: MemoryUse(1)