<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 4:19 PM, Rail Shafigulin <<a href="mailto:rail@esenciatech.com" class="">rail@esenciatech.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br 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=""><div class="gmail_quote" 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;">On Fri, Mar 18, 2016 at 4:16 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 style="word-wrap: break-word;" class=""><br class=""><div class=""><blockquote type="cite" class=""><span class=""><div class="">On Mar 18, 2016, at 4:14 PM, Rail Shafigulin <<a href="mailto:rail@esenciatech.com" target="_blank" class="">rail@esenciatech.com</a>> wrote:</div><br class=""></span><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><span 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 style="word-wrap: break-word;" class=""><div class=""><span class=""><div class="">Here is how I started with SelectionDAG: <br class=""></div></span></div><div class=""><br class=""></div><div class="">- small IR (bugpoint can help)</div></div></blockquote></span><div class="">Did you mean a break point? </div></div></div></div></div></blockquote><div class=""><br class=""></div>No I really meant bugpoint: <a href="http://llvm.org/docs/Bugpoint.html" target="_blank" class="">http://llvm.org/docs/Bugpoint.html</a></div><div class=""><span class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><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 style="word-wrap: break-word;" class=""><div class="">- the magic flag: -debug </div><div class="">- read the output of SelectionDAG debugging (especially with cycles)</div><div class="">- matching the log to source code</div></div></blockquote><div class="">What log are you talking about?</div></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">llc -debug mentioned above.</div></div></div></blockquote><div class="">What do you mean by matching a log to source? What log are you talking about? </div></div></div></blockquote><div><br class=""></div><div>I'm talking about this:</div><div><br class=""></div><div><br class=""></div></div>$ cat <<EOF | ../ninja-clang-release/bin/clang -x c - -emit-llvm -S -o - -O3 | ../ninja-clang-release/bin/llc -debug 2>&1 | grep -i combining -C 20<br class="">> void foo (int a1, int a2, int a3, int a4, int b1, int b2, int b3, int b4, int *res) {<br class="">>   res[0] = a1 + b1 * 2;<br class="">>   res[1] = a2 + b2 * 2;<br class="">>   res[2] = a3 + b3 * 2;<br class="">>   res[3] = a4 + b4 * 2;<br class="">> }<br class="">> EOF<br class="">...<br class=""><div class="">...</div><div class="">=== foo<br class="">Initial selection DAG: BB#0 'foo:entry'<br class="">SelectionDAG has 43 nodes:<br class="">  t0: ch = EntryToken<br class="">  t21: i32 = Constant<0><br class="">  t27: i32 = Constant<2><br class="">  t30: i32 = Constant<3><br class="">                t2: i32,ch = CopyFromReg t0, Register:i32 %vreg0<br class="">              t35: v4i32 = insert_vector_elt undef:v4i32, t2, Constant:i64<0><br class="">              t4: i32,ch = CopyFromReg t0, Register:i32 %vreg1<br class="">            t36: v4i32 = insert_vector_elt t35, t4, Constant:i64<1><br class="">            t6: i32,ch = CopyFromReg t0, Register:i32 %vreg2<br class="">          t37: v4i32 = insert_vector_elt t36, t6, Constant:i64<2><br class="">          t8: i32,ch = CopyFromReg t0, Register:i32 %vreg3<br class="">        t38: v4i32 = insert_vector_elt t37, t8, Constant:i64<3><br class="">                  t10: i32,ch = CopyFromReg t0, Register:i32 %vreg4<br class="">                t23: v4i32 = insert_vector_elt undef:v4i32, t10, Constant:i64<0><br class="">                t12: i32,ch = CopyFromReg t0, Register:i32 %vreg5<br class="">              t26: v4i32 = insert_vector_elt t23, t12, Constant:i64<1><br class="">              t15: i32,ch = load<LD4[FixedStack-1]> t0, FrameIndex:i64<-1>, undef:i64<br class="">            t29: v4i32 = insert_vector_elt t26, t15, Constant:i64<2><br class="">            t17: i32,ch = load<LD4[FixedStack-2]> t0, FrameIndex:i64<-2>, undef:i64<br class="">          t32: v4i32 = insert_vector_elt t29, t17, Constant:i64<3><br class="">          t33: v4i32 = BUILD_VECTOR Constant:i32<1>, Constant:i32<1>, Constant:i32<1>, Constant:i32<1><br class="">        t34: v4i32 = shl t32, t33<br class="">      t39: v4i32 = add t38, t34<br class="">      t19: i64,ch = load<LD8[FixedStack-3]> t0, FrameIndex:i64<-3>, undef:i64<br class="">    t40: ch = store<ST16[%10](align=4)(tbaa=<0x7fd81b503a58>)> t0, t39, t19, undef:i64<br class="">  t42: ch = X86ISD::RET_FLAG t40, TargetConstant:i16<0><br class=""><br class=""><br class=""><br class="">Combining: t42: ch = X86ISD::RET_FLAG t40, TargetConstant:i16<0><br class=""><br class="">Combining: t41: i16 = TargetConstant<0><br class=""><br class="">Combining: t40: ch = store<ST16[%10](align=4)(tbaa=<0x7fd81b503a58>)> t0, t39, t19, undef:i64<br class=""><br class="">Combining: t39: v4i32 = add t38, t34<br class=""><br class="">Combining: t38: v4i32 = insert_vector_elt t37, t8, Constant:i64<3><br class=""><br class="">Combining: t37: v4i32 = insert_vector_elt t36, t6, Constant:i64<2><br class=""><br class="">Combining: t36: v4i32 = insert_vector_elt t35, t4, Constant:i64<1><br class=""><br class="">Combining: t35: v4i32 = insert_vector_elt undef:v4i32, t2, Constant:i64<0><br class=""> ... into: t44: v4i32 = BUILD_VECTOR t2, undef:i32, undef:i32, undef:i32<br class=""><br class="">Combining: t36: v4i32 = insert_vector_elt t44, t4, Constant:i64<1><br class=""> ... into: t45: v4i32 = BUILD_VECTOR t2, t4, undef:i32, undef:i32<br class=""><br class=""><br class=""></div><div class="">...</div><div class=""><br class=""></div><div class="">..</div><div class="">...</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Legalizing: t53: v4i32 = BUILD_VECTOR t10, t12, t15, t17<br class=""> ... replacing: t53: v4i32 = BUILD_VECTOR t10, t12, t15, t17<br class="">     with:      t61: v4i32 = vector_shuffle<0,4,1,5> t59, t60<br class=""><br class="">Legalizing: t47: v4i32 = BUILD_VECTOR t2, t4, t6, t8<br class=""> ... replacing: t47: v4i32 = BUILD_VECTOR t2, t4, t6, t8<br class="">     with:      t68: v4i32 = vector_shuffle<0,4,1,5> t66, t67<br class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">This is exactly what happens in SelectionDAG, and matching these messages to the source code should help figuring what SelectionDAG is doing and why.</div><div class=""><br class=""></div><div class="">-- </div><div class="">Mehdi</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>