2019-04-17 12:52:47 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2019-11-07 07:16:43 +08:00
|
|
|
; RUN: opt -S -indvars -indvars-predicate-loops=0 < %s | FileCheck %s
|
2019-04-17 12:52:47 +08:00
|
|
|
|
|
|
|
; Check that we don't reuse %zext instead of %inc11 for LCSSA Phi node. Case
|
|
|
|
; with constants SCEV.
|
|
|
|
|
|
|
|
define i32 @test_01() {
|
|
|
|
; CHECK-LABEL: @test_01(
|
|
|
|
; CHECK-NEXT: entry:
|
|
|
|
; CHECK-NEXT: br label [[FOR_COND1_PREHEADER:%.*]]
|
|
|
|
; CHECK: for.cond1.preheader:
|
|
|
|
; CHECK-NEXT: br label [[FOR_COND4_PREHEADER:%.*]]
|
|
|
|
; CHECK: for.cond4.preheader:
|
|
|
|
; CHECK-NEXT: [[ZEXT:%.*]] = zext i16 1 to i32
|
|
|
|
; CHECK-NEXT: br label [[FOR_BODY6:%.*]]
|
|
|
|
; CHECK: for.cond4:
|
[IndVars] Eliminate loop exits with equivalent exit counts
We can end up with two loop exits whose exit counts are equivalent, but whose textual representation is different and non-obvious. For the sub-case where we have a series of exits which dominate one another (common), eliminate any exits which would iterate *after* a previous exit on the exiting iteration.
As noted in the TODO being removed, I'd always thought this was a good idea, but I've now seen this in a real workload as well.
Interestingly, in review, Nikita pointed out there's let another oppurtunity to leverage SCEV's reasoning. If we kept track of the min of dominanting exits so far, we could discharge exits with EC >= MDE. This is less powerful than the existing transform (since later exits aren't considered), but potentially more powerful for any case where SCEV can prove a >= b, but neither a == b or a > b. I don't have an example to illustrate that oppurtunity, but won't be suprised if we find one and return to handle that case as well.
Differential Revision: https://reviews.llvm.org/D69009
llvm-svn: 375379
2019-10-21 07:38:02 +08:00
|
|
|
; CHECK-NEXT: br i1 true, label [[FOR_BODY6]], label [[FOR_END:%.*]]
|
2019-04-17 12:52:47 +08:00
|
|
|
; CHECK: for.body6:
|
[IndVars] Eliminate loop exits with equivalent exit counts
We can end up with two loop exits whose exit counts are equivalent, but whose textual representation is different and non-obvious. For the sub-case where we have a series of exits which dominate one another (common), eliminate any exits which would iterate *after* a previous exit on the exiting iteration.
As noted in the TODO being removed, I'd always thought this was a good idea, but I've now seen this in a real workload as well.
Interestingly, in review, Nikita pointed out there's let another oppurtunity to leverage SCEV's reasoning. If we kept track of the min of dominanting exits so far, we could discharge exits with EC >= MDE. This is less powerful than the existing transform (since later exits aren't considered), but potentially more powerful for any case where SCEV can prove a >= b, but neither a == b or a > b. I don't have an example to illustrate that oppurtunity, but won't be suprised if we find one and return to handle that case as well.
Differential Revision: https://reviews.llvm.org/D69009
llvm-svn: 375379
2019-10-21 07:38:02 +08:00
|
|
|
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[FOR_COND4_PREHEADER]] ], [ [[INC:%.*]], [[FOR_COND4:%.*]] ]
|
2019-04-17 12:52:47 +08:00
|
|
|
; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i32 [[IV]], [[ZEXT]]
|
|
|
|
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[IV]], 1
|
|
|
|
; CHECK-NEXT: br i1 [[TMP0]], label [[RETURN_LOOPEXIT:%.*]], label [[FOR_COND4]]
|
|
|
|
; CHECK: for.end:
|
|
|
|
; CHECK-NEXT: br i1 false, label [[FOR_COND4_PREHEADER]], label [[FOR_END9:%.*]]
|
|
|
|
; CHECK: for.end9:
|
|
|
|
; CHECK-NEXT: br i1 false, label [[FOR_COND1_PREHEADER]], label [[RETURN_LOOPEXIT3:%.*]]
|
|
|
|
; CHECK: return.loopexit:
|
|
|
|
; CHECK-NEXT: unreachable
|
|
|
|
; CHECK: return.loopexit3:
|
|
|
|
; CHECK-NEXT: br label [[RETURN:%.*]]
|
|
|
|
; CHECK: return:
|
|
|
|
; CHECK-NEXT: ret i32 1
|
|
|
|
;
|
|
|
|
entry:
|
|
|
|
br label %for.cond1.preheader
|
|
|
|
|
|
|
|
for.cond1.preheader: ; preds = %for.end9, %entry
|
|
|
|
br label %for.cond4.preheader
|
|
|
|
|
|
|
|
for.cond4.preheader: ; preds = %for.end, %for.cond1.preheader
|
|
|
|
%zext = zext i16 1 to i32
|
|
|
|
br label %for.body6
|
|
|
|
|
|
|
|
for.cond4: ; preds = %for.body6
|
|
|
|
%cmp5 = icmp ult i32 %inc, 2
|
|
|
|
br i1 %cmp5, label %for.body6, label %for.end
|
|
|
|
|
|
|
|
for.body6: ; preds = %for.cond4, %for.cond4.preheader
|
|
|
|
%iv = phi i32 [ 0, %for.cond4.preheader ], [ %inc, %for.cond4 ]
|
|
|
|
%0 = icmp eq i32 %iv, %zext
|
|
|
|
%inc = add nuw nsw i32 %iv, 1
|
|
|
|
br i1 %0, label %return.loopexit, label %for.cond4
|
|
|
|
|
|
|
|
for.end: ; preds = %for.cond4
|
|
|
|
br i1 false, label %for.cond4.preheader, label %for.end9
|
|
|
|
|
|
|
|
for.end9: ; preds = %for.end
|
|
|
|
%inc11 = add nuw nsw i32 0, 1
|
|
|
|
br i1 false, label %for.cond1.preheader, label %return.loopexit3
|
|
|
|
|
|
|
|
return.loopexit: ; preds = %for.body6
|
|
|
|
unreachable
|
|
|
|
|
|
|
|
return.loopexit3: ; preds = %for.end9
|
|
|
|
%inc11.lcssa = phi i32 [ %inc11, %for.end9 ]
|
|
|
|
br label %return
|
|
|
|
|
|
|
|
return: ; preds = %return.loopexit3
|
|
|
|
ret i32 %inc11.lcssa
|
|
|
|
}
|
|
|
|
|
|
|
|
; Same as test_01, but the instructions with the same SCEV have a non-constant
|
|
|
|
; SCEV.
|
|
|
|
define i32 @test_02(i32 %x) {
|
|
|
|
; CHECK-LABEL: @test_02(
|
|
|
|
; CHECK-NEXT: entry:
|
|
|
|
; CHECK-NEXT: br label [[FOR_COND1_PREHEADER:%.*]]
|
|
|
|
; CHECK: for.cond1.preheader:
|
|
|
|
; CHECK-NEXT: br label [[FOR_COND4_PREHEADER:%.*]]
|
|
|
|
; CHECK: for.cond4.preheader:
|
|
|
|
; CHECK-NEXT: [[ZEXT:%.*]] = mul i32 [[X:%.*]], 1
|
|
|
|
; CHECK-NEXT: br label [[FOR_BODY6:%.*]]
|
|
|
|
; CHECK: for.cond4:
|
|
|
|
; CHECK-NEXT: [[CMP5:%.*]] = icmp ult i32 [[INC:%.*]], 2
|
|
|
|
; CHECK-NEXT: br i1 [[CMP5]], label [[FOR_BODY6]], label [[FOR_END:%.*]]
|
|
|
|
; CHECK: for.body6:
|
|
|
|
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[FOR_COND4_PREHEADER]] ], [ [[INC]], [[FOR_COND4:%.*]] ]
|
|
|
|
; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i32 [[IV]], [[ZEXT]]
|
|
|
|
; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[IV]], 1
|
|
|
|
; CHECK-NEXT: br i1 [[TMP0]], label [[RETURN_LOOPEXIT:%.*]], label [[FOR_COND4]]
|
|
|
|
; CHECK: for.end:
|
|
|
|
; CHECK-NEXT: br i1 false, label [[FOR_COND4_PREHEADER]], label [[FOR_END9:%.*]]
|
|
|
|
; CHECK: for.end9:
|
|
|
|
; CHECK-NEXT: br i1 false, label [[FOR_COND1_PREHEADER]], label [[RETURN_LOOPEXIT3:%.*]]
|
|
|
|
; CHECK: return.loopexit:
|
|
|
|
; CHECK-NEXT: unreachable
|
|
|
|
; CHECK: return.loopexit3:
|
|
|
|
; CHECK-NEXT: br label [[RETURN:%.*]]
|
|
|
|
; CHECK: return:
|
2019-08-01 05:15:21 +08:00
|
|
|
; CHECK-NEXT: ret i32 [[X]]
|
2019-04-17 12:52:47 +08:00
|
|
|
;
|
|
|
|
entry:
|
|
|
|
br label %for.cond1.preheader
|
|
|
|
|
|
|
|
for.cond1.preheader: ; preds = %for.end9, %entry
|
|
|
|
br label %for.cond4.preheader
|
|
|
|
|
|
|
|
for.cond4.preheader: ; preds = %for.end, %for.cond1.preheader
|
|
|
|
%zext = mul i32 %x, 1
|
|
|
|
br label %for.body6
|
|
|
|
|
|
|
|
for.cond4: ; preds = %for.body6
|
|
|
|
%cmp5 = icmp ult i32 %inc, 2
|
|
|
|
br i1 %cmp5, label %for.body6, label %for.end
|
|
|
|
|
|
|
|
for.body6: ; preds = %for.cond4, %for.cond4.preheader
|
|
|
|
%iv = phi i32 [ 0, %for.cond4.preheader ], [ %inc, %for.cond4 ]
|
|
|
|
%0 = icmp eq i32 %iv, %zext
|
|
|
|
%inc = add nuw nsw i32 %iv, 1
|
|
|
|
br i1 %0, label %return.loopexit, label %for.cond4
|
|
|
|
|
|
|
|
for.end: ; preds = %for.cond4
|
|
|
|
br i1 false, label %for.cond4.preheader, label %for.end9
|
|
|
|
|
|
|
|
for.end9: ; preds = %for.end
|
|
|
|
%inc11 = add nuw nsw i32 0, %x
|
|
|
|
br i1 false, label %for.cond1.preheader, label %return.loopexit3
|
|
|
|
|
|
|
|
return.loopexit: ; preds = %for.body6
|
|
|
|
unreachable
|
|
|
|
|
|
|
|
return.loopexit3: ; preds = %for.end9
|
|
|
|
%inc11.lcssa = phi i32 [ %inc11, %for.end9 ]
|
|
|
|
br label %return
|
|
|
|
|
|
|
|
return: ; preds = %return.loopexit3
|
|
|
|
ret i32 %inc11.lcssa
|
|
|
|
}
|