<p dir="ltr">Can you elaborate in your commit message? What was the problem? How does this fix it?</p>
<div class="gmail_quote">On Aug 2, 2014 12:51 PM, "Erik Eckstein" <<a href="mailto:eeckstein@apple.com">eeckstein@apple.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: eeckstein<br>
Date: Sat Aug 2 14:39:42 2014<br>
New Revision: 214638<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=214638&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=214638&view=rev</a><br>
Log:<br>
fix bug 20513 - Crash in SLP Vectorizer<br>
<br>
<br>
Added:<br>
llvm/trunk/test/Transforms/SLPVectorizer/X86/crash_scheduling.ll<br>
Modified:<br>
llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp?rev=214638&r1=214637&r2=214638&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp?rev=214638&r1=214637&r2=214638&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp Sat Aug 2 14:39:42 2014<br>
@@ -806,7 +806,7 @@ private:<br>
<br>
/// Performs the "real" scheduling. Done before vectorization is actually<br>
/// performed in a basic block.<br>
- void scheduleBlock(BasicBlock *BB);<br>
+ void scheduleBlock(BlockScheduling *BS);<br>
<br>
/// List of users to ignore during scheduling and that don't need extracting.<br>
ArrayRef<Value *> UserIgnoreList;<br>
@@ -1741,8 +1741,6 @@ Value *BoUpSLP::vectorizeTree(TreeEntry<br>
setInsertPointAfterBundle(E->Scalars);<br>
return Gather(E->Scalars, VecTy);<br>
}<br>
- BasicBlock *BB = VL0->getParent();<br>
- scheduleBlock(BB);<br>
<br>
unsigned Opcode = getSameOpcode(E->Scalars);<br>
<br>
@@ -2076,6 +2074,12 @@ Value *BoUpSLP::vectorizeTree(TreeEntry<br>
}<br>
<br>
Value *BoUpSLP::vectorizeTree() {<br>
+<br>
+ // All blocks must be scheduled before any instructions are inserted.<br>
+ for (auto &BSIter : BlocksSchedules) {<br>
+ scheduleBlock(BSIter.second.get());<br>
+ }<br>
+<br>
Builder.SetInsertPoint(F->getEntryBlock().begin());<br>
vectorizeTree(&VectorizableTree[0]);<br>
<br>
@@ -2548,12 +2552,12 @@ void BoUpSLP::BlockScheduling::resetSche<br>
ReadyInsts.clear();<br>
}<br>
<br>
-void BoUpSLP::scheduleBlock(BasicBlock *BB) {<br>
- DEBUG(dbgs() << "SLP: schedule block " << BB->getName() << "\n");<br>
-<br>
- BlockScheduling *BS = BlocksSchedules[BB].get();<br>
- if (!BS || !BS->ScheduleStart)<br>
+void BoUpSLP::scheduleBlock(BlockScheduling *BS) {<br>
+<br>
+ if (!BS->ScheduleStart)<br>
return;<br>
+<br>
+ DEBUG(dbgs() << "SLP: schedule block " << BS->BB->getName() << "\n");<br>
<br>
BS->resetSchedule();<br>
<br>
@@ -2598,8 +2602,8 @@ void BoUpSLP::scheduleBlock(BasicBlock *<br>
while (BundleMember) {<br>
Instruction *pickedInst = BundleMember->Inst;<br>
if (LastScheduledInst->getNextNode() != pickedInst) {<br>
- BB->getInstList().remove(pickedInst);<br>
- BB->getInstList().insert(LastScheduledInst, pickedInst);<br>
+ BS->BB->getInstList().remove(pickedInst);<br>
+ BS->BB->getInstList().insert(LastScheduledInst, pickedInst);<br>
}<br>
LastScheduledInst = pickedInst;<br>
BundleMember = BundleMember->NextInBundle;<br>
<br>
Added: llvm/trunk/test/Transforms/SLPVectorizer/X86/crash_scheduling.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SLPVectorizer/X86/crash_scheduling.ll?rev=214638&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SLPVectorizer/X86/crash_scheduling.ll?rev=214638&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/SLPVectorizer/X86/crash_scheduling.ll (added)<br>
+++ llvm/trunk/test/Transforms/SLPVectorizer/X86/crash_scheduling.ll Sat Aug 2 14:39:42 2014<br>
@@ -0,0 +1,47 @@<br>
+; RUN: opt < %s -basicaa -slp-vectorizer -S -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7<br>
+<br>
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64-apple-darwin13.3.0"<br>
+<br>
+define void @_foo(double %p1, double %p2, double %p3) #0 {<br>
+entry:<br>
+ %tab1 = alloca [256 x i32], align 16<br>
+ %tab2 = alloca [256 x i32], align 16<br>
+ br label %bb1<br>
+<br>
+<br>
+bb1:<br>
+ %mul19 = fmul double %p1, 1.638400e+04<br>
+ %mul20 = fmul double %p3, 1.638400e+04<br>
+ %add = fadd double %mul20, 8.192000e+03<br>
+ %mul21 = fmul double %p2, 1.638400e+04<br>
+ ; The SLPVectorizer crashed when scheduling this block after it inserted an<br>
+ ; insertelement instruction (during vectorizing the for.body block) at this position.<br>
+ br label %for.body<br>
+<br>
+for.body:<br>
+ %indvars.iv266 = phi i64 [ 0, %bb1 ], [ %indvars.iv.next267, %for.body ]<br>
+ %t.0259 = phi double [ 0.000000e+00, %bb1 ], [ %add27, %for.body ]<br>
+ %p3.addr.0258 = phi double [ %add, %bb1 ], [ %add28, %for.body ]<br>
+ %vecinit.i.i237 = insertelement <2 x double> undef, double %t.0259, i32 0<br>
+ %x13 = tail call i32 @_xfn(<2 x double> %vecinit.i.i237) #2<br>
+ %arrayidx = getelementptr inbounds [256 x i32]* %tab1, i64 0, i64 %indvars.iv266<br>
+ store i32 %x13, i32* %arrayidx, align 4, !tbaa !4<br>
+ %vecinit.i.i = insertelement <2 x double> undef, double %p3.addr.0258, i32 0<br>
+ %x14 = tail call i32 @_xfn(<2 x double> %vecinit.i.i) #2<br>
+ %arrayidx26 = getelementptr inbounds [256 x i32]* %tab2, i64 0, i64 %indvars.iv266<br>
+ store i32 %x14, i32* %arrayidx26, align 4, !tbaa !4<br>
+ %add27 = fadd double %mul19, %t.0259<br>
+ %add28 = fadd double %mul21, %p3.addr.0258<br>
+ %indvars.iv.next267 = add nuw nsw i64 %indvars.iv266, 1<br>
+ %exitcond = icmp eq i64 %indvars.iv.next267, 256<br>
+ br i1 %exitcond, label %return, label %for.body<br>
+<br>
+return:<br>
+ ret void<br>
+}<br>
+<br>
+declare i32 @_xfn(<2 x double>) #4<br>
+<br>
+!3 = metadata !{metadata !"int", metadata !4, i64 0}<br>
+!4 = metadata !{metadata !3, metadata !3, i64 0}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>