Index: llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp +++ llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp @@ -891,6 +891,10 @@ if (MaxDepthInBB != -1 && InstructionNb++ >= MaxDepthInBB) break; + // Do not value number terminator instructions. + if (!isa(&I1)) + break; + if (auto *Load = dyn_cast(&I1)) LI.insert(Load, VN); else if (auto *Store = dyn_cast(&I1)) Index: llvm/trunk/test/Transforms/GVNHoist/hoist-recursive-geps.ll =================================================================== --- llvm/trunk/test/Transforms/GVNHoist/hoist-recursive-geps.ll +++ llvm/trunk/test/Transforms/GVNHoist/hoist-recursive-geps.ll @@ -8,9 +8,9 @@ ; CHECK: load ; CHECK: load ; CHECK: fsub -; CHECK: fmul ; CHECK: fsub ; CHECK: fmul +; CHECK: fmul ; CHECK-NOT: fsub ; CHECK-NOT: fmul