[llvm] r277785 - GVN-hoist: fix early exit logic

Sebastian Pop via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 4 16:49:05 PDT 2016


Author: spop
Date: Thu Aug  4 18:49:05 2016
New Revision: 277785

URL: http://llvm.org/viewvc/llvm-project?rev=277785&view=rev
Log:
GVN-hoist: fix early exit logic

The patch splits a complex && if condition into easier to read and understand
logic.  That wrong early exit condition was letting some instructions with not
all operands available pass through when HoistingGeps was true.

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

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

Modified: llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp?rev=277785&r1=277784&r2=277785&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp Thu Aug  4 18:49:05 2016
@@ -750,12 +750,19 @@ private:
         Repl = InstructionsToHoist.front();
 
         // We can move Repl in HoistPt only when all operands are available.
-        // When not HoistingGeps we need to copy the GEPs now.
         // The order in which hoistings are done may influence the availability
         // of operands.
-        if (!allOperandsAvailable(Repl, HoistPt) && !HoistingGeps &&
-            !makeGepOperandsAvailable(Repl, HoistPt, InstructionsToHoist))
-          continue;
+        if (!allOperandsAvailable(Repl, HoistPt)) {
+
+          // When HoistingGeps there is nothing more we can do to make the
+          // operands available: just continue.
+          if (HoistingGeps)
+            continue;
+
+          // When not HoistingGeps we need to copy the GEPs.
+          if (!makeGepOperandsAvailable(Repl, HoistPt, InstructionsToHoist))
+            continue;
+        }
 
         // Move the instruction at the end of HoistPt.
         Instruction *Last = HoistPt->getTerminator();

Added: llvm/trunk/test/Transforms/GVN/hoist-call.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/hoist-call.ll?rev=277785&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GVN/hoist-call.ll (added)
+++ llvm/trunk/test/Transforms/GVN/hoist-call.ll Thu Aug  4 18:49:05 2016
@@ -0,0 +1,28 @@
+; RUN: opt -S -gvn-hoist < %s | FileCheck %s
+
+; Check that the call and fcmp are hoisted.
+; CHECK-LABEL: define void @fun(
+; CHECK: call float
+; CHECK: fcmp oeq
+; CHECK-NOT: call float
+; CHECK-NOT: fcmp oeq
+
+define void @fun(float %__b) minsize {
+entry:
+  br label %if.then
+
+if.then:                                          ; preds = %entry
+  br i1 undef, label %if.then8, label %lor.lhs.false
+
+lor.lhs.false:                                    ; preds = %if.then
+  %0 = call float @llvm.fabs.f32(float %__b) #2
+  %cmpinf7 = fcmp oeq float %0, 0x7FF0000000000000
+  unreachable
+
+if.then8:                                         ; preds = %if.then
+  %1 = call float @llvm.fabs.f32(float %__b) #2
+  %cmpinf10 = fcmp oeq float %1, 0x7FF0000000000000
+  ret void
+}
+
+declare float @llvm.fabs.f32(float)

Modified: llvm/trunk/test/Transforms/GVN/hoist-recursive-geps.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/hoist-recursive-geps.ll?rev=277785&r1=277784&r2=277785&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GVN/hoist-recursive-geps.ll (original)
+++ llvm/trunk/test/Transforms/GVN/hoist-recursive-geps.ll Thu Aug  4 18:49:05 2016
@@ -100,4 +100,4 @@ define zeroext i1 @fun(%2*, %12* derefer
   %53 = load double, double* %9, align 8
   %54 = fcmp olt double %52, %53
   ret i1 %54
-}
\ No newline at end of file
+}

Modified: llvm/trunk/test/Transforms/GVN/hoist.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/hoist.ll?rev=277785&r1=277784&r2=277785&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GVN/hoist.ll (original)
+++ llvm/trunk/test/Transforms/GVN/hoist.ll Thu Aug  4 18:49:05 2016
@@ -223,10 +223,10 @@ if.end:
 
 ; Check that all independent expressions are hoisted.
 ; CHECK-LABEL: @independentScalarsHoisting
-; CHECK: fadd
 ; CHECK: fsub
 ; CHECK: fdiv
 ; CHECK: fmul
+; CHECK: fadd
 ; CHECK-NOT: fsub
 ; CHECK-NOT: fdiv
 ; CHECK-NOT: fmul




More information about the llvm-commits mailing list