[llvm] [Instrumentation][nsan] Intrinsic tests + bugfixes (PR #186803)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 16 06:55:55 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Lewis Crawford (LewisCrawford)
<details>
<summary>Changes</summary>
Add comprehensive lit-test coverage to the NumericalStabilitySanitizer's intrinsic and libfunc handling.
Also, several minor bugfixes:
- Fix typo in llvm.nearbyint.f80's name.
- Remove lround and llround intrinsics, since they return ints (and are not instrumented by nsan as a result).
- Add missing fmuladd.f80 variant.
---
Patch is 177.42 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/186803.diff
4 Files Affected:
- (modified) llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp (+4-19)
- (modified) llvm/test/Instrumentation/NumericalStabilitySanitizer/basic.ll (-74)
- (added) llvm/test/Instrumentation/NumericalStabilitySanitizer/intrinsics.ll (+1807)
- (added) llvm/test/Instrumentation/NumericalStabilitySanitizer/libfuncs.ll (+1430)
``````````diff
diff --git a/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
index f9ef67923ed48..70b69c6a341c0 100644
--- a/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
@@ -1398,14 +1398,11 @@ const KnownIntrinsic::WidenedIntrinsic KnownIntrinsic::kWidenedIntrinsics[] = {
{"llvm.log2.f64", Intrinsic::log2, makeX86FP80X86FP80},
{"llvm.log2.f80", Intrinsic::log2, makeX86FP80X86FP80},
{"llvm.fma.f32", Intrinsic::fma, makeDoubleDoubleDoubleDouble},
-
- {"llvm.fmuladd.f32", Intrinsic::fmuladd, makeDoubleDoubleDoubleDouble},
-
{"llvm.fma.f64", Intrinsic::fma, makeX86FP80X86FP80X86FP80X86FP80},
-
- {"llvm.fmuladd.f64", Intrinsic::fma, makeX86FP80X86FP80X86FP80X86FP80},
-
{"llvm.fma.f80", Intrinsic::fma, makeX86FP80X86FP80X86FP80X86FP80},
+ {"llvm.fmuladd.f32", Intrinsic::fmuladd, makeDoubleDoubleDoubleDouble},
+ {"llvm.fmuladd.f64", Intrinsic::fma, makeX86FP80X86FP80X86FP80X86FP80},
+ {"llvm.fmuladd.f80", Intrinsic::fma, makeX86FP80X86FP80X86FP80X86FP80},
{"llvm.fabs.f32", Intrinsic::fabs, makeDoubleDouble},
{"llvm.fabs.f64", Intrinsic::fabs, makeX86FP80X86FP80},
{"llvm.fabs.f80", Intrinsic::fabs, makeX86FP80X86FP80},
@@ -1438,22 +1435,10 @@ const KnownIntrinsic::WidenedIntrinsic KnownIntrinsic::kWidenedIntrinsics[] = {
{"llvm.rint.f80", Intrinsic::rint, makeX86FP80X86FP80},
{"llvm.nearbyint.f32", Intrinsic::nearbyint, makeDoubleDouble},
{"llvm.nearbyint.f64", Intrinsic::nearbyint, makeX86FP80X86FP80},
- {"llvm.nearbyin80f64", Intrinsic::nearbyint, makeX86FP80X86FP80},
+ {"llvm.nearbyint.f80", Intrinsic::nearbyint, makeX86FP80X86FP80},
{"llvm.round.f32", Intrinsic::round, makeDoubleDouble},
{"llvm.round.f64", Intrinsic::round, makeX86FP80X86FP80},
{"llvm.round.f80", Intrinsic::round, makeX86FP80X86FP80},
- {"llvm.lround.f32", Intrinsic::lround, makeDoubleDouble},
- {"llvm.lround.f64", Intrinsic::lround, makeX86FP80X86FP80},
- {"llvm.lround.f80", Intrinsic::lround, makeX86FP80X86FP80},
- {"llvm.llround.f32", Intrinsic::llround, makeDoubleDouble},
- {"llvm.llround.f64", Intrinsic::llround, makeX86FP80X86FP80},
- {"llvm.llround.f80", Intrinsic::llround, makeX86FP80X86FP80},
- {"llvm.lrint.f32", Intrinsic::lrint, makeDoubleDouble},
- {"llvm.lrint.f64", Intrinsic::lrint, makeX86FP80X86FP80},
- {"llvm.lrint.f80", Intrinsic::lrint, makeX86FP80X86FP80},
- {"llvm.llrint.f32", Intrinsic::llrint, makeDoubleDouble},
- {"llvm.llrint.f64", Intrinsic::llrint, makeX86FP80X86FP80},
- {"llvm.llrint.f80", Intrinsic::llrint, makeX86FP80X86FP80},
};
const KnownIntrinsic::LFEntry KnownIntrinsic::kLibfuncIntrinsics[] = {
diff --git a/llvm/test/Instrumentation/NumericalStabilitySanitizer/basic.ll b/llvm/test/Instrumentation/NumericalStabilitySanitizer/basic.ll
index 304508d9f86c4..a27e3318c59e8 100644
--- a/llvm/test/Instrumentation/NumericalStabilitySanitizer/basic.ll
+++ b/llvm/test/Instrumentation/NumericalStabilitySanitizer/basic.ll
@@ -503,80 +503,6 @@ entry:
ret void
}
-declare float @llvm.sin.f32(float) readnone
-
-define float @call_sin_intrinsic() sanitize_numerical_stability {
-; CHECK-LABEL: @call_sin_intrinsic(
-; CHECK-NEXT: entry:
-; CHECK-NEXT: [[R:%.*]] = call float @llvm.sin.f32(float 1.000000e+00)
-; CHECK-NEXT: [[TMP0:%.*]] = call double @llvm.sin.f64(double 1.000000e+00)
-; CHECK-NEXT: [[TMP1:%.*]] = call i32 @__nsan_internal_check_float_d(float [[R]], double [[TMP0]], i32 1, i64 0)
-; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 1
-; CHECK-NEXT: [[TMP3:%.*]] = fpext float [[R]] to double
-; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP2]], double [[TMP3]], double [[TMP0]]
-; CHECK-NEXT: store i64 ptrtoint (ptr @call_sin_intrinsic to i64), ptr @__nsan_shadow_ret_tag, align 8
-; CHECK-NEXT: store double [[TMP4]], ptr @__nsan_shadow_ret_ptr, align 8
-; CHECK-NEXT: ret float [[R]]
-;
-entry:
- %r = call float @llvm.sin.f32(float 1.0)
- ret float %r
-}
-
-declare float @sinf(float)
-
-define float @call_sinf_libfunc() sanitize_numerical_stability {
-; CHECK-LABEL: @call_sinf_libfunc(
-; CHECK-NEXT: entry:
-; CHECK-NEXT: [[R:%.*]] = call float @sinf(float 1.000000e+00) #[[ATTR3:[0-9]+]]
-; CHECK-NEXT: [[TMP0:%.*]] = call double @llvm.sin.f64(double 1.000000e+00)
-; CHECK-NEXT: [[TMP1:%.*]] = call i32 @__nsan_internal_check_float_d(float [[R]], double [[TMP0]], i32 1, i64 0)
-; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 1
-; CHECK-NEXT: [[TMP3:%.*]] = fpext float [[R]] to double
-; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP2]], double [[TMP3]], double [[TMP0]]
-; CHECK-NEXT: store i64 ptrtoint (ptr @call_sinf_libfunc to i64), ptr @__nsan_shadow_ret_tag, align 8
-; CHECK-NEXT: store double [[TMP4]], ptr @__nsan_shadow_ret_ptr, align 8
-; CHECK-NEXT: ret float [[R]]
-;
-entry:
- %r = call float @sinf(float 1.0)
- ret float %r
-}
-
-declare double @sin(double)
-
-; FIXME: nsan uses `sin(double)` for fp128.
-define double @call_sin_libfunc() sanitize_numerical_stability {
-; DQQ-LABEL: @call_sin_libfunc(
-; DQQ-NEXT: entry:
-; DQQ-NEXT: [[R:%.*]] = call double @sin(double 1.000000e+00) #[[ATTR3]]
-; DQQ-NEXT: [[TMP0:%.*]] = call x86_fp80 @llvm.sin.f80(x86_fp80 0xK3FFF8000000000000000)
-; DQQ-NEXT: [[TMP1:%.*]] = fpext x86_fp80 [[TMP0]] to fp128
-; DQQ-NEXT: [[TMP2:%.*]] = call i32 @__nsan_internal_check_double_q(double [[R]], fp128 [[TMP1]], i32 1, i64 0)
-; DQQ-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP2]], 1
-; DQQ-NEXT: [[TMP4:%.*]] = fpext double [[R]] to fp128
-; DQQ-NEXT: [[TMP5:%.*]] = select i1 [[TMP3]], fp128 [[TMP4]], fp128 [[TMP1]]
-; DQQ-NEXT: store i64 ptrtoint (ptr @call_sin_libfunc to i64), ptr @__nsan_shadow_ret_tag, align 8
-; DQQ-NEXT: store fp128 [[TMP5]], ptr @__nsan_shadow_ret_ptr, align 16
-; DQQ-NEXT: ret double [[R]]
-;
-; DLQ-LABEL: @call_sin_libfunc(
-; DLQ-NEXT: entry:
-; DLQ-NEXT: [[R:%.*]] = call double @sin(double 1.000000e+00) #[[ATTR3]]
-; DLQ-NEXT: [[TMP0:%.*]] = call x86_fp80 @llvm.sin.f80(x86_fp80 0xK3FFF8000000000000000)
-; DLQ-NEXT: [[TMP1:%.*]] = call i32 @__nsan_internal_check_double_l(double [[R]], x86_fp80 [[TMP0]], i32 1, i64 0)
-; DLQ-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 1
-; DLQ-NEXT: [[TMP3:%.*]] = fpext double [[R]] to x86_fp80
-; DLQ-NEXT: [[TMP4:%.*]] = select i1 [[TMP2]], x86_fp80 [[TMP3]], x86_fp80 [[TMP0]]
-; DLQ-NEXT: store i64 ptrtoint (ptr @call_sin_libfunc to i64), ptr @__nsan_shadow_ret_tag, align 8
-; DLQ-NEXT: store x86_fp80 [[TMP4]], ptr @__nsan_shadow_ret_ptr, align 16
-; DLQ-NEXT: ret double [[R]]
-;
-entry:
- %r = call double @sin(double 1.0)
- ret double %r
-}
-
declare double @frexp(double, i32*)
define double @call_frexp_libfunc_nointrinsic(double %0, i32* nocapture %1) sanitize_numerical_stability {
diff --git a/llvm/test/Instrumentation/NumericalStabilitySanitizer/intrinsics.ll b/llvm/test/Instrumentation/NumericalStabilitySanitizer/intrinsics.ll
new file mode 100644
index 0000000000000..d6888244e3950
--- /dev/null
+++ b/llvm/test/Instrumentation/NumericalStabilitySanitizer/intrinsics.ll
@@ -0,0 +1,1807 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=nsan -nsan-shadow-type-mapping=dqq -nsan-truncate-fcmp-eq=false -S %s | FileCheck %s --check-prefixes=CHECK,DQQ
+; RUN: opt -passes=nsan -nsan-shadow-type-mapping=dlq -nsan-truncate-fcmp-eq=false -S %s | FileCheck %s --check-prefixes=CHECK,DLQ
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+
+;###############################################################
+;# sqrt #
+;###############################################################
+declare float @llvm.sqrt.f32(float) readnone
+declare double @llvm.sqrt.f64(double) readnone
+declare x86_fp80 @llvm.sqrt.f80(x86_fp80) readnone
+
+define float @call_sqrt_f32() sanitize_numerical_stability {
+; CHECK-LABEL: @call_sqrt_f32(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.sqrt.f32(float 4.000000e+00)
+; CHECK-NEXT: [[TMP0:%.*]] = call double @llvm.sqrt.f64(double 4.000000e+00)
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @__nsan_internal_check_float_d(float [[R]], double [[TMP0]], i32 1, i64 0)
+; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 1
+; CHECK-NEXT: [[TMP3:%.*]] = fpext float [[R]] to double
+; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP2]], double [[TMP3]], double [[TMP0]]
+; CHECK-NEXT: store i64 ptrtoint (ptr @call_sqrt_f32 to i64), ptr @__nsan_shadow_ret_tag, align 8
+; CHECK-NEXT: store double [[TMP4]], ptr @__nsan_shadow_ret_ptr, align 8
+; CHECK-NEXT: ret float [[R]]
+;
+entry:
+ %r = call float @llvm.sqrt.f32(float 4.0)
+ ret float %r
+}
+
+define double @call_sqrt_f64() sanitize_numerical_stability {
+; DQQ-LABEL: @call_sqrt_f64(
+; DQQ-NEXT: entry:
+; DQQ-NEXT: [[R:%.*]] = call double @llvm.sqrt.f64(double 4.000000e+00)
+; DQQ-NEXT: [[TMP0:%.*]] = call x86_fp80 @llvm.sqrt.f80(x86_fp80 0xK40018000000000000000)
+; DQQ-NEXT: [[TMP1:%.*]] = fpext x86_fp80 [[TMP0]] to fp128
+; DQQ-NEXT: [[TMP2:%.*]] = call i32 @__nsan_internal_check_double_q(double [[R]], fp128 [[TMP1]], i32 1, i64 0)
+; DQQ-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP2]], 1
+; DQQ-NEXT: [[TMP4:%.*]] = fpext double [[R]] to fp128
+; DQQ-NEXT: [[TMP5:%.*]] = select i1 [[TMP3]], fp128 [[TMP4]], fp128 [[TMP1]]
+; DQQ-NEXT: store i64 ptrtoint (ptr @call_sqrt_f64 to i64), ptr @__nsan_shadow_ret_tag, align 8
+; DQQ-NEXT: store fp128 [[TMP5]], ptr @__nsan_shadow_ret_ptr, align 16
+; DQQ-NEXT: ret double [[R]]
+;
+; DLQ-LABEL: @call_sqrt_f64(
+; DLQ-NEXT: entry:
+; DLQ-NEXT: [[R:%.*]] = call double @llvm.sqrt.f64(double 4.000000e+00)
+; DLQ-NEXT: [[TMP0:%.*]] = call x86_fp80 @llvm.sqrt.f80(x86_fp80 0xK40018000000000000000)
+; DLQ-NEXT: [[TMP1:%.*]] = call i32 @__nsan_internal_check_double_l(double [[R]], x86_fp80 [[TMP0]], i32 1, i64 0)
+; DLQ-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 1
+; DLQ-NEXT: [[TMP3:%.*]] = fpext double [[R]] to x86_fp80
+; DLQ-NEXT: [[TMP4:%.*]] = select i1 [[TMP2]], x86_fp80 [[TMP3]], x86_fp80 [[TMP0]]
+; DLQ-NEXT: store i64 ptrtoint (ptr @call_sqrt_f64 to i64), ptr @__nsan_shadow_ret_tag, align 8
+; DLQ-NEXT: store x86_fp80 [[TMP4]], ptr @__nsan_shadow_ret_ptr, align 16
+; DLQ-NEXT: ret double [[R]]
+;
+entry:
+ %r = call double @llvm.sqrt.f64(double 4.0)
+ ret double %r
+}
+
+define x86_fp80 @call_sqrt_f80() sanitize_numerical_stability {
+; CHECK-LABEL: @call_sqrt_f80(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[R:%.*]] = call x86_fp80 @llvm.sqrt.f80(x86_fp80 0xK40018000000000000000)
+; CHECK-NEXT: [[TMP0:%.*]] = call x86_fp80 @llvm.sqrt.f80(x86_fp80 0xK40018000000000000000)
+; CHECK-NEXT: [[TMP1:%.*]] = fpext x86_fp80 [[TMP0]] to fp128
+; CHECK-NEXT: [[TMP2:%.*]] = call i32 @__nsan_internal_check_longdouble_q(x86_fp80 [[R]], fp128 [[TMP1]], i32 1, i64 0)
+; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP2]], 1
+; CHECK-NEXT: [[TMP4:%.*]] = fpext x86_fp80 [[R]] to fp128
+; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP3]], fp128 [[TMP4]], fp128 [[TMP1]]
+; CHECK-NEXT: store i64 ptrtoint (ptr @call_sqrt_f80 to i64), ptr @__nsan_shadow_ret_tag, align 8
+; CHECK-NEXT: store fp128 [[TMP5]], ptr @__nsan_shadow_ret_ptr, align 16
+; CHECK-NEXT: ret x86_fp80 [[R]]
+;
+entry:
+ %r = call x86_fp80 @llvm.sqrt.f80(x86_fp80 0xK40018000000000000000)
+ ret x86_fp80 %r
+}
+
+;###############################################################
+;# powi #
+;###############################################################
+declare float @llvm.powi.f32(float, i32) readnone
+declare double @llvm.powi.f64(double, i32) readnone
+declare x86_fp80 @llvm.powi.f80(x86_fp80, i32) readnone
+
+define float @call_powi_f32() sanitize_numerical_stability {
+; CHECK-LABEL: @call_powi_f32(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.powi.f32.i32(float 2.000000e+00, i32 3)
+; CHECK-NEXT: [[TMP0:%.*]] = call float @llvm.powi.f32.i32(float 2.000000e+00, i32 3)
+; CHECK-NEXT: [[TMP1:%.*]] = fpext float [[TMP0]] to double
+; CHECK-NEXT: [[TMP2:%.*]] = call i32 @__nsan_internal_check_float_d(float [[R]], double [[TMP1]], i32 1, i64 0)
+; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP2]], 1
+; CHECK-NEXT: [[TMP4:%.*]] = fpext float [[R]] to double
+; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP3]], double [[TMP4]], double [[TMP1]]
+; CHECK-NEXT: store i64 ptrtoint (ptr @call_powi_f32 to i64), ptr @__nsan_shadow_ret_tag, align 8
+; CHECK-NEXT: store double [[TMP5]], ptr @__nsan_shadow_ret_ptr, align 8
+; CHECK-NEXT: ret float [[R]]
+;
+entry:
+ %r = call float @llvm.powi.f32(float 2.0, i32 3)
+ ret float %r
+}
+
+define double @call_powi_f64() sanitize_numerical_stability {
+; DQQ-LABEL: @call_powi_f64(
+; DQQ-NEXT: entry:
+; DQQ-NEXT: [[R:%.*]] = call double @llvm.powi.f64.i32(double 2.000000e+00, i32 3)
+; DQQ-NEXT: [[TMP0:%.*]] = call double @llvm.powi.f64.i32(double 2.000000e+00, i32 3)
+; DQQ-NEXT: [[TMP1:%.*]] = fpext double [[TMP0]] to fp128
+; DQQ-NEXT: [[TMP2:%.*]] = call i32 @__nsan_internal_check_double_q(double [[R]], fp128 [[TMP1]], i32 1, i64 0)
+; DQQ-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP2]], 1
+; DQQ-NEXT: [[TMP4:%.*]] = fpext double [[R]] to fp128
+; DQQ-NEXT: [[TMP5:%.*]] = select i1 [[TMP3]], fp128 [[TMP4]], fp128 [[TMP1]]
+; DQQ-NEXT: store i64 ptrtoint (ptr @call_powi_f64 to i64), ptr @__nsan_shadow_ret_tag, align 8
+; DQQ-NEXT: store fp128 [[TMP5]], ptr @__nsan_shadow_ret_ptr, align 16
+; DQQ-NEXT: ret double [[R]]
+;
+; DLQ-LABEL: @call_powi_f64(
+; DLQ-NEXT: entry:
+; DLQ-NEXT: [[R:%.*]] = call double @llvm.powi.f64.i32(double 2.000000e+00, i32 3)
+; DLQ-NEXT: [[TMP0:%.*]] = call double @llvm.powi.f64.i32(double 2.000000e+00, i32 3)
+; DLQ-NEXT: [[TMP1:%.*]] = fpext double [[TMP0]] to x86_fp80
+; DLQ-NEXT: [[TMP2:%.*]] = call i32 @__nsan_internal_check_double_l(double [[R]], x86_fp80 [[TMP1]], i32 1, i64 0)
+; DLQ-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP2]], 1
+; DLQ-NEXT: [[TMP4:%.*]] = fpext double [[R]] to x86_fp80
+; DLQ-NEXT: [[TMP5:%.*]] = select i1 [[TMP3]], x86_fp80 [[TMP4]], x86_fp80 [[TMP1]]
+; DLQ-NEXT: store i64 ptrtoint (ptr @call_powi_f64 to i64), ptr @__nsan_shadow_ret_tag, align 8
+; DLQ-NEXT: store x86_fp80 [[TMP5]], ptr @__nsan_shadow_ret_ptr, align 16
+; DLQ-NEXT: ret double [[R]]
+;
+entry:
+ %r = call double @llvm.powi.f64(double 2.0, i32 3)
+ ret double %r
+}
+
+define x86_fp80 @call_powi_f80() sanitize_numerical_stability {
+; CHECK-LABEL: @call_powi_f80(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[R:%.*]] = call x86_fp80 @llvm.powi.f80.i32(x86_fp80 0xK40008000000000000000, i32 3)
+; CHECK-NEXT: [[TMP0:%.*]] = call x86_fp80 @llvm.powi.f80.i32(x86_fp80 0xK40008000000000000000, i32 3)
+; CHECK-NEXT: [[TMP1:%.*]] = fpext x86_fp80 [[TMP0]] to fp128
+; CHECK-NEXT: [[TMP2:%.*]] = call i32 @__nsan_internal_check_longdouble_q(x86_fp80 [[R]], fp128 [[TMP1]], i32 1, i64 0)
+; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP2]], 1
+; CHECK-NEXT: [[TMP4:%.*]] = fpext x86_fp80 [[R]] to fp128
+; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP3]], fp128 [[TMP4]], fp128 [[TMP1]]
+; CHECK-NEXT: store i64 ptrtoint (ptr @call_powi_f80 to i64), ptr @__nsan_shadow_ret_tag, align 8
+; CHECK-NEXT: store fp128 [[TMP5]], ptr @__nsan_shadow_ret_ptr, align 16
+; CHECK-NEXT: ret x86_fp80 [[R]]
+;
+entry:
+ %r = call x86_fp80 @llvm.powi.f80(x86_fp80 0xK40008000000000000000, i32 3)
+ ret x86_fp80 %r
+}
+
+;###############################################################
+;# sin #
+;###############################################################
+declare float @llvm.sin.f32(float) readnone
+declare double @llvm.sin.f64(double) readnone
+declare x86_fp80 @llvm.sin.f80(x86_fp80) readnone
+
+define float @call_sin_f32() sanitize_numerical_stability {
+; CHECK-LABEL: @call_sin_f32(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.sin.f32(float 1.000000e+00)
+; CHECK-NEXT: [[TMP0:%.*]] = call double @llvm.sin.f64(double 1.000000e+00)
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @__nsan_internal_check_float_d(float [[R]], double [[TMP0]], i32 1, i64 0)
+; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 1
+; CHECK-NEXT: [[TMP3:%.*]] = fpext float [[R]] to double
+; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP2]], double [[TMP3]], double [[TMP0]]
+; CHECK-NEXT: store i64 ptrtoint (ptr @call_sin_f32 to i64), ptr @__nsan_shadow_ret_tag, align 8
+; CHECK-NEXT: store double [[TMP4]], ptr @__nsan_shadow_ret_ptr, align 8
+; CHECK-NEXT: ret float [[R]]
+;
+entry:
+ %r = call float @llvm.sin.f32(float 1.0)
+ ret float %r
+}
+
+define double @call_sin_f64() sanitize_numerical_stability {
+; DQQ-LABEL: @call_sin_f64(
+; DQQ-NEXT: entry:
+; DQQ-NEXT: [[R:%.*]] = call double @llvm.sin.f64(double 1.000000e+00)
+; DQQ-NEXT: [[TMP0:%.*]] = call x86_fp80 @llvm.sin.f80(x86_fp80 0xK3FFF8000000000000000)
+; DQQ-NEXT: [[TMP1:%.*]] = fpext x86_fp80 [[TMP0]] to fp128
+; DQQ-NEXT: [[TMP2:%.*]] = call i32 @__nsan_internal_check_double_q(double [[R]], fp128 [[TMP1]], i32 1, i64 0)
+; DQQ-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP2]], 1
+; DQQ-NEXT: [[TMP4:%.*]] = fpext double [[R]] to fp128
+; DQQ-NEXT: [[TMP5:%.*]] = select i1 [[TMP3]], fp128 [[TMP4]], fp128 [[TMP1]]
+; DQQ-NEXT: store i64 ptrtoint (ptr @call_sin_f64 to i64), ptr @__nsan_shadow_ret_tag, align 8
+; DQQ-NEXT: store fp128 [[TMP5]], ptr @__nsan_shadow_ret_ptr, align 16
+; DQQ-NEXT: ret double [[R]]
+;
+; DLQ-LABEL: @call_sin_f64(
+; DLQ-NEXT: entry:
+; DLQ-NEXT: [[R:%.*]] = call double @llvm.sin.f64(double 1.000000e+00)
+; DLQ-NEXT: [[TMP0:%.*]] = call x86_fp80 @llvm.sin.f80(x86_fp80 0xK3FFF8000000000000000)
+; DLQ-NEXT: [[TMP1:%.*]] = call i32 @__nsan_internal_check_double_l(double [[R]], x86_fp80 [[TMP0]], i32 1, i64 0)
+; DLQ-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 1
+; DLQ-NEXT: [[TMP3:%.*]] = fpext double [[R]] to x86_fp80
+; DLQ-NEXT: [[TMP4:%.*]] = select i1 [[TMP2]], x86_fp80 [[TMP3]], x86_fp80 [[TMP0]]
+; DLQ-NEXT: store i64 ptrtoint (ptr @call_sin_f64 to i64), ptr @__nsan_shadow_ret_tag, align 8
+; DLQ-NEXT: store x86_fp80 [[TMP4]], ptr @__nsan_shadow_ret_ptr, align 16
+; DLQ-NEXT: ret double [[R]]
+;
+entry:
+ %r = call double @llvm.sin.f64(double 1.0)
+ ret double %r
+}
+
+define x86_fp80 @call_sin_f80() sanitize_numerical_stability {
+; CHECK-LABEL: @call_sin_f80(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[R:%.*]] = call x86_fp80 @llvm.sin.f80(x86_fp80 0xK3FFF8000000000000000)
+; CHECK-NEXT: [[TMP0:%.*]] = call x86_fp80 @llvm.sin.f80(x86_fp80 0xK3FFF8000000000000000)
+; CHECK-NEXT: [[TMP1:%.*]] = fpext x86_fp80 [[TMP0]] to fp128
+; CHECK-NEXT: [[TMP2:%.*]] = call i32 @__nsan_internal_check_longdouble_q(x86_fp80 [[R]], fp128 [[TMP1]], i32 1, i64 0)
+; CHECK-NEXT: [[TMP3:%.*]] = icmp eq i32 [[TMP2]], 1
+; CHECK-NEXT: [[TMP4:%.*]] = fpext x86_fp80 [[R]] to fp128
+; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP3]], fp128 [[TMP4]], fp128 [[TMP1]]
+; CHECK-NEXT: store i64 ptrtoint (ptr @call_sin_f80 to i64), ptr @__nsan_shadow_ret_tag, align 8
+; CHECK-NEXT: store fp128 [[TMP5]], ptr @__nsan_shadow_ret_ptr, align 16
+; CHECK-NEXT: ret x86_fp80 [[R]]
+;
+entry:
+ %r = call x86_fp80 @llvm.sin.f80(x86_fp80 0xK3FFF8000000000000000)
+ ret x86_fp80 %r
+}
+
+;###############################################################
+;# cos #
+;###############################################################
+declare float @llvm.cos.f32(float) readnone
+declare double @llvm.cos.f64(double) readnone
+declare x86_fp80 @llvm.cos.f80(x86_fp80) readnone
+
+define float @call_cos_f32() sanitize_numerical_stability {
+; CHECK-LABEL: @call_cos_f32(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.cos.f32(float 1.000000e+00)
+; CHECK-NEXT: [[TMP0:%....
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/186803
More information about the llvm-commits
mailing list