[llvm] r335816 - [IndVarSimplify] Ignore unreachable users of truncs
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 28 01:20:03 PDT 2018
Author: mkazantsev
Date: Thu Jun 28 01:20:03 2018
New Revision: 335816
URL: http://llvm.org/viewvc/llvm-project?rev=335816&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp
llvm/trunk/test/Transforms/IndVarSimplify/eliminate-trunc.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp?rev=335816&r1=335815&r2=335816&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyIndVar.cpp Thu Jun 28 01:20:03 2018
@@ -535,6 +535,10 @@ bool SimplifyIndvar::eliminateTrunc(Trun
// 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?");
Modified: llvm/trunk/test/Transforms/IndVarSimplify/eliminate-trunc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/eliminate-trunc.ll?rev=335816&r1=335815&r2=335816&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/eliminate-trunc.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/eliminate-trunc.ll Thu Jun 28 01:20:03 2018
@@ -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
+}
More information about the llvm-commits
mailing list