[PATCH] D11276: [LoopUnswitch] Code refactoring to separate trivial loop unswitch and non-trivial loop unswitch in processCurrentLoop()

Philip Reames listmail at philipreames.com
Fri Jul 17 17:53:11 PDT 2015


reames added a comment.

Comments inline.

p.s. What's the motivation for this?  Is it a step towards a transform or just general code cleanup?


================
Comment at: lib/Transforms/Scalar/LoopUnswitch.cpp:834
@@ +833,3 @@
+// TryTrivialLoopUnswitch - Check if loop header block's terminator is a trivial
+// unswitch condition (loop header block is the only possible block to have a
+// trivial unswitch condition). If it is, always unswitch becayse there is no
----------------
why is the header the only possible trivial unswitch?  (I know the answer, but it's not obvious from the comment.)

================
Comment at: lib/Transforms/Scalar/LoopUnswitch.cpp:835
@@ +834,3 @@
+// unswitch condition (loop header block is the only possible block to have a
+// trivial unswitch condition). If it is, always unswitch becayse there is no
+// code growth for this case.
----------------
spelling

================
Comment at: lib/Transforms/Scalar/LoopUnswitch.cpp:841
@@ +840,3 @@
+
+  Constant *CondVal = nullptr;
+  BasicBlock *ExitBlock = nullptr;
----------------
This code can be greatly simplified by inlining the definition of FindLIVLoopCondition and IsTrivialUnswitchCondition.  If I'm reading the code right, you'd basically end up with the existing code in isTrivialUnswitchCondition plus getting the condition from the branch and checking that it's loop invariant.  

To put it differently, the generality of this code is actively confusing, not helping.  

================
Comment at: lib/Transforms/Scalar/LoopUnswitch.cpp:855
@@ +854,3 @@
+        UnswitchTrivialCondition(currentLoop, LoopCond, CondVal, ExitBlock, HeaderTerm);
+        return true;
+      }
----------------
You're missing the NumBranches and NumSwitches statistic updates here.  You might be better off introducing new statistics for the trivial cases for reporting though.


http://reviews.llvm.org/D11276







More information about the llvm-commits mailing list