| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 
 | ; RUN: opt < %s -passes=libcalls-shrinkwrap -S | FileCheck %s
; #include <math.h>
; #include <fenv.h>
; #include <stdlib.h>
;
; void() {
;   volatile double d;
;   d = __builtin_nan ("");
;   feclearexcept (FE_ALL_EXCEPT);
;   acos(d);
;   if (fetestexcept (FE_ALL_EXCEPT))  // expect no fp exception raised
;     abort();
; }
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define void @test_quiet_nan() {
  %1 = alloca double, align 8
  store volatile double 0x7FF8000000000000, ptr %1, align 8
  %2 = tail call i32 @feclearexcept(i32 noundef 61)
  %3 = load volatile double, ptr %1, align 8
  %4 = call double @acos(double noundef %3)
; CHECK: [[COND1:%[0-9]+]] = fcmp ogt double [[VALUE:%.*]], 1.000000e+00
; CHECK: [[COND1:%[0-9]+]] = fcmp olt double [[VALUE]], -1.000000e+00
  %5 = call i32 @fetestexcept(i32 noundef 61)
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %abort, label %ret
abort:
  call void @abort()
  unreachable
ret:
  ret void
}
define void @test_quiet_nan_strictfp() strictfp {
  %1 = alloca double, align 8
  store volatile double 0x7FF8000000000000, ptr %1, align 8
  %2 = tail call i32 @feclearexcept(i32 noundef 61) strictfp
  %3 = load volatile double, ptr %1, align 8
  %4 = call double @acos(double noundef %3) strictfp
; Generate constrained fcmp if function has strictfp attribute.
; That avoids raising fp exception with quiet nan input.
; CHECK: [[COND1:%[0-9]+]] = call i1 @llvm.experimental.constrained.fcmp.f64(double [[VALUE]], double 1.000000e+00, metadata !"ogt", metadata !"fpexcept.strict")
; CHECK: [[COND1:%[0-9]+]] = call i1 @llvm.experimental.constrained.fcmp.f64(double [[VALUE]], double -1.000000e+00, metadata !"olt", metadata !"fpexcept.strict")
  %5 = call i32 @fetestexcept(i32 noundef 61) strictfp
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %abort, label %ret
abort:
  call void @abort() strictfp
  unreachable
ret:
  ret void
}
declare i32 @feclearexcept(i32 noundef)
declare i32 @fetestexcept(i32 noundef)
declare double @acos(double noundef)
declare void @abort()
 |