<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:Helvetica;
panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
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;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.apple-converted-space
{mso-style-name:apple-converted-space;}
span.EmailStyle18
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:#1F497D;}
span.EmailStyle19
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:799957587;
mso-list-type:hybrid;
mso-list-template-ids:-1214880770 44585902 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
{mso-level-start-at:0;
mso-level-number-format:bullet;
mso-level-text:-;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-font-family:"Times New Roman";}
@list l0:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level3
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level4
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level6
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
@list l0:level7
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Symbol;}
@list l0:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:"Courier New";}
@list l0:level9
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;
font-family:Wingdings;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></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"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">This is the change between two commits:<o:p></o:p></span></a></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">(1)<o:p></o:p></span></p>
<p class="MsoNormal">@@ -2658,7 +2584,9 @@ void InnerLoopVectorizer::vectorizeMemor<br>
// Handle consecutive loads/stores.<br>
GetElementPtrInst *Gep = getGEPInstruction(Ptr);<br>
if (ConsecutiveStride) {<br>
- if (Gep && Legal->isInductionVariable(Gep->getPointerOperand())) {<br>
+ if (Gep &&<br>
+ !PSE.getSE()->isLoopInvariant(PSE.getSCEV(Gep->getPointerOperand()),<br>
+ OrigLoop)) {<br>
setDebugLocFromInst(Builder, Gep);<br>
Value *PtrOperand = Gep->getPointerOperand();<br>
Value *FirstBasePtr = getVectorValue(PtrOperand)[0];<br>
<br>
<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">And (2)<o:p></o:p></span></p>
<p class="MsoNormal"> } else { // No GEP<br>
- // Use the induction element ptr.<br>
- assert(isa<SCEVAddRecExpr>(PSE.getSE()->getSCEV(Ptr)) &&<o:p></o:p></p>
<p class="MsoNormal">- "Invalid induction ptr");<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"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">(2) Is easy to explain –
</span>SCEVAddRecExpr<span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> is calculated in getPtrStride() and is not saved inside SE. I succeeded to reproduce it. (LNT build)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">(1) Failed on a self-build (clang builds clang with sanitizer). I was unable to reproduce the failure on my system.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Do you think that
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span> if (Gep && Legal->isInductionVariable(Gep->getPointerOperand()))<o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%">and</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">
</span>if (Gep && !PSE.getSE()->isLoopInvariant(PSE.getSCEV(Gep->getPointerOperand()),<br>
OrigLoop)<o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%">should be handled differently ?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%">If Eric will send me the test case, I will find the problem.</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F4E79;mso-style-textfill-fill-color:#1F4E79;mso-style-textfill-fill-alpha:100.0%"><o:p></o:p></span></p>
<div>
<p class="MsoListParagraph"><b><i><span style="color:#2F5496"><o:p> </o:p></span></i></b></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo2"><![if !supportLists]><span style="font-family:"Calibri",sans-serif;color:#2F5496"><span style="mso-list:Ignore">-<span style="font:7.0pt "Times New Roman"">
</span></span></span><![endif]><span dir="LTR"></span><b><i><span style="color:#2F5496"><o:p> </o:p></span></i></b></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo2"><![if !supportLists]><span style="font-family:"Calibri",sans-serif;color:#2F5496"><span style="mso-list:Ignore">-<span style="font:7.0pt "Times New Roman"">
</span></span></span><![endif]><span dir="LTR"></span><b><i><span style="color:#2F5496"> Elena<o:p></o:p></span></i></b></p>
</div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><a name="_____replyseparator"></a><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"> anemet@apple.com [mailto:anemet@apple.com]
<br>
<b>Sent:</b> Tuesday, June 28, 2016 20:46<br>
<b>To:</b> Demikhovsky, Elena <elena.demikhovsky@intel.com><br>
<b>Cc:</b> Eric Liu <ioeric@google.com>; llvm-commits@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm] r273864 - Fixed consecutive memory access detection in Loop Vectorizer.<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Jun 28, 2016, at 10:35 AM, Demikhovsky, Elena via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">It would be great if you can provide a test, even big.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">If I’ll not find a solution in 2-3 days, I’ll revert the patch.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">The problem is not in the small diff between two commits, it is, probably, in usage of getPtrStride() that allows to vectorize more loops.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thank you.</span><o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">It is still a good idea to explain what has changed for the recommit in the commit log .<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Adam<o:p></o:p></p>
</div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
</div>
<div style="margin-left:36.0pt">
<p class="MsoNormal" style="text-indent:-18.0pt"><span style="font-family:"Calibri",sans-serif;color:#2F5496">-</span><span style="font-size:7.0pt;color:#2F5496"> <span class="apple-converted-space"> </span></span><b><i><span style="color:#2F5496"> Elena</span></i></b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
</div>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<div>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span class="apple-converted-space"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span></span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Eric
Liu [</span><a href="mailto:ioeric@google.com"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:purple">mailto:ioeric@google.com</span></a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">]<span class="apple-converted-space"> </span><br>
<b>Sent:</b><span class="apple-converted-space"> </span>Tuesday, June 28, 2016 17:36<br>
<b>To:</b><span class="apple-converted-space"> </span>Demikhovsky, Elena <</span><a href="mailto:elena.demikhovsky@intel.com"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:purple">elena.demikhovsky@intel.com</span></a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">>;<span class="apple-converted-space"> </span></span><a href="mailto:llvm-commits@lists.llvm.org"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:purple">llvm-commits@lists.llvm.org</span></a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><br>
<b>Cc:</b><span class="apple-converted-space"> </span>Nirav Davé <</span><a href="mailto:niravd@google.com"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:purple">niravd@google.com</span></a><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">><br>
<b>Subject:</b><span class="apple-converted-space"> </span>Re: [llvm] r273864 - Fixed consecutive memory access detection in Loop Vectorizer.</span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">Hi Elena,<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">I see this is a re-commit of a previous patch but wondering if new changes you introduced in this re-commit have been reviewed or not? <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">One of our internal test cases fails when built with llvm that is sync to this revision (the test passes with both r273863 llvm and gcc). I am trying to find a minimal test case that can reproduce the bug, but please could you take a second
look at the changes? Thanks a lot!<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Cheers,<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Eric<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal">On Mon, Jun 27, 2016 at 1:26 PM Elena Demikhovsky via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org"><span style="color:purple">llvm-commits@lists.llvm.org</span></a>> wrote:<o:p></o:p></p>
</div>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">Author: delena<br>
Date: Mon Jun 27 06:19:23 2016<br>
New Revision: 273864<br>
<br>
URL:<span class="apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=273864&view=rev" target="_blank"><span style="color:purple">http://llvm.org/viewvc/llvm-project?rev=273864&view=rev</span></a><br>
Log:<br>
Fixed consecutive memory access detection in Loop Vectorizer.<br>
It did not handle correctly cases without GEP.<br>
<br>
The following loop wasn't vectorized:<br>
<br>
for (int i=0; i<len; i++)<br>
<br>
*to++ = *from++;<br>
<br>
I use getPtrStride() to find Stride for memory access and return 0 is the Stride is not 1 or -1.<br>
<br>
Re-commit rL273257 - revision:<span class="apple-converted-space"> </span><a href="http://reviews.llvm.org/D20789" target="_blank"><span style="color:purple">http://reviews.llvm.org/D20789</span></a><br>
<br>
<br>
Added:<br>
llvm/trunk/test/Transforms/LoopVectorize/consec_no_gep.ll<br>
- copied unchanged from r273257, llvm/trunk/test/Transforms/LoopVectorize/consec_no_gep.ll<br>
llvm/trunk/test/Transforms/LoopVectorize/consec_no_gep2.ll<br>
Modified:<br>
llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h<br>
llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp<br>
llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp<br>
llvm/trunk/test/Transforms/LoopVectorize/ptr-induction.ll<br>
<br>
Modified: llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h<br>
URL:<span class="apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h?rev=273864&r1=273863&r2=273864&view=diff" target="_blank"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h?rev=273864&r1=273863&r2=273864&view=diff</span></a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h (original)<br>
+++ llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h Mon Jun 27 06:19:23 2016<br>
@@ -679,9 +679,11 @@ const SCEV *replaceSymbolicStrideSCEV(Pr<br>
/// to \p PtrToStride and therefore add further predicates to \p PSE.<br>
/// The \p Assume parameter indicates if we are allowed to make additional<br>
/// run-time assumptions.<br>
+/// The \p ShouldCheckWrap indicates that we should ensure that address<br>
+/// calculation does not wrap.<br>
int getPtrStride(PredicatedScalarEvolution &PSE, Value *Ptr, const Loop *Lp,<br>
const ValueToValueMap &StridesMap = ValueToValueMap(),<br>
- bool Assume = false);<br>
+ bool Assume = false, bool ShouldCheckWrap = true);<br>
<br>
/// \brief Returns true if the memory operations \p A and \p B are consecutive.<br>
/// This is a simple API that does not depend on the analysis pass.<br>
<br>
Modified: llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp<br>
URL:<span class="apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp?rev=273864&r1=273863&r2=273864&view=diff" target="_blank"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp?rev=273864&r1=273863&r2=273864&view=diff</span></a><br>
==============================================================================<br>
--- llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp (original)<br>
+++ llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp Mon Jun 27 06:19:23 2016<br>
@@ -866,7 +866,7 @@ static bool isNoWrapAddRec(Value *Ptr, c<br>
/// \brief Check whether the access through \p Ptr has a constant stride.<br>
int llvm::getPtrStride(PredicatedScalarEvolution &PSE, Value *Ptr,<br>
const Loop *Lp, const ValueToValueMap &StridesMap,<br>
- bool Assume) {<br>
+ bool Assume, bool ShouldCheckWrap) {<br>
Type *Ty = Ptr->getType();<br>
assert(Ty->isPointerTy() && "Unexpected non-ptr");<br>
<br>
@@ -905,9 +905,9 @@ int llvm::getPtrStride(PredicatedScalarE<br>
// to access the pointer value "0" which is undefined behavior in address<br>
// space 0, therefore we can also vectorize this case.<br>
bool IsInBoundsGEP = isInBoundsGep(Ptr);<br>
- bool IsNoWrapAddRec =<br>
- PSE.hasNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW) ||<br>
- isNoWrapAddRec(Ptr, AR, PSE, Lp);<br>
+ bool IsNoWrapAddRec = !ShouldCheckWrap ||<br>
+ PSE.hasNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW) ||<br>
+ isNoWrapAddRec(Ptr, AR, PSE, Lp);<br>
bool IsInAddressSpaceZero = PtrTy->getAddressSpace() == 0;<br>
if (!IsNoWrapAddRec && !IsInBoundsGEP && !IsInAddressSpaceZero) {<br>
if (Assume) {<br>
<br>
Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp<br>
URL:<span class="apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=273864&r1=273863&r2=273864&view=diff" target="_blank"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=273864&r1=273863&r2=273864&view=diff</span></a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Mon Jun 27 06:19:23 2016<br>
@@ -2242,87 +2242,13 @@ Value *InnerLoopVectorizer::getStepVecto<br>
}<br>
<br>
int LoopVectorizationLegality::isConsecutivePtr(Value *Ptr) {<br>
- assert(Ptr->getType()->isPointerTy() && "Unexpected non-ptr");<br>
- auto *SE = PSE.getSE();<br>
- // Make sure that the pointer does not point to structs.<br>
- if (Ptr->getType()->getPointerElementType()->isAggregateType())<br>
- return 0;<br>
-<br>
- // If this value is a pointer induction variable, we know it is consecutive.<br>
- PHINode *Phi = dyn_cast_or_null<PHINode>(Ptr);<br>
- if (Phi && Inductions.count(Phi)) {<br>
- InductionDescriptor II = Inductions[Phi];<br>
- return II.getConsecutiveDirection();<br>
- }<br>
-<br>
- GetElementPtrInst *Gep = getGEPInstruction(Ptr);<br>
- if (!Gep)<br>
- return 0;<br>
-<br>
- unsigned NumOperands = Gep->getNumOperands();<br>
- Value *GpPtr = Gep->getPointerOperand();<br>
- // If this GEP value is a consecutive pointer induction variable and all of<br>
- // the indices are constant, then we know it is consecutive.<br>
- Phi = dyn_cast<PHINode>(GpPtr);<br>
- if (Phi && Inductions.count(Phi)) {<br>
-<br>
- // Make sure that the pointer does not point to structs.<br>
- PointerType *GepPtrType = cast<PointerType>(GpPtr->getType());<br>
- if (GepPtrType->getElementType()->isAggregateType())<br>
- return 0;<br>
-<br>
- // Make sure that all of the index operands are loop invariant.<br>
- for (unsigned i = 1; i < NumOperands; ++i)<br>
- if (!SE->isLoopInvariant(PSE.getSCEV(Gep->getOperand(i)), TheLoop))<br>
- return 0;<br>
-<br>
- InductionDescriptor II = Inductions[Phi];<br>
- return II.getConsecutiveDirection();<br>
- }<br>
<br>
- unsigned InductionOperand = getGEPInductionOperand(Gep);<br>
-<br>
- // Check that all of the gep indices are uniform except for our induction<br>
- // operand.<br>
- for (unsigned i = 0; i != NumOperands; ++i)<br>
- if (i != InductionOperand &&<br>
- !SE->isLoopInvariant(PSE.getSCEV(Gep->getOperand(i)), TheLoop))<br>
- return 0;<br>
-<br>
- // We can emit wide load/stores only if the last non-zero index is the<br>
- // induction variable.<br>
- const SCEV *Last = nullptr;<br>
- if (!getSymbolicStrides() || !getSymbolicStrides()->count(Gep))<br>
- Last = PSE.getSCEV(Gep->getOperand(InductionOperand));<br>
- else {<br>
- // Because of the multiplication by a stride we can have a s/zext cast.<br>
- // We are going to replace this stride by 1 so the cast is safe to ignore.<br>
- //<br>
- // %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]<br>
- // %0 = trunc i64 %indvars.iv to i32<br>
- // %mul = mul i32 %0, %Stride1<br>
- // %idxprom = zext i32 %mul to i64 << Safe cast.<br>
- // %arrayidx = getelementptr inbounds i32* %B, i64 %idxprom<br>
- //<br>
- Last = replaceSymbolicStrideSCEV(PSE, *getSymbolicStrides(),<br>
- Gep->getOperand(InductionOperand), Gep);<br>
- if (const SCEVCastExpr *C = dyn_cast<SCEVCastExpr>(Last))<br>
- Last =<br>
- (C->getSCEVType() == scSignExtend || C->getSCEVType() == scZeroExtend)<br>
- ? C->getOperand()<br>
- : Last;<br>
- }<br>
- if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(Last)) {<br>
- const SCEV *Step = AR->getStepRecurrence(*SE);<br>
-<br>
- // The memory is consecutive because the last index is consecutive<br>
- // and all other indices are loop invariant.<br>
- if (Step->isOne())<br>
- return 1;<br>
- if (Step->isAllOnesValue())<br>
- return -1;<br>
- }<br>
+ const ValueToValueMap &Strides = getSymbolicStrides() ? *getSymbolicStrides() :<br>
+ ValueToValueMap();<br>
<br>
+ int Stride = getPtrStride(PSE, Ptr, TheLoop, Strides, true, false);<br>
+ if (Stride == 1 || Stride == -1)<br>
+ return Stride;<br>
return 0;<br>
}<br>
<br>
@@ -2658,7 +2584,9 @@ void InnerLoopVectorizer::vectorizeMemor<br>
// Handle consecutive loads/stores.<br>
GetElementPtrInst *Gep = getGEPInstruction(Ptr);<br>
if (ConsecutiveStride) {<br>
- if (Gep && Legal->isInductionVariable(Gep->getPointerOperand())) {<br>
+ if (Gep &&<br>
+ !PSE.getSE()->isLoopInvariant(PSE.getSCEV(Gep->getPointerOperand()),<br>
+ OrigLoop)) {<br>
setDebugLocFromInst(Builder, Gep);<br>
Value *PtrOperand = Gep->getPointerOperand();<br>
Value *FirstBasePtr = getVectorValue(PtrOperand)[0];<br>
@@ -2671,9 +2599,6 @@ void InnerLoopVectorizer::vectorizeMemor<br>
Ptr = Builder.Insert(Gep2);<br>
} else if (Gep) {<br>
setDebugLocFromInst(Builder, Gep);<br>
- assert(PSE.getSE()->isLoopInvariant(PSE.getSCEV(Gep->getPointerOperand()),<br>
- OrigLoop) &&<br>
- "Base ptr must be invariant");<br>
// The last index does not have to be the induction. It can be<br>
// consecutive and be a function of the index. For example A[I+1];<br>
unsigned NumOperands = Gep->getNumOperands();<br>
@@ -2702,8 +2627,6 @@ void InnerLoopVectorizer::vectorizeMemor<br>
}<br>
Ptr = Builder.Insert(Gep2);<br>
} else { // No GEP<br>
- // Use the induction element ptr.<br>
- assert(isa<PHINode>(Ptr) && "Invalid induction ptr");<br>
setDebugLocFromInst(Builder, Ptr);<br>
VectorParts &PtrVal = getVectorValue(Ptr);<br>
Ptr = Builder.CreateExtractElement(PtrVal[0], Zero);<br>
<br>
Added: llvm/trunk/test/Transforms/LoopVectorize/consec_no_gep2.ll<br>
URL:<span class="apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopVectorize/consec_no_gep2.ll?rev=273864&view=auto" target="_blank"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopVectorize/consec_no_gep2.ll?rev=273864&view=auto</span></a><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/LoopVectorize/consec_no_gep2.ll (added)<br>
+++ llvm/trunk/test/Transforms/LoopVectorize/consec_no_gep2.ll Mon Jun 27 06:19:23 2016<br>
@@ -0,0 +1,34 @@<br>
+; RUN: opt < %s -loop-vectorize -S | FileCheck %s<br>
+target datalayout = "E-m:e-i64:64-n32:64"<br>
+target triple = "powerpc64-unknown-linux-gnu"<br>
+<br>
+; CHECK-LABEL: @img2buf<br>
+; CHECK: store <4 x i32><br>
+; Function Attrs: nounwind<br>
+define void @img2buf(i64 %val, i8* nocapture %buf, i32 %N) local_unnamed_addr #0 {<br>
+entry:<br>
+ br label %l2<br>
+<br>
+l2:<br>
+ br label %<a href="http://for.body57.us/" target="_blank"><span style="color:purple">for.body57.us</span></a><br>
+<br>
+<a href="http://for.body57.us/" target="_blank"><span style="color:purple">for.body57.us</span></a>:<br>
+ %indvars.iv24 = phi i64 [ %val, %l2 ], [ %indvars.iv.next25, %<a href="http://for.body57.us/" target="_blank"><span style="color:purple">for.body57.us</span></a><span class="apple-converted-space"> </span>]<br>
+ %0 = trunc i64 %indvars.iv24 to i32<br>
+ %<a href="http://add77.us/" target="_blank"><span style="color:purple">add77.us</span></a><span class="apple-converted-space"> </span>= add i32 5, %0<br>
+ %<a href="http://mul78.us/" target="_blank"><span style="color:purple">mul78.us</span></a><span class="apple-converted-space"> </span>= shl nsw i32 %<a href="http://add77.us/" target="_blank"><span style="color:purple">add77.us</span></a>, 2<br>
+ %<a href="http://idx.ext79.us/" target="_blank"><span style="color:purple">idx.ext79.us</span></a><span class="apple-converted-space"> </span>= sext i32 %<a href="http://mul78.us/" target="_blank"><span style="color:purple">mul78.us</span></a><span class="apple-converted-space"> </span>to
i64<br>
+ %<a href="http://add.ptr80.us/" target="_blank"><span style="color:purple">add.ptr80.us</span></a><span class="apple-converted-space"> </span>= getelementptr inbounds i8, i8* %buf, i64 %<a href="http://idx.ext79.us/" target="_blank"><span style="color:purple">idx.ext79.us</span></a><br>
+ %<a href="http://ui32.0.add.ptr80.sroa_cast.us/" target="_blank"><span style="color:purple">ui32.0.add.ptr80.sroa_cast.us</span></a><span class="apple-converted-space"> </span>= bitcast i8* %<a href="http://add.ptr80.us/" target="_blank"><span style="color:purple">add.ptr80.us</span></a><span class="apple-converted-space"> </span>to
i32*<br>
+ store i32 0, i32* %<a href="http://ui32.0.add.ptr80.sroa_cast.us/" target="_blank"><span style="color:purple">ui32.0.add.ptr80.sroa_cast.us</span></a>, align 1<br>
+ %indvars.iv.next25 = add nsw i64 %indvars.iv24, 1<br>
+ %lftr.wideiv26 = trunc i64 %indvars.iv.next25 to i32<br>
+ %exitcond27 = icmp eq i32 %lftr.wideiv26, %N<br>
+ br i1 %exitcond27, label %l3, label %<a href="http://for.body57.us/" target="_blank"><span style="color:purple">for.body57.us</span></a><br>
+<br>
+l3:<br>
+ ret void<br>
+}<br>
+<br>
+attributes #0 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="ppc64" "target-features"="+altivec,-bpermd,-crypto,-direct-move,-extdiv,-power8-vector,-qpx,-vsx"
"unsafe-fp-math"="false" "use-soft-float"="false" }<br>
+<br>
<br>
Modified: llvm/trunk/test/Transforms/LoopVectorize/ptr-induction.ll<br>
URL:<span class="apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopVectorize/ptr-induction.ll?rev=273864&r1=273863&r2=273864&view=diff" target="_blank"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopVectorize/ptr-induction.ll?rev=273864&r1=273863&r2=273864&view=diff</span></a><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/LoopVectorize/ptr-induction.ll (original)<br>
+++ llvm/trunk/test/Transforms/LoopVectorize/ptr-induction.ll Mon Jun 27 06:19:23 2016<br>
@@ -18,6 +18,7 @@ while.body.preheader:<br>
while.body: ; preds = %while.body.preheader, %while.body<br>
%<a href="http://a.pn/" target="_blank"><span style="color:purple">a.pn</span></a><span class="apple-converted-space"> </span>= phi i32* [ %incdec.ptr8, %while.body ], [ %a, %while.body.preheader ]<br>
%acc.07 = phi i32 [ %add, %while.body ], [ 0, %while.body.preheader ]<br>
+ %<a href="http://a1.pn/" target="_blank"><span style="color:purple">a1.pn</span></a><span class="apple-converted-space"> </span>= getelementptr inbounds i32, i32* %<a href="http://a.pn/" target="_blank"><span style="color:purple">a.pn</span></a>, i64 0<br>
%incdec.ptr8 = getelementptr inbounds i32, i32* %<a href="http://a.pn/" target="_blank"><span style="color:purple">a.pn</span></a>, i64 1<br>
%0 = load i32, i32* %incdec.ptr8, align 1<br>
%add = add nuw nsw i32 %0, %acc.07<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank"><span style="color:purple">llvm-commits@lists.llvm.org</span></a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" target="_blank"><span style="color:purple">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</span></a><o:p></o:p></p>
</div>
</blockquote>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;orphans: auto;text-align:start;widows: auto;-webkit-text-stroke-width: 0px;word-spacing:0px">
<span style="font-size:9.0pt;font-family:"Helvetica",sans-serif">---------------------------------------------------------------------<br>
Intel Israel (74) Limited<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;orphans: auto;text-align:start;widows: auto;-webkit-text-stroke-width: 0px;word-spacing:0px">
<span style="font-size:9.0pt;font-family:"Helvetica",sans-serif">This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif">_______________________________________________<br>
llvm-commits mailing list<br>
</span><a href="mailto:llvm-commits@lists.llvm.org"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif;color:purple">llvm-commits@lists.llvm.org</span></a><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif"><br>
</span><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif;color:purple">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</span></a><o:p></o:p></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<p>---------------------------------------------------------------------<br>
Intel Israel (74) Limited</p>
<p>This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.</p></body>
</html>