From afaf6ad3a7afe113a2c92978b2890ce64619a4a6 Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Thu, 22 Sep 2016 14:45:40 +0000 Subject: [PATCH] GVN-hoist: only hoist relevant scalar instructions Without this patch, GVN-hoist would think that a branch instruction is a scalar instruction and would try to value number it. The patch filters out all such kind of irrelevant instructions. A bit frustrating is that there is no easy way to discard all those very infrequent instructions, a bit like isa that stands for a large family of instructions. I'm thinking that checking for those very infrequent other instructions would cost us more in compilation time than just letting those instructions getting numbered, so I'm still thinking that a simpler check: if (isa(I)) return false; is better than listing all the other less frequent instructions. Differential Revision: https://reviews.llvm.org/D23929 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282160 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/GVNHoist.cpp | 4 ++++ test/Transforms/GVNHoist/hoist-recursive-geps.ll | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Scalar/GVNHoist.cpp b/lib/Transforms/Scalar/GVNHoist.cpp index b09bd36b6b4..023d1255064 100644 --- a/lib/Transforms/Scalar/GVNHoist.cpp +++ b/lib/Transforms/Scalar/GVNHoist.cpp @@ -891,6 +891,10 @@ private: 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)) diff --git a/test/Transforms/GVNHoist/hoist-recursive-geps.ll b/test/Transforms/GVNHoist/hoist-recursive-geps.ll index 76bc7c26e81..3cc1d993aff 100644 --- a/test/Transforms/GVNHoist/hoist-recursive-geps.ll +++ b/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 -- 2.50.1