]> granicus.if.org Git - llvm/commitdiff
GVN-hoist: only hoist relevant scalar instructions
authorSebastian Pop <sebpop@gmail.com>
Thu, 22 Sep 2016 14:45:40 +0000 (14:45 +0000)
committerSebastian Pop <sebpop@gmail.com>
Thu, 22 Sep 2016 14:45:40 +0000 (14:45 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282160 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/GVNHoist.cpp
test/Transforms/GVNHoist/hoist-recursive-geps.ll

index b09bd36b6b4818f2c5482fe636caabc56b41f5a7..023d1255064c0a56f16c4a7bd81eb6a0566ae351 100644 (file)
@@ -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))
index 76bc7c26e815c5a5b8c116a7db31fd6864c43af3..3cc1d993aff69ee6a7321b273fbe3343190b54b8 100644 (file)
@@ -8,9 +8,9 @@
 ; CHECK: load
 ; CHECK: load
 ; CHECK: fsub
-; CHECK: fmul
 ; CHECK: fsub
 ; CHECK: fmul
+; CHECK: fmul
 ; CHECK-NOT: fsub
 ; CHECK-NOT: fmul