<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
<div dir="ltr">Hi,<br><br>I understand the idea behind compare_numeric() is to compare strings containing digits in a special way: Do a normal string-compare up to the point where both string elemnts are numerical. Find then an outcome based on the number of consecutive digits in the strings while disregarding the value of the digits, eg a12b < a123.<br><br>I guess then this order should hold: a12 == a22 < a1b, for these strings.<br><br>Looking at StringRef::compare_numeric(StringRef RHS), the problem is, for a12 and a1b, Data[1]==RHS.Data[1], and the continue is reached. Data[2] is then less than RHS.Data[2], so a12 < a1b. But in the case for a22 and a1b, we get the opposite, since '2'!='1', and 22 is more digits than 1. So we get a12 < a1b < a22, which is incorrect, because a12==a22.<br><br>My problem was with these registers: a23g, a2g and a3g. When I renamed a23g to aa23g, it worked. Since '2'=='2', the problem was that a23g<a2g.<br><br>I think the fix is to first check for two digits, and move the equality comparison to after this. Then a2g < a3g < a23g:<br><br>/// compare_numeric - Compare strings, handle embedded numbers.<br>int StringRef::compare_numeric(StringRef RHS) const {<br> for (size_t I = 0, E = min(Length, RHS.Length); I != E; ++I) {<br> if (ascii_isdigit(Data[I]) && ascii_isdigit(RHS.Data[I])) {<br> // The longer sequence of numbers is larger. This doesn't really handle<br> // prefixed zeros well.<br> for (size_t J = I+1; J != E+1; ++J) {<br> bool ld = J < Length && ascii_isdigit(Data[J]);<br> bool rd = J < RHS.Length && ascii_isdigit(RHS.Data[J]);<br> if (ld != rd)<br> return rd ? -1 : 1;<br> if (!rd)<br> break;<br> }<br> }<br> if (Data[I] == RHS.Data[I])<br> continue;<br> return (unsigned char)Data[I] < (unsigned char)RHS.Data[I] ? -1 : 1;<br> }<br> if (Length == RHS.Length)<br> return 0;<br> return Length < RHS.Length ? -1 : 1;<br>}<br><br>patch (2.9):<br>/lib/Support/StringRef.cpp:<br>48a49,50<br>> if (Data[I] == RHS.Data[I])<br>> continue;<br>61,62d62<br>< if (Data[I] == RHS.Data[I])<br>< continue;<br><br>I ran this, and now I have no problems, and the other targets built as well, at least, without problems. I have not run the testsuite.<br><br>Jonas<br><br><br><div><hr id="stopSpelling">Subject: Re: [LLVMdev] Tablegen: RegisterInfoEmitter.cpp<br>From: stoklund@2pi.dk<br>Date: Fri, 30 Sep 2011 08:39:51 -0700<br>CC: llvmdev@cs.uiuc.edu<br>To: jnspaulsson@hotmail.com<br><br>
<meta http-equiv="Content-Type" content="text/html; charset=unicode">
<meta name="Generator" content="Microsoft SafeHTML"><br><div><div>On Sep 30, 2011, at 8:29 AM, Jonas Paulsson wrote:</div><br class="ecxApple-interchange-newline"><blockquote><span class="ecxApple-style-span" style="border-collapse:separate;font-family:Optima;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;font-size:medium"><span class="ecxApple-style-span" style="font-family:Tahoma;font-size:13px">The conclusion is that the StringRef::compare_numeric() is not deterministic</span></span></blockquote></div><br><div>Thanks for tracking this down.</div><div><br></div><div>I believe we have a bug in compare_numeric() causing it to be non-transitive sometimes. It is supposed to provide a total ordering of strings. Can you find the bug?</div><div><br></div><div>/jakob</div><div><br></div></div></div>
</div></body>
</html>