Skip to content

Invalid register allocation #2837

@asl

Description

@asl
Bugzilla Link 2465
Resolution FIXED
Resolved on Nov 07, 2018 00:17
Version trunk
OS Linux
Attachments Bytecode in questions
CC @efriedma-quic

Extended Description

Consider the attached .ll file (sorry, I wasn't be able to reduce it).

in bb27.i.i74 we're seeing:

bb27.i.i74: ; preds = %bb14.i.i
%tmp30.i.i69 = getelementptr i8* %tmp1097, i32 %x_addr.0.i.i ; <i8*> [#uses=1]
%tmp31.i.i70 = load i8* %tmp30.i.i69, align 1 ; [#uses=2]
%tmp34.i.i71 = getelementptr i8* %tmp1094, i32 %y.0.i.i ; <i8*> [#uses=1]
%tmp35.i.i72 = load i8* %tmp34.i.i71, align 1 ; [#uses=1]
%tmp36.i.i73 = icmp eq i8 %tmp31.i.i70, %tmp35.i.i72 ; [#uses=1]
zext i8 %tmp31.i.i70 to i32 ; :1418 [#uses=2]
%tmp1.i2918 = and i32 %1418, 1 ; [#uses=1]
%tmp2.i2919 = xor i32 %tmp1.i2918, 1 ; [#uses=1]
%tmp4.i2920 = sub i32 0, %1418 ; [#uses=1]
%tmp.i2921 = icmp ne i32 %tmp2.i2919, %tmp4.i2920 ; [#uses=1]
and i1 %tmp36.i.i73, %tmp.i2921 ; :1419 [#uses=1]
br i1 %1419, label %bb9.i.i, label %snake.exit.i

so, two GEPs plus some innocent bit plays.

These are codegen'ed into:

LBB5_811: # bb27.i.i74
movl 208(%esp), %ecx
movb (%ecx,%ebp), %al
movzbl %al, %ecx
movl %ecx, %edx
andl $1, %edx
negl %ecx
xorl $1, %edx
movl 204(%esp), %ebx
cmpb (%ebx,%ecx), %al
jne LBB5_813 # bb14.i.i.snake.exit.i_crit_edge

Note, that
%tmp35.i.i72 = load i8* %tmp34.i.i71, align 1 ; [#uses=1]
%tmp36.i.i73 = icmp eq i8 %tmp31.i.i70, %tmp35.i.i72 ;

is turned into

    movl    204(%esp), %ebx
    cmpb    (%ebx,%ecx), %al

which is definitely incorrect, since %ecx was already clobbered by computations.

If I run opt -std-compile-opts before, result is pretty sane:

LBB5_744: # bb27.i.i74
movl 208(%esp), %esi
movb (%esi,%edx), %bl
movzbl %bl, %esi
movl %esi, %ebp
negl %ebp
andl $1, %esi
xorl $1, %esi
cmpl %ebp, %esi
movl 204(%esp), %esi
movb (%esi,%eax), %bh
je LBB5_746 # bb14.i.i.snake.exit.i_crit_edge

here %eax and %edx are liveins from prev BBs, where GEP indices were calculated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions