Skip to content

Commit 774c8a2

Browse files
authored
Merge pull request #840 from GuillaumeGomez/sqrt-f32-intrinsic
Add missing intrinsic translation for `llvm.sqrt.f32`
2 parents bcb24ce + d3df4bd commit 774c8a2

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/intrinsic/llvm.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,12 @@ pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function
10621062
"llvm.x86.xgetbv" => "__builtin_ia32_xgetbv",
10631063
// NOTE: this doc specifies the equivalent GCC builtins: http://huonw.github.io/llvmint/llvmint/x86/index.html
10641064
"llvm.sqrt.v2f64" => "__builtin_ia32_sqrtpd",
1065+
"llvm.sqrt.f32" => {
1066+
let gcc_name = "__builtin_sqrtf";
1067+
let func = cx.context.get_builtin_function(gcc_name);
1068+
cx.functions.borrow_mut().insert(gcc_name.to_string(), func);
1069+
return func;
1070+
}
10651071
"llvm.x86.avx512.pmul.dq.512" => "__builtin_ia32_pmuldq512_mask",
10661072
"llvm.x86.avx512.pmulu.dq.512" => "__builtin_ia32_pmuludq512_mask",
10671073
"llvm.x86.avx512.max.ps.512" => "__builtin_ia32_maxps512_mask",

tests/run/call-llvm-intrinsics.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Compiler:
2+
//
3+
// Run-time:
4+
// status: 0
5+
6+
// FIXME: Remove this test once rustc's `./tests/codegen/riscv-abi/call-llvm-intrinsics.rs`
7+
// stops ignoring GCC backend.
8+
9+
#![feature(link_llvm_intrinsics)]
10+
#![allow(internal_features)]
11+
12+
struct A;
13+
14+
impl Drop for A {
15+
fn drop(&mut self) {
16+
println!("A");
17+
}
18+
}
19+
20+
extern "C" {
21+
#[link_name = "llvm.sqrt.f32"]
22+
fn sqrt(x: f32) -> f32;
23+
}
24+
25+
pub fn do_call() {
26+
let _a = A;
27+
28+
unsafe {
29+
// Ensure that we `call` LLVM intrinsics instead of trying to `invoke` them
30+
// CHECK: store float 4.000000e+00, float* %{{.}}, align 4
31+
// CHECK: call float @llvm.sqrt.f32(float %{{.}}
32+
sqrt(4.0);
33+
}
34+
}
35+
36+
fn main() {
37+
do_call();
38+
}

0 commit comments

Comments
 (0)