From 9f06ef76d3cbaaf945f57a80059f0c6d3679a4c4 Mon Sep 17 00:00:00 2001 From: Michael Zolotukhin Date: Wed, 29 Jul 2015 18:10:33 +0000 Subject: [PATCH] [Unroll] Handle SwitchInst properly. Previously successor selection was simply wrong. llvm-svn: 243545 --- llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp | 4 ++-- .../Transforms/LoopUnroll/full-unroll-crashers.ll | 24 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp index 25b0877..6b64d4e 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -619,8 +619,8 @@ analyzeLoopUnrollCost(const Loop *L, unsigned TripCount, ScalarEvolution &SE, if (isa(SimpleCond)) Succ = SI->getSuccessor(0); else - Succ = - SI->getSuccessor(cast(SimpleCond)->getSExtValue()); + Succ = SI->findCaseValue(cast(SimpleCond)) + .getCaseSuccessor(); if (L->contains(Succ)) BBWorklist.insert(Succ); continue; diff --git a/llvm/test/Transforms/LoopUnroll/full-unroll-crashers.ll b/llvm/test/Transforms/LoopUnroll/full-unroll-crashers.ll index 0bf1327..eebf5a0 100644 --- a/llvm/test/Transforms/LoopUnroll/full-unroll-crashers.ll +++ b/llvm/test/Transforms/LoopUnroll/full-unroll-crashers.ll @@ -57,3 +57,27 @@ for.inc: ; preds = %for.body, %if.then for.end: ; preds = %for.inc ret void } + +define void @switch() { +entry: + br label %for.body + +for.body: + %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.inc ] + %arrayidx1 = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %iv.0 + %x1 = load i32, i32* %arrayidx1, align 4 + switch i32 %x1, label %l1 [ + ] + +l1: + %x2 = add i32 %x1, 2 + br label %for.inc + +for.inc: + %iv.1 = add nuw nsw i64 %iv.0, 1 + %exitcond = icmp eq i64 %iv.1, 10 + br i1 %exitcond, label %for.end, label %for.body + +for.end: + ret void +} -- 2.7.4