[LLVMdev] Thumb-2 code generation error in Apple LLVM at all optimization levels

Owen Anderson resistor at mac.com
Fri Nov 11 17:26:16 PST 2011


On Nov 11, 2011, at 4:14 PM, Don Quixote de la Mancha wrote:
> cmp.w *looks* like a 16-bit comparison with an immediate constant, but
> in reality the constant is twelve bits.  The ARM and Thumb instruction
> sets have quite severe restrictions on the allowed ranges of immediate
> values because the richness of the ARM and Thumb instruction set makes
> it hard to find enough bits in the instruction words to express a
> wider range of immediate values than is presently possible.

This is not quite right.  It does have a 12-bit immediate field, but it is decomposed into an 8-bit base immediate and a 4-bit right-rotate value.  Your example of #4000 is encoded as a base value of 0xfa and a rotate of 0xe, which is correct.

> I don't know what the "it hs" instruction does.  I suspect that's
> where the problem lies, but "it" is a very common word, and "hs" is
> quite common as well, as it is a frequent mispelling for "has".
> Perhaps someone who knows Thumb-2 assembly better than I do could
> comment.

The IT instruction is how you express predication in Thumb2.  Unlike ARM instructions, where the predicate is part of the instruction, Thumb2 instructions use IT to set the predicates for following instructions.  In this case, it applies the "hs" predicate to the subsequent call to _usleep.  I'd have to double check, but I'm fairly confident that the hs condition code is equivalent to >= for integers.

--Owen




More information about the llvm-dev mailing list