About register allocation

I have tested the register allocation in llvm, using: $llc -debug test.bc
where, test.c is like:

int a, b, c, d, x;
a = 3;
b = 5;
d = 4;
x = 100;
if ( a > b )

And I got the machine code before register allocation:

MOV32mi <fi#2>, 1, %reg0, 0, %reg0, 3; mem:ST4[%a]
MOV32mi <fi#3>, 1, %reg0, 0, %reg0, 5; mem:ST4[%b]
MOV32mi <fi#5>, 1, %reg0, 0, %reg0, 4; mem:ST4[%d]
MOV32mi <fi#6>, 1, %reg0, 0, %reg0, 100; mem:ST4[%x]
%reg16384 = MOV32rm <fi#3>, 1, %reg0, 0, %reg0; mem:LD4[%b] GR32:%reg16384
CMP32mr <fi#2>, 1, %reg0, 0, %reg0, %reg16384, %EFLAGS; mem:LD4[%a] GR32:%reg16384
JLE_4 <BB#2>, %EFLAGS<imp-use,kill>

The machine code after register allocation:

MOV32mi <fi#2>, 1, %reg0, 0, %reg0, 3; mem:ST4[%a]
MOV32mi <fi#3>, 1, %reg0, 0, %reg0, 5; mem:ST4[%b]
MOV32mi <fi#5>, 1, %reg0, 0, %reg0, 4; mem:ST4[%d]
MOV32mi <fi#6>, 1, %reg0, 0, %reg0, 100; mem:ST4[%x]
%EAX = MOV32rm <fi#3>, 1, %reg0, 0, %reg0; mem:LD4[%b]Remembering SS#3 in physreg EAX
CMP32mr <fi#2>, 1, %reg0, 0, %reg0, %EAX, %EFLAGS; mem:LD4[%a]
JLE_4 <BB#2>, %EFLAGS<imp-use,kill>

It seems only variables named “reg” are allocated into registers. My problem is, why not allocate the local variables “a”, “b”, .etc into registers instead of into stack frame? Is there any problem for allocating “a” into register file rather than stack frame with offset of 2?

You need to optimize your bitcode first, llc doesn't do that.

Run the bitcode through "opt -O2", or create it with "llvm-gcc -O2 -emit-llvm".

/jakob