Index: lib/Transforms/Scalar/LICM.cpp =================================================================== --- lib/Transforms/Scalar/LICM.cpp +++ lib/Transforms/Scalar/LICM.cpp @@ -530,7 +530,9 @@ } using namespace PatternMatch; - if (match(&I, m_Intrinsic()) && + if (((I.use_empty() && + match(&I, m_Intrinsic())) || + match(&I, m_Intrinsic())) && IsMustExecute && IsMemoryNotModified && CurLoop->hasLoopInvariantOperands(&I)) { hoist(I, DT, CurLoop, SafetyInfo, ORE); @@ -687,7 +689,6 @@ if (Function *F = CI->getCalledFunction()) switch (F->getIntrinsicID()) { default: break; - // TODO: support invariant.start, and experimental.guard here case Intrinsic::assume: // Assumes don't actually alias anything or throw return true; Index: test/Transforms/LICM/invariant.start.ll =================================================================== --- test/Transforms/LICM/invariant.start.ll +++ test/Transforms/LICM/invariant.start.ll @@ -3,19 +3,18 @@ ; RUN: opt -aa-pipeline=basic-aa -licm-n2-threshold=0 -passes='require,require,require,require,loop(licm)' < %s -S | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -licm-n2-threshold=200 -passes='require,require,require,require,loop(licm)' < %s -S | FileCheck %s --check-prefix=ALIAS-N2 -; TODO: By default (without the -licm-n2-threshold value), we should be able to hoist both load and invariant.start define void @test1(i1 %cond, i32* %ptr) { ; CHECK-LABEL: @test1( ; CHECK-LABEL: entry: +; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr) ; CHECK: %val = load i32, i32* %ptr ; CHECK-LABEL: loop: -; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr) ; ALIAS-N2-LABEL: @test1( ; ALIAS-N2-LABEL: entry: -; ALIAS-N2: %val = load i32, i32* %ptr -; ALIAS-N2-LABEL: loop: ; ALIAS-N2: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr) +; ALIAS-N2: %val = load i32, i32* %ptr +; ALIAS-N2-LABEL: loop: entry: br label %loop @@ -57,15 +56,15 @@ define void @test3(i1 %cond, i32* %ptr) { ; CHECK-LABEL: @test3( ; CHECK-LABEL: entry: +; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr) ; CHECK: %val = load i32, i32* %ptr ; CHECK-LABEL: loop: -; CHECK: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr) ; ALIAS-N2-LABEL: @test3( ; ALIAS-N2-LABEL: entry: -; ALIAS-N2: %val = load i32, i32* %ptr +; ALIAS-N2: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr) +; ALIAS-N2: %val = load i32, i32* %ptr ; ALIAS-N2-LABEL: loop: -; ALIAS-N2: call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr) entry: br label %loop