<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 18, 2016, at 12:52 PM, Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" class="">mehdi.amini@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Mar 18, 2016, at 12:45 PM, Rail Shafigulin <<a href="mailto:rail@esenciatech.com" class="">rail@esenciatech.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="gmail_extra"><div class="gmail_quote">On Thu, Mar 17, 2016 at 2:41 PM, Rail Shafigulin<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:rail@esenciatech.com" target="_blank" class="">rail@esenciatech.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><span class="">On Thu, Mar 17, 2016 at 10:10 AM, Rail Shafigulin<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:rail@esenciatech.com" target="_blank" class="">rail@esenciatech.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div dir="ltr" class=""><div class="gmail_extra"><div class=""><div class=""><div class="gmail_quote">On Wed, Mar 16, 2016 at 6:38 PM, Mehdi Amini<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><span class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Mar 16, 2016, at 5:38 PM, Rail Shafigulin <<a href="mailto:rail@esenciatech.com" target="_blank" class="">rail@esenciatech.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote">On Wed, Mar 16, 2016 at 11:48 AM, Mehdi Amini<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div class="" style="word-wrap: break-word;">Hi Rail,<div class=""><br class=""></div><div class="">Two hints to begin with:<div class=""><br class=""></div><div class="">1) Makes sure you example is vectorized on X86 for example<div class="">2) Is your target correctly overriding the TTI (declaring the vector register size for example) so that the vectorizer can kicks-in (see X86TTIImpl::getRegisterBitWidth for instance). Alternatively you can test the SLP vectorizer by passing to clang: -mllvm -slp-max-reg-size -mllvm 512  (I don't see an equivalent option for the loop vectorizer though).</div><div class=""><br class=""></div></div></div></div></blockquote><div class="">Well, it sort of worked. I added a getRegisterBitWidth(...) but then I got this error:</div><div class=""><br class=""></div><div class=""><div class="">fatal error: error in backend: Cannot select: 0x5e949a8: v4i32 = BUILD_VECTOR 0x5e91ae8, 0x5e91ae8, 0x5e91ae8, 0x5e91ae8 [ORD=16] [ID=16]</div><div class=""> <span class="Apple-converted-space"> </span>0x5e91ae8: i32 = Constant<0> [ID=5]</div><div class=""> <span class="Apple-converted-space"> </span>0x5e91ae8: i32 = Constant<0> [ID=5]</div><div class=""> <span class="Apple-converted-space"> </span>0x5e91ae8: i32 = Constant<0> [ID=5]</div><div class=""> <span class="Apple-converted-space"> </span>0x5e91ae8: i32 = Constant<0> [ID=5]</div></div><div class=""><br class=""></div><div class="">What am I missing?</div></div></div></div></div></blockquote><div class=""><br class=""></div></div></span><div class="">I means that you have a vectorized IR that reached your backend, but your backend is not ready to deal with all the vector constructs in SelectionDAG. </div><div class="">You need to express how to legalize/select the BUILD_VECTOR in SelectionDAG to instructions that your target supports. You can look at what other targets are doing.</div><span class=""><font color="#888888" class=""><div class=""><br class=""></div><div class="">-- </div><div class="">Mehdi</div><div class=""><br class=""></div></font></span></div></blockquote></div></div></div></div></div></blockquote></span></div></div></div></blockquote><div class=""><br class=""></div><div class="">So I've added setOperationAction(ISD::BUILD_VECTOR,      MVT::v4i32, Expand); to my code but that generated a following error:</div><div class=""><br class=""></div><div class="">fatal error: error in backend: Cannot select: 0x6a84dc8: i32 = extract_vector_elt 0x6a85388, 0x6a813b0 [ORD=9] [ID=16]</div><div class="">  0x6a85388: v4i32 = add 0x6a81098, 0x6a81e00 [ORD=8] [ID=15]</div><div class="">    0x6a81098: v4i32 = add 0x6a81bf0, 0x6a84168 [ORD=6] [ID=12]</div><div class="">      0x6a81bf0: v4i32,ch = CopyFromReg 0x6a2b7f0, 0x6a819e0 [ORD=5] [ID=8]</div><div class="">        0x6a819e0: v4i32 = Register %vreg4 [ID=1]</div><div class="">      0x6a84168: v4i32 = vector_shuffle 0x6a81bf0, 0x6a857a8<2,3,u,u> [ORD=5] [ID=10]</div><div class="">        0x6a81bf0: v4i32,ch = CopyFromReg 0x6a2b7f0, 0x6a819e0 [ORD=5] [ID=8]</div><div class="">          0x6a819e0: v4i32 = Register %vreg4 [ID=1]</div><div class="">        0x6a857a8: v4i32 = undef [ID=2]</div><div class="">    0x6a81e00: v4i32 = vector_shuffle 0x6a81098, 0x6a857a8<1,u,u,u> [ORD=7] [ID=14]</div><div class="">      0x6a81098: v4i32 = add 0x6a81bf0, 0x6a84168 [ORD=6] [ID=12]</div><div class="">        0x6a81bf0: v4i32,ch = CopyFromReg 0x6a2b7f0, 0x6a819e0 [ORD=5] [ID=8]</div><div class="">          0x6a819e0: v4i32 = Register %vreg4 [ID=1]</div><div class="">        0x6a84168: v4i32 = vector_shuffle 0x6a81bf0, 0x6a857a8<2,3,u,u> [ORD=5] [ID=10]</div><div class="">          0x6a81bf0: v4i32,ch = CopyFromReg 0x6a2b7f0, 0x6a819e0 [ORD=5] [ID=8]</div><div class="">            0x6a819e0: v4i32 = Register %vreg4 [ID=1]</div><div class="">          0x6a857a8: v4i32 = undef [ID=2]</div><div class="">      0x6a857a8: v4i32 = undef [ID=2]</div><div class="">  0x6a813b0: i32 = Constant<0> [ID=3]</div><div class="">In function: main</div><div class=""><br class=""></div><div class="">Then I've added</div><div class="">setOperationAction(ISD::EXTRACT_VECTOR_ELT,      MVT::i32, Expand);<br class=""></div><div class=""><br class=""></div><div class="">but I still got the same error. So removed setOperationAction(ISD::EXTRACT_VECTOR_ELT,      MVT::i32, Expand); and added</div><div class=""><br class=""></div><div class="">setOperationAction(ISD::EXTRACT_VECTOR_ELT,      MVT::v4i32, Expand);<br class=""></div><div class=""><br class=""></div><div class="">which produced a following error:</div><div class=""><br class=""></div><div class=""><div class="">fatal error: error in backend: Cannot select: 0x7389250: v4i32 = vector_shuffle 0x73884e8, 0x738cbf8<1,u,u,u> [ORD=7] [ID=15]</div><div class="">  0x73884e8: v4i32 = add 0x7389040, 0x738b5b8 [ORD=6] [ID=13]</div><div class="">    0x7389040: v4i32,ch = CopyFromReg 0x73327f0, 0x7388e30 [ORD=5] [ID=9]</div><div class="">      0x7388e30: v4i32 = Register %vreg4 [ID=1]</div><div class="">    0x738b5b8: v4i32 = vector_shuffle 0x7389040, 0x738cbf8<2,3,u,u> [ORD=5] [ID=11]</div><div class="">      0x7389040: v4i32,ch = CopyFromReg 0x73327f0, 0x7388e30 [ORD=5] [ID=9]</div><div class="">        0x7388e30: v4i32 = Register %vreg4 [ID=1]</div><div class="">      0x738cbf8: v4i32 = undef [ID=2]</div><div class="">  0x738cbf8: v4i32 = undef [ID=2]</div><div class="">In function: main</div></div><div class=""><br class=""></div><div class="">Then I'v added setOperationAction(ISD::VECTOR_SHUFFLE,      MVT::v4i32, Expand);</div><div class=""><br class=""></div><div class="">and then my clang just hang. There is no error, no warning clang just sits there and nothing happens. </div></div></div></div></div></blockquote><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I think you created a cycle, this is easy to do with SelectionDAG :)<div class="">Basically SelecitonDAG will iterate until it does not see anything to change. So if you insert a transformation on a pattern A, that generates pattern B, while you have another transformation that matches B and generates somehow A, you run into an infinite loop.</div><div class=""><br class=""></div><div class=""><br class=""></div></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class="">I'm doing a lot of guess work in trying to understand what is going on. I would really appreciate any help on this.</div></div></div></div></div></blockquote><div class=""><br class=""></div></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Here is how I started with SelectionDAG: </div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">- small IR (bugpoint can help)</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">- the magic flag: -debug </div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">- read the output of SelectionDAG debugging (especially with cycles)</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">- matching the log to source code</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">- single stepping in a debugger sometimes.</div></div></blockquote><div><br class=""></div><div>Also: try to run your experiments with llc so you can easily tweak the input IR to SelectionDAG.</div><div><br class=""></div><div>-- </div><div>Mehdi</div><div><br class=""></div></div></body></html>