<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I’ve corrected the test to match current output in my patch. I think from what you guys say that’s perfectly good enough.<div class=""><br class=""></div><div class="">I’ll submit to the AVR team via the maintainer.</div><div class=""><br class=""></div><div class="">Thanks for your help guys. :)<br class=""><div class=""><br class=""></div><div class="">Carl<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 8 Mar 2019, at 19:49, via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">-----Original Message-----<br class="">From: llvm-dev [<a href="mailto:llvm-dev-bounces@lists.llvm.org" class="">mailto:llvm-dev-bounces@lists.llvm.org</a>] On Behalf Of Carl<br class="">Peto via llvm-dev<br class="">Sent: Thursday, March 07, 2019 5:44 PM<br class="">To: llvm-dev<br class="">Subject: [llvm-dev] Writing unit tests - how to test re-orderable<br class="">blocks...<br class=""><br class="">We have a test that looks like this…<br class=""><br class="">define void @array16_store() {<br class="">; CHECK-LABEL: array16_store:<br class=""><br class="">; CHECK: ldi [[REG1:r[0-9]+]], 204<br class="">; CHECK: ldi [[REG2:r[0-9]+]], 170<br class="">; CHECK: sts int.array+3, [[REG2]]<br class="">; CHECK: sts int.array+2, [[REG1]]<br class=""><br class="">; CHECK: ldi [[REG1:r[0-9]+]], 187<br class="">; CHECK: ldi [[REG2:r[0-9]+]], 170<br class="">; CHECK: sts int.array+1, [[REG2]]<br class="">; CHECK: sts int.array, [[REG1]]<br class=""><br class=""><br class="">; CHECK: ldi [[REG1:r[0-9]+]], 221<br class="">; CHECK: ldi [[REG2:r[0-9]+]], 170<br class="">; CHECK: sts int.array+5, [[REG2]]<br class="">; CHECK: sts int.array+4, [[REG1]]<br class=""> store i16 43707, i16* getelementptr inbounds ([3 x i16], [3 x i16]*<br class="">@int.array, i32 0, i64 0)<br class=""> store i16 43724, i16* getelementptr inbounds ([3 x i16], [3 x i16]*<br class="">@int.array, i32 0, i64 1)<br class=""> store i16 43741, i16* getelementptr inbounds ([3 x i16], [3 x i16]*<br class="">@int.array, i32 0, i64 2)<br class=""> ret void<br class="">}<br class=""><br class=""><br class=""><br class="">The issue I have is this test is unnecessarily fragile because the<br class="">compiler can (and recently has) decided to reorder the blocks in a<br class="">perfectly valid way.  For example:<br class=""><br class="">; %bb.0:<br class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>ldi<span class="Apple-tab-span" style="white-space: pre;">       </span>r24, 221<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>ldi<span class="Apple-tab-span" style="white-space: pre;">       </span>r25, 170<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>sts<span class="Apple-tab-span" style="white-space: pre;">       </span>int.array+5, r25<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>sts<span class="Apple-tab-span" style="white-space: pre;">       </span>int.array+4, r24<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>ldi<span class="Apple-tab-span" style="white-space: pre;">       </span>r24, 204<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>ldi<span class="Apple-tab-span" style="white-space: pre;">       </span>r25, 170<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>sts<span class="Apple-tab-span" style="white-space: pre;">       </span>int.array+3, r25<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>sts<span class="Apple-tab-span" style="white-space: pre;">       </span>int.array+2, r24<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>ldi<span class="Apple-tab-span" style="white-space: pre;">       </span>r24, 187<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>ldi<span class="Apple-tab-span" style="white-space: pre;">       </span>r25, 170<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>sts<span class="Apple-tab-span" style="white-space: pre;">       </span>int.array+1, r25<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>sts<span class="Apple-tab-span" style="white-space: pre;">       </span>int.array, r24<br class=""><span class="Apple-tab-span" style="white-space: pre;">       </span>ret<br class=""><br class=""><br class="">The three blocks should be independent, it doesn’t matter whether it does<br class="">the store to array+5 and array+4 first or last. What matters is that each<br class="">block stays together, these instructions must stay together for example:<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>ldi<span class="Apple-tab-span" style="white-space: pre;">       </span>r24, 221<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>ldi<span class="Apple-tab-span" style="white-space: pre;">       </span>r25, 170<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>sts<span class="Apple-tab-span" style="white-space: pre;">       </span>int.array+5, r25<br class=""><span class="Apple-tab-span" style="white-space: pre;">     </span>sts<span class="Apple-tab-span" style="white-space: pre;">       </span>int.array+4, r24<br class=""><br class="">But that could come after the other two blocks or before them.<br class=""><br class=""><br class=""><br class="">How can I write FileCheck conditions to test this? If they were single re-<br class="">orderable lines, I could use CHECK-DAG for each, but I need the four lines<br class="">of each block to stay together.<br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">I would capture the text output to a file, and run FileCheck multiple times</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">on the same file, once for each group of instructions. You would need to give<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">each block of CHECK lines its own prefix, but that's a small thing.</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">But I would second the observation that even if different orders are valid,</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">the compiler's behavior should be deterministic, aside from patches that</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">change the ordering for a specific reason. This kind of breakage ought to</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">be unusual, and if it's not, that's likely a bug that should be fixed</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">instead of you working around it in your test.</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">--paulr</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br class="">Can anyone offer advice?<br class=""><br class="">Carl<br class="">_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class=""><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class=""></blockquote><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">_______________________________________________</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">LLVM Developers mailing list</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><a href="mailto:llvm-dev@lists.llvm.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">llvm-dev@lists.llvm.org</a><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: 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-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></div></blockquote></div><br class=""></div></div></body></html>