[PATCH] D89378: [LoopFlatten] Loop limit invariant checks
Sjoerd Meijer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 14 02:34:58 PDT 2020
SjoerdMeijer created this revision.
SjoerdMeijer added reviewers: ostannard, dmgreen, fhahn.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
SjoerdMeijer requested review of this revision.
If the loop limit is not invariant don't directly bail out, but try to make it invariant with makeLoopInvariant.
I precommitted the test case for this in rG20c7ab87a78c <https://reviews.llvm.org/rG20c7ab87a78c8d808a7d1e662d5bfd580dcdc12e>.
https://reviews.llvm.org/D89378
Files:
llvm/lib/Transforms/Scalar/LoopFlatten.cpp
llvm/test/Transforms/LoopFlatten/limit-not-invariant.ll
Index: llvm/test/Transforms/LoopFlatten/limit-not-invariant.ll
===================================================================
--- llvm/test/Transforms/LoopFlatten/limit-not-invariant.ll
+++ llvm/test/Transforms/LoopFlatten/limit-not-invariant.ll
@@ -11,11 +11,11 @@
; CHECK-NEXT: br i1 [[CMP26_NOT]], label [[FOR_END12:%.*]], label [[FOR_COND1_PREHEADER_LR_PH:%.*]]
; CHECK: for.cond1.preheader.lr.ph:
; CHECK-NEXT: [[CONV4:%.*]] = sext i16 [[VAL:%.*]] to i32
+; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[N]] to i64
; CHECK-NEXT: br label [[FOR_COND1_PREHEADER_US:%.*]]
; CHECK: for.cond1.preheader.us:
; CHECK-NEXT: [[I_027_US:%.*]] = phi i32 [ 0, [[FOR_COND1_PREHEADER_LR_PH]] ], [ [[INC11_US:%.*]], [[FOR_COND1_FOR_INC10_CRIT_EDGE_US:%.*]] ]
; CHECK-NEXT: [[MUL_US:%.*]] = mul i32 [[I_027_US]], [[N]]
-; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[N]] to i64
; CHECK-NEXT: br label [[FOR_BODY3_US:%.*]]
; CHECK: for.body3.us:
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[FOR_COND1_PREHEADER_US]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY3_US]] ]
@@ -88,11 +88,11 @@
; CHECK-NEXT: br i1 [[CMP26_NOT]], label [[FOR_END12:%.*]], label [[FOR_COND1_PREHEADER_LR_PH:%.*]]
; CHECK: for.cond1.preheader.lr.ph:
; CHECK-NEXT: [[CONV4:%.*]] = sext i16 [[VAL:%.*]] to i32
+; CHECK-NEXT: [[TRUNC_TRIP_COUNT:%.*]] = trunc i64 [[M:%.*]] to i32
; CHECK-NEXT: br label [[FOR_COND1_PREHEADER_US:%.*]]
; CHECK: for.cond1.preheader.us:
; CHECK-NEXT: [[I_027_US:%.*]] = phi i32 [ 0, [[FOR_COND1_PREHEADER_LR_PH]] ], [ [[INC11_US:%.*]], [[FOR_COND1_FOR_INC10_CRIT_EDGE_US:%.*]] ]
; CHECK-NEXT: [[MUL_US:%.*]] = mul i32 [[I_027_US]], [[N]]
-; CHECK-NEXT: [[TRUNC_TRIP_COUNT:%.*]] = trunc i64 [[M:%.*]] to i32
; CHECK-NEXT: br label [[FOR_BODY3_US:%.*]]
; CHECK: for.body3.us:
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[FOR_COND1_PREHEADER_US]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY3_US]] ]
Index: llvm/lib/Transforms/Scalar/LoopFlatten.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopFlatten.cpp
+++ llvm/lib/Transforms/Scalar/LoopFlatten.cpp
@@ -429,11 +429,12 @@
// Both of the loop limit values must be invariant in the outer loop
// (non-instructions are all inherently invariant).
- if (!OuterLoop->isLoopInvariant(InnerLimit)) {
+ bool Changed;
+ if (!OuterLoop->makeLoopInvariant(InnerLimit, Changed)) {
LLVM_DEBUG(dbgs() << "inner loop limit not invariant\n");
return false;
}
- if (!OuterLoop->isLoopInvariant(OuterLimit)) {
+ if (!OuterLoop->makeLoopInvariant(OuterLimit, Changed)) {
LLVM_DEBUG(dbgs() << "outer loop limit not invariant\n");
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89378.298087.patch
Type: text/x-patch
Size: 2787 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201014/3ea0099f/attachment.bin>
More information about the llvm-commits
mailing list