1; RUN: opt -S -instcombine < %s | FileCheck %s
2
3declare float @llvm.fma.f32(float, float, float) #0
4declare float @llvm.fmuladd.f32(float, float, float) #0
5declare <4 x float> @llvm.fma.v4f32(<4 x float>, <4 x float>, <4 x float>) #0
6
7declare double @llvm.fma.f64(double, double, double) #0
8declare double @llvm.fmuladd.f64(double, double, double) #0
9
10declare double @llvm.sqrt.f64(double) #0
11
12
13; CHECK-LABEL: @constant_fold_fma_f32
14; CHECK-NEXT: ret float 6.000000e+00
15define float @constant_fold_fma_f32() #0 {
16  %x = call float @llvm.fma.f32(float 1.0, float 2.0, float 4.0) #0
17  ret float %x
18}
19
20; CHECK-LABEL: @constant_fold_fma_v4f32
21; CHECK-NEXT: ret <4 x float> <float 1.200000e+01, float 1.400000e+01, float 1.600000e+01, float 1.800000e+01>
22define <4 x float> @constant_fold_fma_v4f32() #0 {
23  %x = call <4 x float> @llvm.fma.v4f32(<4 x float> <float 1.0, float 2.0, float 3.0, float 4.0>, <4 x float> <float 2.0, float 2.0, float 2.0, float 2.0>, <4 x float> <float 10.0, float 10.0, float 10.0, float 10.0>)
24  ret <4 x float> %x
25}
26
27; CHECK-LABEL: @constant_fold_fmuladd_f32
28; CHECK-NEXT: ret float 6.000000e+00
29define float @constant_fold_fmuladd_f32() #0 {
30  %x = call float @llvm.fmuladd.f32(float 1.0, float 2.0, float 4.0) #0
31  ret float %x
32}
33
34; CHECK-LABEL: @constant_fold_fma_f64
35; CHECK-NEXT: ret double 6.000000e+00
36define double @constant_fold_fma_f64() #0 {
37  %x = call double @llvm.fma.f64(double 1.0, double 2.0, double 4.0) #0
38  ret double %x
39}
40
41; CHECK-LABEL: @constant_fold_fmuladd_f64
42; CHECK-NEXT: ret double 6.000000e+00
43define double @constant_fold_fmuladd_f64() #0 {
44  %x = call double @llvm.fmuladd.f64(double 1.0, double 2.0, double 4.0) #0
45  ret double %x
46}
47
48; The sqrt intrinsic is undefined for negative inputs besides -0.0.
49; CHECK-LABEL: @bad_sqrt
50; CHECK-NEXT: ret double undef
51define double @bad_sqrt() {
52  %x = call double @llvm.sqrt.f64(double -2.000000e+00)
53  ret double %x
54}
55
56attributes #0 = { nounwind readnone }
57