<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>LGTM. Please commit.</div><div><br></div><div>Thanks.<br></div><div><br>On Feb 16, 2014, at 6:42 PM, Gerolf Hoflehner <<a href="mailto:ghoflehner@apple.com">ghoflehner@apple.com</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><div>Hi</div><div><br></div><div>We run into an null VectorizedValue assertion in the SLP Vectorizer (in function vectorizeTree()). The root cause is that we can end up picking wrong PHI nodes because we used </div><div>indices to get their incoming value rather than the blocks.</div><div><br></div><div><br></div><div>-Gerolf</div><div><br></div><div></div></div></blockquote><blockquote type="cite"><div><slp.patch></div></blockquote><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><div></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><div style="margin: 0px; font-family: Menlo;">Index: lib/Transforms/Vectorize/SLPVectorizer.cpp</div><div style="margin: 0px; font-family: Menlo;">===================================================================</div><div style="margin: 0px; font-family: Menlo;">--- lib/Transforms/Vectorize/SLPVectorizer.cpp<span class="Apple-tab-span" style="white-space: pre;"> </span>(revision 201486)</div><div style="margin: 0px; font-family: Menlo;">+++ lib/Transforms/Vectorize/SLPVectorizer.cpp<span class="Apple-tab-span" style="white-space: pre;"> </span>(working copy)</div><div style="margin: 0px; font-family: Menlo;">@@ -779,7 +779,8 @@</div><div style="margin: 0px; font-family: Menlo;"> // Check for terminator values (e.g. invoke).</div><div style="margin: 0px; font-family: Menlo;"> for (unsigned j = 0; j < VL.size(); ++j)</div><div style="margin: 0px; font-family: Menlo;"> for (unsigned i = 0, e = PH->getNumIncomingValues(); i < e; ++i) {</div><div style="margin: 0px; font-family: Menlo;">- TerminatorInst *Term = dyn_cast<TerminatorInst>(cast<PHINode>(VL[j])->getIncomingValue(i));</div><div style="margin: 0px; font-family: Menlo;">+ TerminatorInst *Term = dyn_cast<TerminatorInst>(</div><div style="margin: 0px; font-family: Menlo;">+ cast<PHINode>(VL[j])->getIncomingValueForBlock(PH->getIncomingBlock(i)));</div><div style="margin: 0px; font-family: Menlo;"> if (Term) {</div><div style="margin: 0px; font-family: Menlo;"> DEBUG(dbgs() << "SLP: Need to swizzle PHINodes (TerminatorInst use).\n");</div><div style="margin: 0px; font-family: Menlo;"> newTreeEntry(VL, false);</div><div style="margin: 0px; font-family: Menlo;">@@ -794,7 +795,8 @@</div><div style="margin: 0px; font-family: Menlo;"> ValueList Operands;</div><div style="margin: 0px; font-family: Menlo;"> // Prepare the operand vector.</div><div style="margin: 0px; font-family: Menlo;"> for (unsigned j = 0; j < VL.size(); ++j)</div><div style="margin: 0px; font-family: Menlo;">- Operands.push_back(cast<PHINode>(VL[j])->getIncomingValue(i));</div><div style="margin: 0px; font-family: Menlo;">+ Operands.push_back(cast<PHINode>(VL[j])->getIncomingValueForBlock(</div><div style="margin: 0px; font-family: Menlo;">+ PH->getIncomingBlock(i)));</div><div style="margin: 0px; font-family: Menlo; min-height: 21px;"> <br class="webkit-block-placeholder"></div><div style="margin: 0px; font-family: Menlo;"> buildTree_rec(Operands, Depth + 1);</div><div style="margin: 0px; font-family: Menlo;"> }</div><div style="margin: 0px; font-family: Menlo;">Index: test/Transforms/SLPVectorizer/X86/crash_vectorizeTree.ll</div><div style="margin: 0px; font-family: Menlo;">===================================================================</div><div style="margin: 0px; font-family: Menlo;">--- test/Transforms/SLPVectorizer/X86/crash_vectorizeTree.ll<span class="Apple-tab-span" style="white-space: pre;"> </span>(revision 0)</div><div style="margin: 0px; font-family: Menlo;">+++ test/Transforms/SLPVectorizer/X86/crash_vectorizeTree.ll<span class="Apple-tab-span" style="white-space: pre;"> </span>(working copy)</div><div style="margin: 0px; font-family: Menlo;">@@ -0,0 +1,65 @@</div><div style="margin: 0px; font-family: Menlo;">+; RUN: opt -slp-vectorizer -mtriple=x86_64-apple-macosx10.9.0 -mcpu=corei7-avx -S < %s | FileCheck %s</div><div style="margin: 0px; font-family: Menlo;">+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"</div><div style="margin: 0px; font-family: Menlo;">+target triple = "x86_64-apple-macosx10.9.0"</div><div style="margin: 0px; font-family: Menlo;">+</div><div style="margin: 0px; font-family: Menlo;">+</div><div style="margin: 0px; font-family: Menlo;">+; This test used to crash because we were following phi chains incorrectly.</div><div style="margin: 0px; font-family: Menlo;">+; We used indices to get the incoming value of two phi nodes rather than </div><div style="margin: 0px; font-family: Menlo;">+; incoming block lookup.</div><div style="margin: 0px; font-family: Menlo;">+; This can give wrong results when the ordering of incoming</div><div style="margin: 0px; font-family: Menlo;">+; edges in the two phi nodes don't match.</div><div style="margin: 0px; font-family: Menlo;">+;CHECK-LABEL: bar</div><div style="margin: 0px; font-family: Menlo;">+</div><div style="margin: 0px; font-family: Menlo;">+%0 = type { %1, %2 }</div><div style="margin: 0px; font-family: Menlo;">+%1 = type { double, double }</div><div style="margin: 0px; font-family: Menlo;">+%2 = type { double, double }</div><div style="margin: 0px; font-family: Menlo;">+</div><div style="margin: 0px; font-family: Menlo;">+</div><div style="margin: 0px; font-family: Menlo;">+;define fastcc void @bar() {</div><div style="margin: 0px; font-family: Menlo;">+define void @bar() {</div><div style="margin: 0px; font-family: Menlo;">+ %1 = getelementptr inbounds %0* undef, i64 0, i32 1, i32 0</div><div style="margin: 0px; font-family: Menlo;">+ %2 = getelementptr inbounds %0* undef, i64 0, i32 1, i32 1</div><div style="margin: 0px; font-family: Menlo;">+ %3 = getelementptr inbounds %0* undef, i64 0, i32 1, i32 0</div><div style="margin: 0px; font-family: Menlo;">+ %4 = getelementptr inbounds %0* undef, i64 0, i32 1, i32 1</div><div style="margin: 0px; font-family: Menlo;">+ %5 = getelementptr inbounds %0* undef, i64 0, i32 1, i32 0</div><div style="margin: 0px; font-family: Menlo;">+ %6 = getelementptr inbounds %0* undef, i64 0, i32 1, i32 1</div><div style="margin: 0px; font-family: Menlo;">+ br label %7</div><div style="margin: 0px; font-family: Menlo;">+</div><div style="margin: 0px; font-family: Menlo;">+; <label>:7 ; preds = %18, %17, %17, %0</div><div style="margin: 0px; font-family: Menlo;">+ %8 = phi double [ 2.800000e+01, %0 ], [ %11, %18 ], [ %11, %17 ], [ %11, %17 ]</div><div style="margin: 0px; font-family: Menlo;">+ %9 = phi double [ 1.800000e+01, %0 ], [ %10, %18 ], [ %10, %17 ], [ %10, %17 ]</div><div style="margin: 0px; font-family: Menlo;">+ store double %9, double* %1, align 8</div><div style="margin: 0px; font-family: Menlo;">+ store double %8, double* %2, align 8</div><div style="margin: 0px; font-family: Menlo;">+ %10 = load double* %3, align 8</div><div style="margin: 0px; font-family: Menlo;">+ %11 = load double* %4, align 8</div><div style="margin: 0px; font-family: Menlo;">+ br i1 undef, label %12, label %13</div><div style="margin: 0px; font-family: Menlo;">+</div><div style="margin: 0px; font-family: Menlo;">+; <label>:12 ; preds = %7</div><div style="margin: 0px; font-family: Menlo;">+ ret void</div><div style="margin: 0px; font-family: Menlo;">+</div><div style="margin: 0px; font-family: Menlo;">+; <label>:13 ; preds = %7</div><div style="margin: 0px; font-family: Menlo;">+ store double %10, double* %5, align 8</div><div style="margin: 0px; font-family: Menlo;">+ store double %11, double* %6, align 8</div><div style="margin: 0px; font-family: Menlo;">+ br i1 undef, label %14, label %15</div><div style="margin: 0px; font-family: Menlo;">+</div><div style="margin: 0px; font-family: Menlo;">+; <label>:14 ; preds = %13</div><div style="margin: 0px; font-family: Menlo;">+ br label %15</div><div style="margin: 0px; font-family: Menlo;">+</div><div style="margin: 0px; font-family: Menlo;">+; <label>:15 ; preds = %14, %13</div><div style="margin: 0px; font-family: Menlo;">+ br i1 undef, label %16, label %17</div><div style="margin: 0px; font-family: Menlo;">+</div><div style="margin: 0px; font-family: Menlo;">+; <label>:16 ; preds = %15</div><div style="margin: 0px; font-family: Menlo;">+ unreachable</div><div style="margin: 0px; font-family: Menlo;">+</div><div style="margin: 0px; font-family: Menlo;">+; <label>:17 ; preds = %15</div><div style="margin: 0px; font-family: Menlo;">+ switch i32 undef, label %18 [</div><div style="margin: 0px; font-family: Menlo;">+ i32 32, label %7</div><div style="margin: 0px; font-family: Menlo;">+ i32 103, label %7</div><div style="margin: 0px; font-family: Menlo;">+ ]</div><div style="margin: 0px; font-family: Menlo;">+</div><div style="margin: 0px; font-family: Menlo;">+; <label>:18 ; preds = %17</div><div style="margin: 0px; font-family: Menlo;">+ br i1 undef, label %7, label %19</div><div style="margin: 0px; font-family: Menlo;">+</div><div style="margin: 0px; font-family: Menlo;">+; <label>:19 ; preds = %18</div><div style="margin: 0px; font-family: Menlo;">+ unreachable</div><div style="margin: 0px; font-family: Menlo;">+}</div></div></div></blockquote></body></html>