diff options
author | Philip Reames <listmail@philipreames.com> | 2019-06-23 17:06:57 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2019-06-23 17:06:57 +0000 |
commit | d22a2a9a7264ebe6468c5776b0e95d4dcf800ef5 (patch) | |
tree | 556ce88652bc43e5325f9b64113c4334f6f3e755 | |
parent | f955d5f623dd18d87e8b8bd6857cc0dbc1ec636d (diff) | |
download | bcm5719-llvm-d22a2a9a7264ebe6468c5776b0e95d4dcf800ef5.tar.gz bcm5719-llvm-d22a2a9a7264ebe6468c5776b0e95d4dcf800ef5.zip |
[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
4 files changed, 7 insertions, 19 deletions
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 57f246373f0..c173f9e4c03 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -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; } diff --git a/llvm/test/Transforms/IndVarSimplify/eliminate-comparison.ll b/llvm/test/Transforms/IndVarSimplify/eliminate-comparison.ll index 49088601125..4b4a05a94f5 100644 --- a/llvm/test/Transforms/IndVarSimplify/eliminate-comparison.ll +++ b/llvm/test/Transforms/IndVarSimplify/eliminate-comparison.ll @@ -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() diff --git a/llvm/test/Transforms/IndVarSimplify/eliminate-trunc.ll b/llvm/test/Transforms/IndVarSimplify/eliminate-trunc.ll index eaa20b5bf6d..74e422b797b 100644 --- a/llvm/test/Transforms/IndVarSimplify/eliminate-trunc.ll +++ b/llvm/test/Transforms/IndVarSimplify/eliminate-trunc.ll @@ -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 diff --git a/llvm/test/Transforms/IndVarSimplify/floating-point-iv.ll b/llvm/test/Transforms/IndVarSimplify/floating-point-iv.ll index c5bf3860ab5..ef08863428e 100644 --- a/llvm/test/Transforms/IndVarSimplify/floating-point-iv.ll +++ b/llvm/test/Transforms/IndVarSimplify/floating-point-iv.ll @@ -50,7 +50,7 @@ bb: ; preds = %bb, %entry return: ret void ; CHECK-LABEL: @test3( -; CHECK: fcmp +; CHECK: br i1 false } define void @test4() nounwind { |