[llvm] r282160 - GVN-hoist: only hoist relevant scalar instructions

Sebastian Pop via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 22 07:45:40 PDT 2016


Author: spop
Date: Thu Sep 22 09:45:40 2016
New Revision: 282160

URL: http://llvm.org/viewvc/llvm-project?rev=282160&view=rev
Log:
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<TerminatorInst> 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<TerminatorInst>(I))
    return false;

is better than listing all the other less frequent instructions.

Differential Revision: https://reviews.llvm.org/D23929

Modified:
    llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp
    llvm/trunk/test/Transforms/GVNHoist/hoist-recursive-geps.ll

Modified: llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp?rev=282160&r1=282159&r2=282160&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp Thu Sep 22 09:45:40 2016
@@ -891,6 +891,10 @@ private:
         if (MaxDepthInBB != -1 && InstructionNb++ >= MaxDepthInBB)
           break;
 
+        // Do not value number terminator instructions.
+        if (!isa<TerminatorInst>(&I1))
+          break;
+
         if (auto *Load = dyn_cast<LoadInst>(&I1))
           LI.insert(Load, VN);
         else if (auto *Store = dyn_cast<StoreInst>(&I1))

Modified: llvm/trunk/test/Transforms/GVNHoist/hoist-recursive-geps.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVNHoist/hoist-recursive-geps.ll?rev=282160&r1=282159&r2=282160&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GVNHoist/hoist-recursive-geps.ll (original)
+++ llvm/trunk/test/Transforms/GVNHoist/hoist-recursive-geps.ll Thu Sep 22 09:45:40 2016
@@ -8,9 +8,9 @@
 ; CHECK: load
 ; CHECK: load
 ; CHECK: fsub
-; CHECK: fmul
 ; CHECK: fsub
 ; CHECK: fmul
+; CHECK: fmul
 ; CHECK-NOT: fsub
 ; CHECK-NOT: fmul
 




More information about the llvm-commits mailing list