[PATCH] D21720: Unroll for uncountable loops

Michael Zolotukhin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 14 16:45:06 PST 2016

mzolotukhin added inline comments.

Comment at: lib/Transforms/Scalar/LoopUnrollPass.cpp:430-434
+      if ((TripCount & 1) == 0) {
+        if (IL && IL->getOpcode() == Instruction::Xor &&
+            IL->getOperand(0) == PHI && L->isLoopInvariant(IL->getOperand(1))) {
+          Constant *CP = dyn_cast<Constant>(VP);
+          if (Iteration & 1)
This look very hacky. What is the motivation of this change? How often do we see such loops?

If we do want to handle such cases (which I'm not convinced now), then we should do it in a general way. That is, the logic should be in instruction visitors, and we should automagically deduce that these instructions are free. There are more cases than just xor - we can multiply by -1, and we should be able to handle in a similar way. In the current form the code is not easily extensible to handle new cases.



More information about the llvm-commits mailing list