[PATCH] D104148: WIP: [LoopUtils] Fix incorrect runtimechecks

Mindong Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 11 13:17:58 PDT 2021


mdchen created this revision.
Herald added a subscriber: hiraditya.
mdchen requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

As described in https://bugs.llvm.org/show_bug.cgi?id=50686, `expandBounds` that works for LoopVectorize can
generate incorrect runtime checks and lead to unpleasant program results.

This is a quick and immature fix but can point out where the problem is. Also, I want to bring the problem into
discussion ASAP, and it'd be better if this can intrigue better ideas.

TODO: will update a test case later


https://reviews.llvm.org/D104148

Files:
  llvm/lib/Transforms/Utils/LoopUtils.cpp


Index: llvm/lib/Transforms/Utils/LoopUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -1595,7 +1595,7 @@
   // Use this type for pointer arithmetic.
   Type *PtrArithTy = Type::getInt8PtrTy(Ctx, AS);
 
-  if (SE->isLoopInvariant(Sc, TheLoop)) {
+  if (SE->isLoopInvariant(Sc, TheLoop) && CG->Members.size() == 1) {
     LLVM_DEBUG(dbgs() << "LAA: Adding RT check for a loop invariant ptr:"
                       << *Ptr << "\n");
     // Ptr could be in the loop body. If so, expand a new one at the correct


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104148.351542.patch
Type: text/x-patch
Size: 629 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210611/d5ece8dd/attachment.bin>


More information about the llvm-commits mailing list