1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[IndVars] Remove dead instructions after folding trivial loop exit

In rL364135, I taught IndVars to fold exiting branches in loops with a zero backedge taken count (i.e. loops that only run one iteration).  This extends that to eliminate the dead comparison left around.  

llvm-svn: 364155
This commit is contained in:
Philip Reames 2019-06-23 17:06:57 +00:00
parent 4a716ac9b6
commit 91b3493b11
4 changed files with 7 additions and 19 deletions

View File

@ -2732,10 +2732,12 @@ bool IndVarSimplify::run(Loop *L) {
if (ExitCount->isZero()) {
auto *BI = cast<BranchInst>(ExitingBB->getTerminator());
bool ExitIfTrue = !L->contains(*succ_begin(ExitingBB));
auto *NewCond = ExitIfTrue ?
ConstantInt::getTrue(BI->getCondition()->getType()) :
ConstantInt::getFalse(BI->getCondition()->getType());
auto *OldCond = BI->getCondition();
auto *NewCond = ExitIfTrue ? ConstantInt::getTrue(OldCond->getType()) :
ConstantInt::getFalse(OldCond->getType());
BI->setCondition(NewCond);
if (OldCond->use_empty())
DeadInsts.push_back(OldCond);
Changed = true;
continue;
}

View File

@ -276,14 +276,8 @@ define i32 @func_12() nounwind uwtable {
; CHECK-NEXT: tail call void @llvm.trap()
; CHECK-NEXT: unreachable
; CHECK: forcond38:
; CHECK-NEXT: [[__KEY8_0:%.*]] = phi i32 [ [[TMP81:%.*]], [[NOASSERT68:%.*]] ], [ 2, [[FORCOND38_PREHEADER]] ]
; CHECK-NEXT: br i1 true, label [[NOASSERT68]], label [[UNROLLEDEND:%.*]]
; CHECK-NEXT: br i1 true, label [[NOASSERT68:%.*]], label [[UNROLLEDEND:%.*]]
; CHECK: noassert68:
; CHECK-NEXT: [[TMP57:%.*]] = sdiv i32 -32768, [[__KEY8_0]]
; CHECK-NEXT: [[SEXT34:%.*]] = shl i32 [[TMP57]], 16
; CHECK-NEXT: [[SEXT21:%.*]] = shl i32 [[TMP57]], 16
; CHECK-NEXT: [[TMP76:%.*]] = icmp ne i32 [[SEXT34]], [[SEXT21]]
; CHECK-NEXT: [[TMP81]] = add nuw nsw i32 [[__KEY8_0]], 1
; CHECK-NEXT: br i1 false, label [[FORCOND38]], label [[ASSERT77:%.*]]
; CHECK: assert77:
; CHECK-NEXT: tail call void @llvm.trap()

View File

@ -170,10 +170,6 @@ define void @test_06(i32 %n) {
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ -2147483649, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
; CHECK-NEXT: [[NARROW_IV:%.*]] = trunc i64 [[IV]] to i32
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[NARROW_IV]], [[N:%.*]]
; CHECK-NEXT: br i1 false, label [[LOOP]], label [[EXIT:%.*]]
; CHECK: exit:
; CHECK-NEXT: ret void
@ -350,10 +346,6 @@ define void @test_06_unsigned(i32 %n) {
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ -1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
; CHECK-NEXT: [[IV_NEXT]] = add nsw i64 [[IV]], 1
; CHECK-NEXT: [[NARROW_IV:%.*]] = trunc i64 [[IV]] to i32
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[NARROW_IV]], [[N:%.*]]
; CHECK-NEXT: br i1 false, label [[LOOP]], label [[EXIT:%.*]]
; CHECK: exit:
; CHECK-NEXT: ret void

View File

@ -50,7 +50,7 @@ bb: ; preds = %bb, %entry
return:
ret void
; CHECK-LABEL: @test3(
; CHECK: fcmp
; CHECK: br i1 false
}
define void @test4() nounwind {