[LLVMdev] equivalent IR, different asm

Jakob Stoklund Olesen stoklund at 2pi.dk
Wed Sep 1 13:48:45 PDT 2010


On Sep 1, 2010, at 12:26 PM, Chris Lattner wrote:

> 
> On Sep 1, 2010, at 11:14 AM, Dale Johannesen wrote:
> 
>> 
>> On Sep 1, 2010, at 6:25 AMPDT, Argyrios Kyrtzidis wrote:
>> 
>>> The attached .ll files seem equivalent, but the resulting asm from  
>>> 'opt-fail.ll' causes a crash to webkit.
>>> I suspect the usage of registers is wrong, can someone take a look ?
>> 
>> Yes, the code here is wrong:
>> 
>>> 	movl	(%rbx), %ecx
>>> 	imull	%ecx, %eax
>> 
>> This computes h*((int32)%1) in %eax.
>> 
>>> 	shrq	$32, %rax
>>> 	movl	%eax, %ecx
>> 
>> This is trying to compute (int32)(%1>>32) into %ecx, but is using the  
>> wrong input value since %rax has been clobbered by the above code, and  
>> further is clobbering the value in %eax computed above, which is  
>> implicit input to the divide.  This is some kind of back end error,  
>> probably register allocator.
> 
> Jakob, can you take a look when you get a chance?

The instructions look like this before register coalescing:

156L    %reg1034<def> = COPY %reg1026:sub_32bit; GR32:%reg1034 GR64:%reg1026
164L    %reg1039<def> = MOV32rm %reg1025<kill>, 1, %reg0, 0, %reg0; mem:LD4[%h] GR32:%reg1039 GR64:%reg1025
172L    %reg1035<def> = COPY %reg1039<kill>; GR32:%reg1035,1039
180L    %reg1035<def> = IMUL32rr %reg1035, %reg1034<kill>, %EFLAGS<imp-def,dead>; GR32:%reg1035,1034
188L    %reg1036<def> = COPY %reg1026<kill>; GR64:%reg1036,1026
196L    %reg1036<def> = SHR64ri %reg1036, 32, %EFLAGS<imp-def,dead>; GR64:%reg1036
204L    %reg1037<def> = COPY %reg1036:sub_32bit<kill>; GR32:%reg1037 GR64:%reg1036
212L    %EAX<def> = COPY %reg1035<kill>; GR32:%reg1035

And after:

BB#1:           # derived from 
164L    %reg1035<def> = MOV32rm %reg1025<kill>, 1, %reg0, 0, %reg0; mem:LD4[%h] GR32:%reg1035 GR64:%reg1025
180L    %EAX<def> = IMUL32rr %EAX, %reg1035<kill>, %EFLAGS<imp-def,dead>; GR32:%reg1035
196L    %RAX<def> = SHR64ri %RAX, 32, %EFLAGS<imp-def,dead>
204L    %reg1037<def> = COPY %EAX; GR32:%reg1037

It looks like something got messed up when IMUL32rr was commuted. Possibly because both RAX and EAX are in play.

I'll take a look.

/jakob





More information about the llvm-dev mailing list