LLVM BUG for x86 code generation ?

HI All,

when I compiled attached .ll file with llc 2.8 as follows:

llc -O0 -march=x86 llvmfails.ll -o llvmfails.s
gcc -m32 llvmfails.s -o llvmfails
./llvmfails

the executable exits with the expected message: "SUCCESS", whereas if I use -O1 instead of -O0 for LLC, it prints out FAILS.

llc -O0 -march=x86 llvmfails.ll -o llvmfails.s
gcc -m32 llvmfails.s -o llvmfails
./llvmfails

As far as I can tell code generation for select instruction is not correct, It seems that sign-extension propagation convert a sign-extension into a zero-extend.
Routine to look at is:

@result = internal global i32 0
define void @test() {
L.entry:
        %__.I0000610 = alloca i32
        call void @init()
        %0 = load i32* @t
        %1 = icmp eq i32 %0, 0
        %2 = zext i1 %1 to i32
        %3 = trunc i32 %2 to i1
        %4 = load i8* @uc
        %5 = zext i8 %4 to i32
        %6 = load i8* @sc
        %7 = sext i8 %6 to i32
        %8 = select i1 %3, i32 %5, i32 %7
        store i32 %8, i32* %__.I0000610
        %9 = load i32* %__.I0000610
        call void @seti(i32* @result, i32 %9)
        ret void
}

llvmfails.ll (1.68 KB)

HI All,

when I compiled attached .ll file with llc 2.8 as follows:

llc -O0 -march=x86 llvmfails.ll -o llvmfails.s
gcc -m32 llvmfails.s -o llvmfails
./llvmfails

the executable exits with the expected message: "SUCCESS", whereas if I use -O1 instead of -O0 for LLC, it prints out FAILS.

llc -O0 -march=x86 llvmfails.ll -o llvmfails.s
gcc -m32 llvmfails.s -o llvmfails
./llvmfails

As far as I can tell code generation for select instruction is not correct, It seems that sign-extension propagation convert a sign-extension into a zero-extend.
Routine to look at is:

@result = internal global i32 0
define void @test() {
L.entry:
        %__.I0000610 = alloca i32
        call void @init()
        %0 = load i32* @t
        %1 = icmp eq i32 %0, 0
        %2 = zext i1 %1 to i32
        %3 = trunc i32 %2 to i1
        %4 = load i8* @uc
        %5 = zext i8 %4 to i32
        %6 = load i8* @sc
        %7 = sext i8 %6 to i32
        %8 = select i1 %3, i32 %5, i32 %7
        store i32 %8, i32* %__.I0000610
        %9 = load i32* %__.I0000610
        call void @seti(i32* @result, i32 %9)
        ret void
}

Can you confirm that ?
Best Regards
Seb

llvmfails.ll (1.68 KB)

Hi Sebastian,

when I compiled attached .ll file with llc 2.8 as follows:

llc -O0 -march=x86 llvmfails.ll -o llvmfails.s
gcc -m32 llvmfails.s -o llvmfails
./llvmfails

the executable exits with the expected message: "SUCCESS", whereas if I use -O1 instead of -O0 for LLC, it prints out FAILS.

llc -O0 -march=x86 llvmfails.ll -o llvmfails.s
gcc -m32 llvmfails.s -o llvmfails
./llvmfails

does the attached patch fix your problems?

Ciao,

Duncan.

PS: In the future please open a bug report when reporting a bug.

llvmfails.diff (945 Bytes)

Hi Duncan,

I've patched LLVM 2.8 source tree, and it doesn't fix the problem on my side.
Did you checked that your patch fixes the problem ?

Best Regards
Seb

Hi Sebastien,

I've patched LLVM 2.8 source tree, and it doesn't fix the problem on my side.

Are you sure you tested using the newly built llc?

Did you checked that your patch fixes the problem ?

I did:

Before:
$ llc -O1 -march=x86 llvmfails.ll -o llvmfails.s
$ gcc -m32 llvmfails.s -o llvmfails && ./llvmfails
FAILS

After:

$ ~/LLVM/llvm-objects/Debug+Asserts/bin/llc -O1 -march=x86 llvmfails.ll -o llvmfails.s
$ gcc -m32 llvmfails.s -o llvmfails && ./llvmfails
SUCCESS

Ciao,

Duncan.

Hi Duncan,

I think, I found my problem, I've patch 2.8 source tree, I guess I need to patch dev source tree right ?
Anyway, thanks for the time you spend on this problem.

Best Regards
Seb

Hi Seb,

I think, I found my problem, I've patch 2.8 source tree, I guess I need to patch dev source tree right ?
Anyway, thanks for the time you spend on this problem.

I applied my fix in commit 119728.

Ciao,

Duncan.