Index: lib/Analysis/AliasSetTracker.cpp =================================================================== --- lib/Analysis/AliasSetTracker.cpp +++ lib/Analysis/AliasSetTracker.cpp @@ -174,7 +174,8 @@ // but don't actually modify any specific memory location. using namespace PatternMatch; bool MayWriteMemory = I->mayWriteToMemory() && - !match(I, m_Intrinsic()); + !match(I, m_Intrinsic()) && + !(I->use_empty() && match(I, m_Intrinsic())); if (!MayWriteMemory) { Alias = SetMayAlias; Access |= RefAccess; Index: test/Transforms/LICM/invariant.start.ll =================================================================== --- test/Transforms/LICM/invariant.start.ll +++ test/Transforms/LICM/invariant.start.ll @@ -1,13 +1,13 @@ ; RUN: opt -licm -basicaa < %s -S | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='require,require,require,require,loop(licm)' < %s -S | FileCheck %s -; TODO: should be able to hoist both load and invariant.start +; TODO: should be able to hoist the invariant.start define void @test1(i1 %cond, i32* %ptr) { ; CHECK-LABEL: @test1( ; CHECK-LABEL: entry: +; CHECK: %val = load i32, i32* %ptr ; CHECK-LABEL: loop: ; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr) -; CHECK: %val = load i32, i32* %ptr entry: br label %loop @@ -20,14 +20,13 @@ br label %loop } -;; TODO: despite the loop varying invariant.start, we should be -;; able to hoist the load +;; despite the loop varying invariant.start, we can hoist the load define void @test2(i1 %cond, i32* %ptr) { ; CHECK-LABEL: @test2( ; CHECK-LABEL: entry: +; CHECK: %val = load i32, i32* %ptr ; CHECK-LABEL: loop: ; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %piv) -; CHECK: %val = load i32, i32* %ptr entry: br label %loop @@ -41,13 +40,15 @@ br label %loop } -; Should be able to hoist since store doesn't alias +;; can hoist the load since the store doesn't alias -- due to +;; the unknown instruction handling, the store ends up in a separate +;; aliasing set define void @test3(i1 %cond, i32* %ptr) { ; CHECK-LABEL: @test3( ; CHECK-LABEL: entry: +; CHECK: %val = load i32, i32* %ptr ; CHECK-LABEL: loop: ; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr) -; CHECK: %val = load i32, i32* %ptr entry: br label %loop @@ -85,20 +86,21 @@ } ; don't try to reason about scopes +;; FIXME: not actually testing scopes case yet define void @test5(i1 %cond, i32* %ptr) { ; CHECK-LABEL: @test5( ; CHECK-LABEL: entry: +; CHECK: %val = load i32, i32* %ptr ; CHECK-LABEL: loop: -; CHECK: store i32 0, i32* %ptr ; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr) -; CHECK: %val = load i32, i32* %ptr entry: br label %loop loop: %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ] - store i32 0, i32* %ptr + %p2 = getelementptr i32, i32* %ptr, i32 1 + store i32 0, i32* %p2 %scope = call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr) %val = load i32, i32* %ptr ;; NOTE: despite being correct syntax, uncommenting this line causes