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