mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-24 21:25:41 +00:00
56318195bf
This patch allows atomic loads and stores of floating point to be specified in the IR and adds an adapter to allow them to be lowered via existing backend support for bitcast-to-equivalent-integer idiom. Previously, the only way to specify a atomic float operation was to bitcast the pointer to a i32, load the value as an i32, then bitcast to a float. At it's most basic, this patch simply moves this expansion step to the point we start lowering to the backend. This patch does not add canonicalization rules to convert the bitcast idioms to the appropriate atomic loads. I plan to do that in the future, but for now, let's simply add the support. I'd like to get instruction selection working through at least one backend (x86-64) without the bitcast conversion before canonicalizing into this form. Similarly, I haven't yet added the target hooks to opt out of the lowering step I added to AtomicExpand. I figured it would more sense to add those once at least one backend (x86) was ready to actually opt out. As you can see from the included tests, the generated code quality is not great. I plan on submitting some patches to fix this, but help from others along that line would be very welcome. I'm not super familiar with the backend and my ramp up time may be material. Differential Revision: http://reviews.llvm.org/D15471 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255737 91177308-0d34-0410-b5e6-96231b3b80d8
109 lines
3.1 KiB
LLVM
109 lines
3.1 KiB
LLVM
; RUN: llc < %s -mtriple=x86_64-linux-generic -verify-machineinstrs -mattr=sse2 | FileCheck %s
|
|
|
|
; Note: This test is testing that the lowering for atomics matches what we
|
|
; currently emit for non-atomics + the atomic restriction. The presence of
|
|
; particular lowering detail in these tests should not be read as requiring
|
|
; that detail for correctness unless it's related to the atomicity itself.
|
|
; (Specifically, there were reviewer questions about the lowering for halfs
|
|
; and their calling convention which remain unresolved.)
|
|
|
|
define void @store_half(half* %fptr, half %v) {
|
|
; CHECK-LABEL: @store_half
|
|
; CHECK: movq %rdi, %rbx
|
|
; CHECK: callq __gnu_f2h_ieee
|
|
; CHECK: movw %ax, (%rbx)
|
|
store atomic half %v, half* %fptr unordered, align 2
|
|
ret void
|
|
}
|
|
|
|
define void @store_float(float* %fptr, float %v) {
|
|
; CHECK-LABEL: @store_float
|
|
; CHECK: movd %xmm0, %eax
|
|
; CHECK: movl %eax, (%rdi)
|
|
store atomic float %v, float* %fptr unordered, align 4
|
|
ret void
|
|
}
|
|
|
|
define void @store_double(double* %fptr, double %v) {
|
|
; CHECK-LABEL: @store_double
|
|
; CHECK: movd %xmm0, %rax
|
|
; CHECK: movq %rax, (%rdi)
|
|
store atomic double %v, double* %fptr unordered, align 8
|
|
ret void
|
|
}
|
|
|
|
define void @store_fp128(fp128* %fptr, fp128 %v) {
|
|
; CHECK-LABEL: @store_fp128
|
|
; CHECK: callq __sync_lock_test_and_set_16
|
|
store atomic fp128 %v, fp128* %fptr unordered, align 16
|
|
ret void
|
|
}
|
|
|
|
define half @load_half(half* %fptr) {
|
|
; CHECK-LABEL: @load_half
|
|
; CHECK: movw (%rdi), %ax
|
|
; CHECK: movzwl %ax, %edi
|
|
; CHECK: jmp __gnu_h2f_ieee
|
|
%v = load atomic half, half* %fptr unordered, align 2
|
|
ret half %v
|
|
}
|
|
|
|
define float @load_float(float* %fptr) {
|
|
; CHECK-LABEL: @load_float
|
|
; CHECK: movl (%rdi), %eax
|
|
; CHECK: movd %eax, %xmm0
|
|
%v = load atomic float, float* %fptr unordered, align 4
|
|
ret float %v
|
|
}
|
|
|
|
define double @load_double(double* %fptr) {
|
|
; CHECK-LABEL: @load_double
|
|
; CHECK: movq (%rdi), %rax
|
|
; CHECK: movd %rax, %xmm0
|
|
%v = load atomic double, double* %fptr unordered, align 8
|
|
ret double %v
|
|
}
|
|
|
|
define fp128 @load_fp128(fp128* %fptr) {
|
|
; CHECK-LABEL: @load_fp128
|
|
; CHECK: callq __sync_val_compare_and_swap_16
|
|
%v = load atomic fp128, fp128* %fptr unordered, align 16
|
|
ret fp128 %v
|
|
}
|
|
|
|
|
|
; sanity check the seq_cst lowering since that's the
|
|
; interesting one from an ordering perspective on x86.
|
|
|
|
define void @store_float_seq_cst(float* %fptr, float %v) {
|
|
; CHECK-LABEL: @store_float_seq_cst
|
|
; CHECK: movd %xmm0, %eax
|
|
; CHECK: xchgl %eax, (%rdi)
|
|
store atomic float %v, float* %fptr seq_cst, align 4
|
|
ret void
|
|
}
|
|
|
|
define void @store_double_seq_cst(double* %fptr, double %v) {
|
|
; CHECK-LABEL: @store_double_seq_cst
|
|
; CHECK: movd %xmm0, %rax
|
|
; CHECK: xchgq %rax, (%rdi)
|
|
store atomic double %v, double* %fptr seq_cst, align 8
|
|
ret void
|
|
}
|
|
|
|
define float @load_float_seq_cst(float* %fptr) {
|
|
; CHECK-LABEL: @load_float_seq_cst
|
|
; CHECK: movl (%rdi), %eax
|
|
; CHECK: movd %eax, %xmm0
|
|
%v = load atomic float, float* %fptr seq_cst, align 4
|
|
ret float %v
|
|
}
|
|
|
|
define double @load_double_seq_cst(double* %fptr) {
|
|
; CHECK-LABEL: @load_double_seq_cst
|
|
; CHECK: movq (%rdi), %rax
|
|
; CHECK: movd %rax, %xmm0
|
|
%v = load atomic double, double* %fptr seq_cst, align 8
|
|
ret double %v
|
|
}
|