From 2a7fbb1927153390dd2f04958f79c2ecca11b87e Mon Sep 17 00:00:00 2001 From: James Molloy Date: Mon, 16 Feb 2015 17:02:00 +0000 Subject: [PATCH] [LoopReroll] Relax some assumptions a little. We won't find a root with index zero in any loop that we are able to reroll. However, we may find one in a non-rerollable loop, so bail gracefully instead of failing hard. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229406 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopRerollPass.cpp | 9 ++++--- test/Transforms/LoopReroll/basic.ll | 30 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Scalar/LoopRerollPass.cpp b/lib/Transforms/Scalar/LoopRerollPass.cpp index 704299f3041..fdf7e3b1b19 100644 --- a/lib/Transforms/Scalar/LoopRerollPass.cpp +++ b/lib/Transforms/Scalar/LoopRerollPass.cpp @@ -719,14 +719,17 @@ collectPossibleRoots(Instruction *Base, std::map &Roots) { if (Roots.empty()) return false; - - assert(Roots.find(0) == Roots.end() && "Didn't expect a zero index!"); // If we found non-loop-inc, non-root users of Base, assume they are // for the zeroth root index. This is because "add %a, 0" gets optimized // away. - if (BaseUsers.size()) + if (BaseUsers.size()) { + if (Roots.find(0) != Roots.end()) { + DEBUG(dbgs() << "LRR: Multiple roots found for base - aborting!\n"); + return false; + } Roots[0] = Base; + } // Calculate the number of users of the base, or lowest indexed, iteration. unsigned NumBaseUses = BaseUsers.size(); diff --git a/test/Transforms/LoopReroll/basic.ll b/test/Transforms/LoopReroll/basic.ll index f30f417f17a..75334611d5f 100644 --- a/test/Transforms/LoopReroll/basic.ll +++ b/test/Transforms/LoopReroll/basic.ll @@ -545,6 +545,36 @@ for.end: ; preds = %for.body ret void } +%struct.s = type { i32, i32 } + +; Function Attrs: nounwind uwtable +define void @gep1(%struct.s* nocapture %x) #0 { +entry: + %call = tail call i32 @foo(i32 0) #1 + br label %for.body + +for.body: ; preds = %for.body, %entry + %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] + %0 = mul nsw i64 %indvars.iv, 3 + %arrayidx = getelementptr inbounds %struct.s* %x, i64 %0, i32 0 + store i32 %call, i32* %arrayidx, align 4 + %1 = add nsw i64 %0, 1 + %arrayidx4 = getelementptr inbounds %struct.s* %x, i64 %1, i32 0 + store i32 %call, i32* %arrayidx4, align 4 + %2 = add nsw i64 %0, 2 + %arrayidx9 = getelementptr inbounds %struct.s* %x, i64 %2, i32 0 + store i32 %call, i32* %arrayidx9, align 4 + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 + %exitcond = icmp eq i64 %indvars.iv.next, 500 + br i1 %exitcond, label %for.end, label %for.body + +; CHECK-LABEL: @gep1 +; This test is a crash test only. +; CHECK: ret +for.end: ; preds = %for.body + ret void +} + attributes #0 = { nounwind uwtable } attributes #1 = { nounwind } -- 2.34.1