1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

[IndVarSimplify] Ignore unreachable users of truncs

If a trunc has a user in a block which is not reachable from entry,
we can safely perform trunc elimination as if this user didn't exist.

llvm-svn: 335816
This commit is contained in:
Max Kazantsev 2018-06-28 08:20:03 +00:00
parent 68d7181227
commit 73d0084174
2 changed files with 51 additions and 0 deletions

View File

@ -535,6 +535,10 @@ bool SimplifyIndvar::eliminateTrunc(TruncInst *TI) {
// Bail if we find something different.
SmallVector<ICmpInst *, 4> ICmpUsers;
for (auto *U : TI->users()) {
// We don't care about users in unreachable blocks.
if (isa<Instruction>(U) &&
!DT->isReachableFromEntry(cast<Instruction>(U)->getParent()))
continue;
if (ICmpInst *ICI = dyn_cast<ICmpInst>(U)) {
if (ICI->getOperand(0) == TI && L->isLoopInvariant(ICI->getOperand(1))) {
assert(L->contains(ICI->getParent()) && "LCSSA form broken?");

View File

@ -484,3 +484,50 @@ loop:
exit:
ret void
}
define void @test_11() {
; CHECK-LABEL: @test_11(
; CHECK-NEXT: br label [[BB1:%.*]]
; CHECK: bb1:
; CHECK-NEXT: br i1 undef, label [[BB2:%.*]], label [[BB6:%.*]]
; CHECK: bb2:
; CHECK-NEXT: br i1 undef, label [[BB3:%.*]], label [[BB4:%.*]]
; CHECK: bb3:
; CHECK-NEXT: br label [[BB4]]
; CHECK: bb4:
; CHECK-NEXT: br label [[BB6]]
; CHECK: bb5:
; CHECK-NEXT: [[_TMP24:%.*]] = icmp slt i16 undef, 0
; CHECK-NEXT: br i1 [[_TMP24]], label [[BB5:%.*]], label [[BB5]]
; CHECK: bb6:
; CHECK-NEXT: br i1 false, label [[BB1]], label [[BB7:%.*]]
; CHECK: bb7:
; CHECK-NEXT: ret void
;
br label %bb1
bb1: ; preds = %bb6, %0
%e.5.0 = phi i32 [ 0, %0 ], [ %_tmp32, %bb6 ]
br i1 undef, label %bb2, label %bb6
bb2: ; preds = %bb1
%_tmp15 = trunc i32 %e.5.0 to i16
br i1 undef, label %bb3, label %bb4
bb3: ; preds = %bb2
br label %bb4
bb4: ; preds = %bb3, %bb2
br label %bb6
bb5: ; preds = %bb5, %bb5
%_tmp24 = icmp slt i16 %_tmp15, 0
br i1 %_tmp24, label %bb5, label %bb5
bb6: ; preds = %bb4, %bb1
%_tmp32 = add nuw nsw i32 %e.5.0, 1
br i1 false, label %bb1, label %bb7
bb7: ; preds = %bb6
ret void
}