LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1033 - bitcast between long and double on x86-64
Summary: bitcast between long and double on x86-64
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: X86 (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Chris Lattner
URL:
Keywords: compile-fail
Depends on:
Blocks:
 
Reported: 2006-12-04 11:58 PST by Dan Gohman
Modified: 2010-02-22 12:48 PST (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Gohman 2006-12-04 11:58:41 PST
On x86-64 a bitcast from long to double or double to long results triggers an
llc abort. Among other things, this comes up in the expansion of copysign.

long %p(double %t) {
  %u = bitcast double %t to long
  ret long %u
}

double %q(long %t) {
  %u = bitcast long %t to double
  ret double %u
}

With llc -march=x86-64, this gets

Cannot yet select: 0x8813318: f64 = bit_convert 0x88135c8
Comment 1 Reid Spencer 2006-12-04 12:18:06 PST
Mine.
Comment 2 Chris Lattner 2006-12-04 12:18:46 PST
I think this is a codegen bug Reid,

-Chris
Comment 3 Reid Spencer 2006-12-04 12:30:07 PST
This one looks like yours Evan. It seems the TD for x86-64 isn't handling bit
casts of 64-bit things.

The test case for it has already been committed to Regression/CodeGen/X86.

Reid.
Comment 4 Chris Lattner 2006-12-05 12:23:52 PST
The preferred fix for this is to expand it into movd/movq.  However, Evan is busy with other things, so 
this won't happen in the near term.  In the short-term, this patch gets us correct, but suboptimal (goes 
through memory) code:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20061204/040803.html


Testcase here: CodeGen/X86/bitcast.ll

-Chris

_test1:
        subq $8, %rsp
        movsd %xmm0, (%rsp)
        movq (%rsp), %rax
        addq $8, %rsp
        ret
_test2:
        subq $8, %rsp
        movq %rdi, (%rsp)
        movsd (%rsp), %xmm0
        addq $8, %rsp
        ret

Comment 5 Chris Lattner 2006-12-05 12:47:21 PST
Actually, MOVQ apparently doesn't do 64-bit GPR to SSE reg.

I implemented the movd case, compiling bitcast.ll::test3/test4 to:

_test3:
        movd %xmm0, %eax
        ret
_test4:
        movd %edi, %xmm0
        ret

Patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20061204/040806.html