diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -1068,6 +1068,10 @@ return false; Addr = BC->getOperand(0); } + // If we've ended up at a global/constant, bail. We shouldn't be looking at + // uselists for non-local Values in a loop pass. + if (isa(Addr)) + return false; unsigned UsesVisited = 0; // Traverse all uses of the load operand value, to see if invariant.start is diff --git a/llvm/test/Transforms/LICM/hoisting.ll b/llvm/test/Transforms/LICM/hoisting.ll --- a/llvm/test/Transforms/LICM/hoisting.ll +++ b/llvm/test/Transforms/LICM/hoisting.ll @@ -602,16 +602,16 @@ @a = external global i8 -; FIXME: Don't hoist invariant loads of globals. +; FIXME: Support hoisting invariant loads of globals. define void @test_fence6() { ; CHECK-LABEL: @test_fence6( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[I:%.*]] = call {}* @llvm.invariant.start.p0i8(i64 1, i8* @a) +; CHECK-NEXT: br label [[F:%.*]] +; CHECK: f: ; CHECK-NEXT: [[TMP0:%.*]] = load i8, i8* @a, align 1 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], 0 ; CHECK-NEXT: [[T:%.*]] = icmp eq i8 [[TMP1]], 0 -; CHECK-NEXT: br label [[F:%.*]] -; CHECK: f: ; CHECK-NEXT: tail call void @g(i1 [[T]]) ; CHECK-NEXT: br label [[F]] ;