llvm.org GIT mirror llvm / 91371a5
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364155 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 2 months ago
4 changed file(s) with 7 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
27312731 if (ExitCount->isZero()) {
27322732 auto *BI = cast(ExitingBB->getTerminator());
27332733 bool ExitIfTrue = !L->contains(*succ_begin(ExitingBB));
2734 auto *NewCond = ExitIfTrue ?
2735 ConstantInt::getTrue(BI->getCondition()->getType()) :
2736 ConstantInt::getFalse(BI->getCondition()->getType());
2734 auto *OldCond = BI->getCondition();
2735 auto *NewCond = ExitIfTrue ? ConstantInt::getTrue(OldCond->getType()) :
2736 ConstantInt::getFalse(OldCond->getType());
27372737 BI->setCondition(NewCond);
2738 if (OldCond->use_empty())
2739 DeadInsts.push_back(OldCond);
27382740 Changed = true;
27392741 continue;
27402742 }
275275 ; CHECK-NEXT: tail call void @llvm.trap()
276276 ; CHECK-NEXT: unreachable
277277 ; CHECK: forcond38:
278 ; CHECK-NEXT: [[__KEY8_0:%.*]] = phi i32 [ [[TMP81:%.*]], [[NOASSERT68:%.*]] ], [ 2, [[FORCOND38_PREHEADER]] ]
279 ; CHECK-NEXT: br i1 true, label [[NOASSERT68]], label [[UNROLLEDEND:%.*]]
278 ; CHECK-NEXT: br i1 true, label [[NOASSERT68:%.*]], label [[UNROLLEDEND:%.*]]
280279 ; CHECK: noassert68:
281 ; CHECK-NEXT: [[TMP57:%.*]] = sdiv i32 -32768, [[__KEY8_0]]
282 ; CHECK-NEXT: [[SEXT34:%.*]] = shl i32 [[TMP57]], 16
283 ; CHECK-NEXT: [[SEXT21:%.*]] = shl i32 [[TMP57]], 16
284 ; CHECK-NEXT: [[TMP76:%.*]] = icmp ne i32 [[SEXT34]], [[SEXT21]]
285 ; CHECK-NEXT: [[TMP81]] = add nuw nsw i32 [[__KEY8_0]], 1
286280 ; CHECK-NEXT: br i1 false, label [[FORCOND38]], label [[ASSERT77:%.*]]
287281 ; CHECK: assert77:
288282 ; CHECK-NEXT: tail call void @llvm.trap()
169169 ; CHECK-NEXT: entry:
170170 ; CHECK-NEXT: br label [[LOOP:%.*]]
171171 ; CHECK: loop:
172 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ -2147483649, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
173 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
174 ; CHECK-NEXT: [[NARROW_IV:%.*]] = trunc i64 [[IV]] to i32
175 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[NARROW_IV]], [[N:%.*]]
176172 ; CHECK-NEXT: br i1 false, label [[LOOP]], label [[EXIT:%.*]]
177173 ; CHECK: exit:
178174 ; CHECK-NEXT: ret void
349345 ; CHECK-NEXT: entry:
350346 ; CHECK-NEXT: br label [[LOOP:%.*]]
351347 ; CHECK: loop:
352 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ -1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
353 ; CHECK-NEXT: [[IV_NEXT]] = add nsw i64 [[IV]], 1
354 ; CHECK-NEXT: [[NARROW_IV:%.*]] = trunc i64 [[IV]] to i32
355 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[NARROW_IV]], [[N:%.*]]
356348 ; CHECK-NEXT: br i1 false, label [[LOOP]], label [[EXIT:%.*]]
357349 ; CHECK: exit:
358350 ; CHECK-NEXT: ret void
4949 return:
5050 ret void
5151 ; CHECK-LABEL: @test3(
52 ; CHECK: fcmp
52 ; CHECK: br i1 false
5353 }
5454
5555 define void @test4() nounwind {