Skip to content

Commit 7e3495f

Browse files
committed
RFC: Remove sqrt_llvm intrinsic
This is more of a "Do we want to move in this direction RFC". As mentioned in #43786, we currently have three implementations of these intrinsics: 1. The code generated by LLVM for the intrinsic 2. The code LLVM uses for constant folding the intrinsic 3. Our own runtime intrinsic used by the interpreter This basically removes the third one, which will be required if we want to do something about #26434 because we just forward these to libm. Of course we'll still have to do something to teach LLVM how to constant fold these in a manner compatible with what will actually end up running, but that's a separate issue.
1 parent 8ec5580 commit 7e3495f

File tree

7 files changed

+2
-12
lines changed

7 files changed

+2
-12
lines changed

base/compiler/optimize.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,6 @@ function is_pure_intrinsic_infer(f::IntrinsicFunction)
618618
f === Intrinsics.pointerset || # this one is never effect-free
619619
f === Intrinsics.llvmcall || # this one is never effect-free
620620
f === Intrinsics.arraylen || # this one is volatile
621-
f === Intrinsics.sqrt_llvm || # this one may differ at runtime (by a few ulps)
622621
f === Intrinsics.sqrt_llvm_fast || # this one may differ at runtime (by a few ulps)
623622
f === Intrinsics.have_fma || # this one depends on the runtime environment
624623
f === Intrinsics.cglobal) # cglobal lookup answer changes at runtime

base/compiler/tfuncs.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ add_tfunc(ceil_llvm, 1, 1, math_tfunc, 10)
167167
add_tfunc(floor_llvm, 1, 1, math_tfunc, 10)
168168
add_tfunc(trunc_llvm, 1, 1, math_tfunc, 10)
169169
add_tfunc(rint_llvm, 1, 1, math_tfunc, 10)
170-
add_tfunc(sqrt_llvm, 1, 1, math_tfunc, 20)
171170
add_tfunc(sqrt_llvm_fast, 1, 1, math_tfunc, 20)
172171
## same-type comparisons ##
173172
cmp_tfunc(@nospecialize(x), @nospecialize(y)) = Bool

base/math.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ using .Base: sign_mask, exponent_mask, exponent_one,
2525
significand_bits, exponent_bits, exponent_bias,
2626
exponent_max, exponent_raw_max
2727

28-
using Core.Intrinsics: sqrt_llvm
29-
3028
using .Base: IEEEFloat
3129

3230
@noinline function throw_complex_domainerror(f::Symbol, x)
@@ -586,6 +584,8 @@ Stacktrace:
586584
"""
587585
log1p(x)
588586

587+
sqrt_llvm(x::Float32) = ccall("llvm.sqrt.f32", llvmcall, Float32, (Float32,), x)
588+
sqrt_llvm(x::Float64) = ccall("llvm.sqrt.f64", llvmcall, Float64, (Float64,), x)
589589
@inline function sqrt(x::Union{Float32,Float64})
590590
x < zero(x) && throw_complex_domainerror(:sqrt, x)
591591
sqrt_llvm(x)

src/intrinsics.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ static void jl_init_intrinsic_functions_codegen(void)
6565
float_func[floor_llvm] = true;
6666
float_func[trunc_llvm] = true;
6767
float_func[rint_llvm] = true;
68-
float_func[sqrt_llvm] = true;
6968
float_func[sqrt_llvm_fast] = true;
7069
}
7170

@@ -1485,10 +1484,6 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, Value **arg
14851484
FunctionCallee rintintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::rint, makeArrayRef(t));
14861485
return ctx.builder.CreateCall(rintintr, x);
14871486
}
1488-
case sqrt_llvm: {
1489-
FunctionCallee sqrtintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::sqrt, makeArrayRef(t));
1490-
return ctx.builder.CreateCall(sqrtintr, x);
1491-
}
14921487
case sqrt_llvm_fast: {
14931488
FunctionCallee sqrtintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::sqrt, makeArrayRef(t));
14941489
return math_builder(ctx, true)().CreateCall(sqrtintr, x);

src/intrinsics.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
ADD_I(floor_llvm, 1) \
8787
ADD_I(trunc_llvm, 1) \
8888
ADD_I(rint_llvm, 1) \
89-
ADD_I(sqrt_llvm, 1) \
9089
ADD_I(sqrt_llvm_fast, 1) \
9190
/* pointer access */ \
9291
ADD_I(pointerref, 3) \

src/julia_internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,6 @@ JL_DLLEXPORT jl_value_t *jl_ceil_llvm(jl_value_t *a);
12331233
JL_DLLEXPORT jl_value_t *jl_floor_llvm(jl_value_t *a);
12341234
JL_DLLEXPORT jl_value_t *jl_trunc_llvm(jl_value_t *a);
12351235
JL_DLLEXPORT jl_value_t *jl_rint_llvm(jl_value_t *a);
1236-
JL_DLLEXPORT jl_value_t *jl_sqrt_llvm(jl_value_t *a);
12371236
JL_DLLEXPORT jl_value_t *jl_sqrt_llvm_fast(jl_value_t *a);
12381237
JL_DLLEXPORT jl_value_t *jl_abs_float(jl_value_t *a);
12391238
JL_DLLEXPORT jl_value_t *jl_copysign_float(jl_value_t *a, jl_value_t *b);

src/runtime_intrinsics.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,6 @@ un_fintrinsic(ceil_float,ceil_llvm)
14451445
un_fintrinsic(floor_float,floor_llvm)
14461446
un_fintrinsic(trunc_float,trunc_llvm)
14471447
un_fintrinsic(rint_float,rint_llvm)
1448-
un_fintrinsic(sqrt_float,sqrt_llvm)
14491448
un_fintrinsic(sqrt_float,sqrt_llvm_fast)
14501449

14511450
JL_DLLEXPORT jl_value_t *jl_arraylen(jl_value_t *a)

0 commit comments

Comments
 (0)