llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

vector uitofp fails for 64-bit integers

Open llvmbot opened this issue 13 years ago • 2 comments

Bugzilla Link 15309
Resolution FIXED
Resolved on Mar 18, 2013 04:55
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @darkbuck

Extended Description

Let's consider following code to convert a 2 x i64 vector into a 2 x float vector:

; ModuleID = 'opencl-kernel-2N45Jj-2-src-def.ll' target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" target triple = "i386-pc-linux-gnu"

define void @​test_convert_float2_ulong2(<2 x i64>* nocapture %src, <2 x float>* nocapture %dest) noinline { L.entry: %0 = getelementptr <2 x i64>* %src, i32 10 %1 = load <2 x i64>* %0, align 16 %2 = uitofp <2 x i64> %1 to <2 x float> %3 = getelementptr <2 x float>* %dest, i32 10 store <2 x float> %2, <2 x float>* %3, align 8 ret void }

Using llc as follows:

llc -march=x86 uitofp.ll -o uitofp.s

We got following assembly generated:

.file	"uitofp.ll"
.section	.rodata.cst16,"aM",@progbits,16
.align	16

.LCPI0_0: .quad 4841369599423283200 # double 4.503600e+15 .quad 4841369599423283200 # double 4.503600e+15 .text .globl test_convert_float2_ulong2 .align 16, 0x90 .type test_convert_float2_ulong2,@function test_convert_float2_ulong2: # @​test_convert_float2_ulong2 .cfi_startproc

BB#0: # %L.entry

movl	4(%esp), %eax
movapd	.LCPI0_0, %xmm0
movapd	160(%eax), %xmm1
orpd	%xmm0, %xmm1
subpd	%xmm0, %xmm1
cvtpd2ps	%xmm1, %xmm0
movl	8(%esp), %eax
extractps	$1, %xmm0, 84(%eax)
movss	%xmm0, 80(%eax)
ret

.Ltmp0: .size test_convert_float2_ulong2, .Ltmp0-test_convert_float2_ulong2 .cfi_endproc

.section	".note.GNU-stack","",@progbits

If for instance we want to convert vector <0x0010000000000000, 0x0010000000000000> expected result is: <0x59800000, 0x59800000>. With implemented algorithm we got:

orpd %xmm0, %xmm1 => xmm1 = <0x4330000000000000, 0x4330000000000000> | <0x0010000000000000, 0x0010000000000000> = <0x4330000000000000, 0x4330000000000000> subpd %xmm0, %xmm1 => xmm1 - xmm0 = <0x0000000000000000, 0x0000000000000000>

Thus final results is <0x00000000, 0x00000000> instead of <0x59800000, 0x59800000>.

llvmbot avatar Feb 20 '13 11:02 llvmbot

Thanks I confirm that your commit fixed the issue and didn't introduce any regression in test we are running.

llvmbot avatar Mar 18 '13 11:03 llvmbot

fixed in r177010. please check whether it works for you.

darkbuck avatar Mar 14 '13 09:03 darkbuck