[LLVMdev] Tablegen: RegisterInfoEmitter.cpp
Jakob Stoklund Olesen
stoklund at 2pi.dk
Mon Oct 3 08:17:49 PDT 2011
On Oct 1, 2011, at 2:42 AM, Jonas Paulsson wrote:
> 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.
Almost. It is trying to compare embedded sequences of digits as numbers. It does this by first comparing the length of the digit sequence, and then a lexicographical comparison of equal length digit sequences.
> I guess then this order should hold: a12 == a22 < a1b, for these strings.
No, a1b < a12 < a22. "a1b" is smaller than "a12" because it has fewer digits. "a12" has the same number of digits as "a22", but it is lexicographically smaller.
> Looking at StringRef::compare_numeric(StringRef RHS), the problem is, for a12 and a1b, Data==RHS.Data, and the continue is reached. Data is then less than RHS.Data, 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.
> 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.
> I think the fix is to first check for two digits, and move the equality comparison to after this. Then a2g < a3g < a23g:
> > if (Data[I] == RHS.Data[I])
> > continue;
> < if (Data[I] == RHS.Data[I])
> < continue;
> 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.
Your fix is correct, but there is one problem: The algorithm is now quadratic in the length of embedded digit sequences.
This is easy to fix, see r140859.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev