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

Mindong Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 13 23:10:58 PDT 2021


mdchen updated this revision to Diff 351781.
mdchen added a comment.

Added a test case.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104148/new/

https://reviews.llvm.org/D104148

Files:
  llvm/lib/Transforms/Utils/LoopUtils.cpp
  llvm/test/Transforms/LoopVectorize/pr50686.ll


Index: llvm/test/Transforms/LoopVectorize/pr50686.ll
===================================================================
--- llvm/test/Transforms/LoopVectorize/pr50686.ll
+++ llvm/test/Transforms/LoopVectorize/pr50686.ll
@@ -7,6 +7,7 @@
 ; CHECK-LABEL: @m(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[P1:%.*]] = bitcast i32* [[P:%.*]] to i8*
+; CHECK-NEXT:    [[P23:%.*]] = bitcast i32* [[P2:%.*]] to i8*
 ; CHECK-NEXT:    [[I:%.*]] = load i32, i32* @k, align 4
 ; CHECK-NEXT:    [[CMP32:%.*]] = icmp slt i32 [[I]], [[Q:%.*]]
 ; CHECK-NEXT:    br i1 [[CMP32]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND2_PREHEADER:%.*]]
@@ -15,18 +16,15 @@
 ; CHECK:       for.cond2.preheader.loopexit:
 ; CHECK-NEXT:    br label [[FOR_COND2_PREHEADER]]
 ; CHECK:       for.cond2.preheader:
-; CHECK-NEXT:    [[ARRAYIDX9_1:%.*]] = getelementptr inbounds i32, i32* [[P2:%.*]], i64 1
+; CHECK-NEXT:    [[ARRAYIDX9_1:%.*]] = getelementptr inbounds i32, i32* [[P2]], i64 1
 ; CHECK-NEXT:    [[ARRAYIDX9_2:%.*]] = getelementptr inbounds i32, i32* [[P2]], i64 2
+; CHECK-NEXT:    [[ARRAYIDX9_24:%.*]] = bitcast i32* [[ARRAYIDX9_2]] to i8*
 ; CHECK-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
 ; CHECK:       vector.memcheck:
 ; CHECK-NEXT:    [[SCEVGEP:%.*]] = getelementptr i32, i32* [[P]], i64 63
 ; CHECK-NEXT:    [[SCEVGEP2:%.*]] = bitcast i32* [[SCEVGEP]] to i8*
-; CHECK-NEXT:    [[SCEVGEP3:%.*]] = getelementptr i32, i32* [[P2]], i64 2
-; CHECK-NEXT:    [[SCEVGEP34:%.*]] = bitcast i32* [[SCEVGEP3]] to i8*
-; CHECK-NEXT:    [[UGLYGEP:%.*]] = getelementptr i8, i8* [[SCEVGEP34]], i64 1
-; CHECK-NEXT:    [[BC:%.*]] = bitcast i32* [[ARRAYIDX9_2]] to i8*
-; CHECK-NEXT:    [[BOUND0:%.*]] = icmp ult i8* [[P1]], [[UGLYGEP]]
-; CHECK-NEXT:    [[BOUND1:%.*]] = icmp ult i8* [[BC]], [[SCEVGEP2]]
+; CHECK-NEXT:    [[BOUND0:%.*]] = icmp ult i8* [[P1]], [[ARRAYIDX9_24]]
+; CHECK-NEXT:    [[BOUND1:%.*]] = icmp ult i8* [[P23]], [[SCEVGEP2]]
 ; CHECK-NEXT:    [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
 ; CHECK-NEXT:    [[MEMCHECK_CONFLICT:%.*]] = and i1 [[FOUND_CONFLICT]], true
 ; CHECK-NEXT:    br i1 [[MEMCHECK_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
Index: llvm/lib/Transforms/Utils/LoopUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -1535,7 +1535,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.351781.patch
Type: text/x-patch
Size: 2830 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210614/577b2892/attachment.bin>


More information about the llvm-commits mailing list