[PATCH] D12107: Replace overflow check in loop vectorization with minimum loop iterations check

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 24 14:48:42 PDT 2015


anemet accepted this revision.
anemet added a comment.
This revision is now accepted and ready to land.

LGTM with some minor changes below.

Also did you see any change in performance?


================
Comment at: lib/Transforms/Vectorize/LoopVectorize.cpp:2528-2536
@@ -2527,16 +2527,11 @@
 
-  // We need to test whether the backedge-taken count is uint##_max. Adding one
-  // to it will cause overflow and an incorrect loop trip count in the vector
-  // body. In case of overflow we want to directly jump to the scalar remainder
-  // loop.
-  Value *BackedgeCount =
-      Exp.expandCodeFor(BackedgeTakeCount, BackedgeTakeCount->getType(),
-                        VectorPH->getTerminator());
-  if (BackedgeCount->getType()->isPointerTy())
-    BackedgeCount = CastInst::CreatePointerCast(BackedgeCount, IdxTy,
-                                                "backedge.ptrcnt.to.int",
-                                                VectorPH->getTerminator());
-  Instruction *CheckBCOverflow =
-      CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, BackedgeCount,
-                      Constant::getAllOnesValue(BackedgeCount->getType()),
-                      "backedge.overflow", VectorPH->getTerminator());
+  // The loop minimum iterations check below is to ensure the loop has enough
+  // trip count so the generated vector loop will likely be executed and the
+  // preparation and rounding-off costs will likely be worthy.
+  //
+  // We also need to test whether the backedge-taken count is uint##_max.
+  // Adding one to it will cause overflow and an incorrect loop trip count
+  // in the vector body. In case of overflow we want to directly jump to the
+  // scalar remainder loop. The overflow test is to check whether BackedgeCount
+  // equals to -1. This check is covered by the minimum loop iterations check.
+  Value *ExitCountValue = Exp.expandCodeFor(ExitCount, ExitCount->getType(),
----------------
The second paragraph is unnecessarily complicated.   It should say something like this:

The minimum iteration check also covers case where the backedge-taken count is uint##_max.  Adding one to it will cause overflow and an incorrect loop trip count being generated in the vector body. In this case we also want to directly jump to the scalar remainder loop.

================
Comment at: test/Transforms/LoopVectorize/miniters.ll:11
@@ +10,3 @@
+
+; Generate min.iters.check to skip the vector loop and jump to scalar.ph directly when loop iteration number is less than MaxVectorSize.
+; CHECK-LABEL: foo(
----------------
You still have MaxVectorSize mentioned here.


Repository:
  rL LLVM

http://reviews.llvm.org/D12107





More information about the llvm-commits mailing list