<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;}
span.gmail-stdout
{mso-style-name:gmail-stdout;}
span.EmailStyle20
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Sorry about that, I’ll take a look!<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>-- Matt<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> Kostya Serebryany [mailto:kcc@google.com] <br><b>Sent:</b> Friday, August 19, 2016 12:43 PM<br><b>To:</b> Matthew Simpson <mssimpso@codeaurora.org><br><b>Cc:</b> LLVM Commits <llvm-commits@lists.llvm.org><br><b>Subject:</b> Re: [llvm] r279125 - [SLP] Initialize VectorizedValue when gathering<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>I think this is causing the ubsan bot failure. please fix: <o:p></o:p></p><div><pre><span class=gmail-stdout><span style='font-size:12.0pt;color:black'>lib/Transforms/Vectorize/SLPVectorizer.cpp:4177:34: runtime error: signed integer overflow: 2147483647 + 11 cannot be represented in type 'int'</span></span><span class=gmail-stdout><span style='font-family:"Arial",sans-serif'> </span></span><o:p></o:p></pre></div><div><p class=MsoNormal><span class=gmail-stdout><a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/15655/steps/check-llvm%20ubsan/logs/stdio">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/15655/steps/check-llvm%20ubsan/logs/stdio</a></span><o:p></o:p></p></div></div><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>On Thu, Aug 18, 2016 at 12:50 PM, Matthew Simpson via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<o:p></o:p></p><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><p class=MsoNormal>Author: mssimpso<br>Date: Thu Aug 18 14:50:32 2016<br>New Revision: 279125<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=279125&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=279125&view=rev</a><br>Log:<br>[SLP] Initialize VectorizedValue when gathering<br><br>We abort building vectorizable trees in some cases (e.g., if the maximum<br>recursion depth is reached, if the region size is too large, etc.). If this<br>happens for a reduction, we can be left with a root entry that needs to be<br>gathered. For these cases, we need make sure we actually set VectorizedValue to<br>the resulting vector.<br><br>This patch ensures we properly set VectorizedValue, and it also ensures the<br>insertelement sequence generated for the gathers is inserted at the correct<br>location.<br><br>Reference: <a href="https://llvm.org/bugs/show_bug.cgi?id=28330" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=28330</a><br>Differential Revison: <a href="https://reviews.llvm.org/D23410" target="_blank">https://reviews.llvm.org/D23410</a><br><br>Added:<br> llvm/trunk/test/Transforms/SLPVectorizer/AArch64/gather-root.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=279125&r1=279124&r2=279125&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp?rev=279125&r1=279124&r2=279125&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp (original)<br>+++ llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp Thu Aug 18 14:50:32 2016<br>@@ -2153,11 +2153,61 @@ void BoUpSLP::reorderInputsAccordingToOp<br> }<br><br> void BoUpSLP::setInsertPointAfterBundle(ArrayRef<Value *> VL) {<br>- Instruction *VL0 = cast<Instruction>(VL[0]);<br>- BasicBlock::iterator NextInst(VL0);<br>- ++NextInst;<br>- Builder.SetInsertPoint(VL0->getParent(), NextInst);<br>- Builder.SetCurrentDebugLocation(VL0->getDebugLoc());<br>+<br>+ // Get the basic block this bundle is in. All instructions in the bundle<br>+ // should be in this block.<br>+ auto *Front = cast<Instruction>(VL.front());<br>+ auto *BB = Front->getParent();<br>+ assert(all_of(make_range(VL.begin(), VL.end()), [&](Value *V) -> bool {<br>+ return cast<Instruction>(V)->getParent() == BB;<br>+ }));<br>+<br>+ // The last instruction in the bundle in program order.<br>+ Instruction *LastInst = nullptr;<br>+<br>+ // Find the last instruction. The common case should be that BB has been<br>+ // scheduled, and the last instruction is VL.back(). So we start with<br>+ // VL.back() and iterate over schedule data until we reach the end of the<br>+ // bundle. The end of the bundle is marked by null ScheduleData.<br>+ if (BlocksSchedules.count(BB)) {<br>+ auto *Bundle = BlocksSchedules[BB]->getScheduleData(VL.back());<br>+ if (Bundle && Bundle->isPartOfBundle())<br>+ for (; Bundle; Bundle = Bundle->NextInBundle)<br>+ LastInst = Bundle->Inst;<br>+ }<br>+<br>+ // LastInst can still be null at this point if there's either not an entry<br>+ // for BB in BlocksSchedules or there's no ScheduleData available for<br>+ // VL.back(). This can be the case if buildTree_rec aborts for various<br>+ // reasons (e.g., the maximum recursion depth is reached, the maximum region<br>+ // size is reached, etc.). ScheduleData is initialized in the scheduling<br>+ // "dry-run".<br>+ //<br>+ // If this happens, we can still find the last instruction by brute force. We<br>+ // iterate forwards from Front (inclusive) until we either see all<br>+ // instructions in the bundle or reach the end of the block. If Front is the<br>+ // last instruction in program order, LastInst will be set to Front, and we<br>+ // will visit all the remaining instructions in the block.<br>+ //<br>+ // One of the reasons we exit early from buildTree_rec is to place an upper<br>+ // bound on compile-time. Thus, taking an additional compile-time hit here is<br>+ // not ideal. However, this should be exceedingly rare since it requires that<br>+ // we both exit early from buildTree_rec and that the bundle be out-of-order<br>+ // (causing us to iterate all the way to the end of the block).<br>+ if (!LastInst) {<br>+ SmallPtrSet<Value *, 16> Bundle(VL.begin(), VL.end());<br>+ for (auto &I : make_range(BasicBlock::iterator(Front), BB->end())) {<br>+ if (Bundle.erase(&I))<br>+ LastInst = &I;<br>+ if (Bundle.empty())<br>+ break;<br>+ }<br>+ }<br>+<br>+ // Set the insertion point after the last instruction in the bundle. Set the<br>+ // debug location to Front.<br>+ Builder.SetInsertPoint(BB, next(BasicBlock::iterator(LastInst)));<br>+ Builder.SetCurrentDebugLocation(Front->getDebugLoc());<br> }<br><br> Value *BoUpSLP::Gather(ArrayRef<Value *> VL, VectorType *Ty) {<br>@@ -2235,7 +2285,9 @@ Value *BoUpSLP::vectorizeTree(TreeEntry<br><br> if (E->NeedToGather) {<br> setInsertPointAfterBundle(E->Scalars);<br>- return Gather(E->Scalars, VecTy);<br>+ auto *V = Gather(E->Scalars, VecTy);<br>+ E->VectorizedValue = V;<br>+ return V;<br> }<br><br> unsigned Opcode = getSameOpcode(E->Scalars);<br>@@ -2282,7 +2334,10 @@ Value *BoUpSLP::vectorizeTree(TreeEntry<br> E->VectorizedValue = V;<br> return V;<br> }<br>- return Gather(E->Scalars, VecTy);<br>+ setInsertPointAfterBundle(E->Scalars);<br>+ auto *V = Gather(E->Scalars, VecTy);<br>+ E->VectorizedValue = V;<br>+ return V;<br> }<br> case Instruction::ExtractValue: {<br> if (canReuseExtract(E->Scalars, Instruction::ExtractValue)) {<br>@@ -2294,7 +2349,10 @@ Value *BoUpSLP::vectorizeTree(TreeEntry<br> E->VectorizedValue = V;<br> return propagateMetadata(V, E->Scalars);<br> }<br>- return Gather(E->Scalars, VecTy);<br>+ setInsertPointAfterBundle(E->Scalars);<br>+ auto *V = Gather(E->Scalars, VecTy);<br>+ E->VectorizedValue = V;<br>+ return V;<br> }<br> case Instruction::ZExt:<br> case Instruction::SExt:<br><br>Added: llvm/trunk/test/Transforms/SLPVectorizer/AArch64/gather-root.ll<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SLPVectorizer/AArch64/gather-root.ll?rev=279125&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SLPVectorizer/AArch64/gather-root.ll?rev=279125&view=auto</a><br>==============================================================================<br>--- llvm/trunk/test/Transforms/SLPVectorizer/AArch64/gather-root.ll (added)<br>+++ llvm/trunk/test/Transforms/SLPVectorizer/AArch64/gather-root.ll Thu Aug 18 14:50:32 2016<br>@@ -0,0 +1,95 @@<br>+; RUN: opt < %s -slp-vectorizer -S | FileCheck %s --check-prefix=DEFAULT<br>+; RUN: opt < %s -slp-recursion-max-depth=0 -slp-vectorizer -S | FileCheck %s --check-prefix=GATHER<br>+<br>+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"<br>+target triple = "aarch64--linux-gnu"<br>+<br>+@a = common global [80 x i8] zeroinitializer, align 16<br>+<br>+; DEFAULT-LABEL: @PR28330(<br>+; DEFAULT: %tmp17 = phi i32 [ %tmp34, %for.body ], [ 0, %entry ]<br>+; DEFAULT: %tmp18 = phi i32 [ %tmp35, %for.body ], [ %n, %entry ]<br>+; DEFAULT: %[[S0:.+]] = select <8 x i1> %1, <8 x i32> <i32 -720, i32 -720, i32 -720, i32 -720, i32 -720, i32 -720, i32 -720, i32 -720>, <8 x i32> <i32 -80, i32 -80, i32 -80, i32 -80, i32 -80, i32 -80, i32 -80, i32 -80><br>+; DEFAULT: %[[R0:.+]] = shufflevector <8 x i32> %[[S0]], <8 x i32> undef, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 undef, i32 undef, i32 undef, i32 undef><br>+; DEFAULT: %[[R1:.+]] = add <8 x i32> %[[S0]], %[[R0]]<br>+; DEFAULT: %[[R2:.+]] = shufflevector <8 x i32> %[[R1]], <8 x i32> undef, <8 x i32> <i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef><br>+; DEFAULT: %[[R3:.+]] = add <8 x i32> %[[R1]], %[[R2]]<br>+; DEFAULT: %[[R4:.+]] = shufflevector <8 x i32> %[[R3]], <8 x i32> undef, <8 x i32> <i32 1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef><br>+; DEFAULT: %[[R5:.+]] = add <8 x i32> %[[R3]], %[[R4]]<br>+; DEFAULT: %[[R6:.+]] = extractelement <8 x i32> %[[R5]], i32 0<br>+; DEFAULT: %tmp34 = add i32 %[[R6]], %tmp17<br>+;<br>+; GATHER-LABEL: @PR28330(<br>+; GATHER: %tmp17 = phi i32 [ %tmp34, %for.body ], [ 0, %entry ]<br>+; GATHER: %tmp18 = phi i32 [ %tmp35, %for.body ], [ %n, %entry ]<br>+; GATHER: %tmp19 = select i1 %tmp1, i32 -720, i32 -80<br>+; GATHER: %tmp21 = select i1 %tmp3, i32 -720, i32 -80<br>+; GATHER: %tmp23 = select i1 %tmp5, i32 -720, i32 -80<br>+; GATHER: %tmp25 = select i1 %tmp7, i32 -720, i32 -80<br>+; GATHER: %tmp27 = select i1 %tmp9, i32 -720, i32 -80<br>+; GATHER: %tmp29 = select i1 %tmp11, i32 -720, i32 -80<br>+; GATHER: %tmp31 = select i1 %tmp13, i32 -720, i32 -80<br>+; GATHER: %tmp33 = select i1 %tmp15, i32 -720, i32 -80<br>+; GATHER: %[[I0:.+]] = insertelement <8 x i32> undef, i32 %tmp19, i32 0<br>+; GATHER: %[[I1:.+]] = insertelement <8 x i32> %[[I0]], i32 %tmp21, i32 1<br>+; GATHER: %[[I2:.+]] = insertelement <8 x i32> %[[I1]], i32 %tmp23, i32 2<br>+; GATHER: %[[I3:.+]] = insertelement <8 x i32> %[[I2]], i32 %tmp25, i32 3<br>+; GATHER: %[[I4:.+]] = insertelement <8 x i32> %[[I3]], i32 %tmp27, i32 4<br>+; GATHER: %[[I5:.+]] = insertelement <8 x i32> %[[I4]], i32 %tmp29, i32 5<br>+; GATHER: %[[I6:.+]] = insertelement <8 x i32> %[[I5]], i32 %tmp31, i32 6<br>+; GATHER: %[[I7:.+]] = insertelement <8 x i32> %[[I6]], i32 %tmp33, i32 7<br>+; GATHER: %[[R0:.+]] = shufflevector <8 x i32> %[[I7]], <8 x i32> undef, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 undef, i32 undef, i32 undef, i32 undef><br>+; GATHER: %[[R1:.+]] = add <8 x i32> %[[I7]], %[[R0]]<br>+; GATHER: %[[R2:.+]] = shufflevector <8 x i32> %[[R1]], <8 x i32> undef, <8 x i32> <i32 2, i32 3, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef><br>+; GATHER: %[[R3:.+]] = add <8 x i32> %[[R1]], %[[R2]]<br>+; GATHER: %[[R4:.+]] = shufflevector <8 x i32> %[[R3]], <8 x i32> undef, <8 x i32> <i32 1, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef><br>+; GATHER: %[[R5:.+]] = add <8 x i32> %[[R3]], %[[R4]]<br>+; GATHER: %[[R6:.+]] = extractelement <8 x i32> %[[R5]], i32 0<br>+; GATHER: %tmp34 = add i32 %[[R6]], %tmp17<br>+<br>+define void @PR28330(i32 %n) {<br>+entry:<br>+ %tmp0 = load i8, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @a, i64 0, i64 1), align 1<br>+ %tmp1 = icmp eq i8 %tmp0, 0<br>+ %tmp2 = load i8, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @a, i64 0, i64 2), align 2<br>+ %tmp3 = icmp eq i8 %tmp2, 0<br>+ %tmp4 = load i8, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @a, i64 0, i64 3), align 1<br>+ %tmp5 = icmp eq i8 %tmp4, 0<br>+ %tmp6 = load i8, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @a, i64 0, i64 4), align 4<br>+ %tmp7 = icmp eq i8 %tmp6, 0<br>+ %tmp8 = load i8, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @a, i64 0, i64 5), align 1<br>+ %tmp9 = icmp eq i8 %tmp8, 0<br>+ %tmp10 = load i8, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @a, i64 0, i64 6), align 2<br>+ %tmp11 = icmp eq i8 %tmp10, 0<br>+ %tmp12 = load i8, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @a, i64 0, i64 7), align 1<br>+ %tmp13 = icmp eq i8 %tmp12, 0<br>+ %tmp14 = load i8, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @a, i64 0, i64 8), align 8<br>+ %tmp15 = icmp eq i8 %tmp14, 0<br>+ br label %for.body<br>+<br>+for.body:<br>+ %tmp17 = phi i32 [ %tmp34, %for.body ], [ 0, %entry ]<br>+ %tmp18 = phi i32 [ %tmp35, %for.body ], [ %n, %entry ]<br>+ %tmp19 = select i1 %tmp1, i32 -720, i32 -80<br>+ %tmp20 = add i32 %tmp17, %tmp19<br>+ %tmp21 = select i1 %tmp3, i32 -720, i32 -80<br>+ %tmp22 = add i32 %tmp20, %tmp21<br>+ %tmp23 = select i1 %tmp5, i32 -720, i32 -80<br>+ %tmp24 = add i32 %tmp22, %tmp23<br>+ %tmp25 = select i1 %tmp7, i32 -720, i32 -80<br>+ %tmp26 = add i32 %tmp24, %tmp25<br>+ %tmp27 = select i1 %tmp9, i32 -720, i32 -80<br>+ %tmp28 = add i32 %tmp26, %tmp27<br>+ %tmp29 = select i1 %tmp11, i32 -720, i32 -80<br>+ %tmp30 = add i32 %tmp28, %tmp29<br>+ %tmp31 = select i1 %tmp13, i32 -720, i32 -80<br>+ %tmp32 = add i32 %tmp30, %tmp31<br>+ %tmp33 = select i1 %tmp15, i32 -720, i32 -80<br>+ %tmp34 = add i32 %tmp32, %tmp33<br>+ %tmp35 = add nsw i32 %tmp18, -1<br>+ %tmp36 = icmp eq i32 %tmp35, 0<br>+ br i1 %tmp36, label %for.end, label %for.body<br>+<br>+for.end:<br>+ ret void<br>+}<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><o:p></o:p></p></blockquote></div><p class=MsoNormal><o:p> </o:p></p></div></div></body></html>