1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -mtriple=amdgcn-amd-amdhsa -instcombine -S | FileCheck %s
3
4; Simplify to +0.0 + z.
5define float @test_zero(float %x, float %z) {
6; CHECK-LABEL: @test_zero(
7; CHECK-NEXT:    [[CALL:%.*]] = fadd float [[Z:%.*]], 0.000000e+00
8; CHECK-NEXT:    ret float [[CALL]]
9;
10  %call = call float @llvm.amdgcn.fma.legacy(float %x, float 0.0, float %z)
11  ret float %call
12}
13
14; Simplify to +0.0 + z, preserving fmf.
15define float @test_zero_fmf(float %x, float %z) {
16; CHECK-LABEL: @test_zero_fmf(
17; CHECK-NEXT:    [[CALL:%.*]] = fadd contract float [[Z:%.*]], 0.000000e+00
18; CHECK-NEXT:    ret float [[CALL]]
19;
20  %call = call contract float @llvm.amdgcn.fma.legacy(float %x, float 0.0, float %z)
21  ret float %call
22}
23
24; Simplify to z.
25define float @test_zero_nsz(float %x, float %z) {
26; CHECK-LABEL: @test_zero_nsz(
27; CHECK-NEXT:    ret float [[Z:%.*]]
28;
29  %call = call nsz float @llvm.amdgcn.fma.legacy(float %x, float 0.0, float %z)
30  ret float %call
31}
32
33; Simplify to +0.0 + z.
34define float @test_negzero(float %y, float %z) {
35; CHECK-LABEL: @test_negzero(
36; CHECK-NEXT:    [[CALL:%.*]] = fadd float [[Z:%.*]], 0.000000e+00
37; CHECK-NEXT:    ret float [[CALL]]
38;
39  %call = call float @llvm.amdgcn.fma.legacy(float -0.0, float %y, float %z)
40  ret float %call
41}
42
43; Simplify to z.
44define float @test_negzero_nsz(float %y, float %z) {
45; CHECK-LABEL: @test_negzero_nsz(
46; CHECK-NEXT:    ret float [[Z:%.*]]
47;
48  %call = call nsz float @llvm.amdgcn.fma.legacy(float -0.0, float %y, float %z)
49  ret float %call
50}
51
52; Combine to fma because the constant is finite and non-zero.
53define float @test_const(float %x, float %z) {
54; CHECK-LABEL: @test_const(
55; CHECK-NEXT:    [[CALL:%.*]] = call float @llvm.fma.f32(float [[X:%.*]], float 9.950000e+01, float [[Z:%.*]])
56; CHECK-NEXT:    ret float [[CALL]]
57;
58  %call = call float @llvm.amdgcn.fma.legacy(float %x, float 99.5, float %z)
59  ret float %call
60}
61
62; Combine to fma because the constant is finite and non-zero, preserving fmf.
63define float @test_const_fmf(float %x, float %z) {
64; CHECK-LABEL: @test_const_fmf(
65; CHECK-NEXT:    [[CALL:%.*]] = call contract float @llvm.fma.f32(float [[X:%.*]], float 9.950000e+01, float [[Z:%.*]])
66; CHECK-NEXT:    ret float [[CALL]]
67;
68  %call = call contract float @llvm.amdgcn.fma.legacy(float %x, float 99.5, float %z)
69  ret float %call
70}
71
72; Combine to fma because neither argument can be infinity or NaN.
73define float @test_finite(i32 %x, i32 %y, float %z) {
74; CHECK-LABEL: @test_finite(
75; CHECK-NEXT:    [[XF:%.*]] = sitofp i32 [[X:%.*]] to float
76; CHECK-NEXT:    [[YF:%.*]] = sitofp i32 [[Y:%.*]] to float
77; CHECK-NEXT:    [[CALL:%.*]] = call float @llvm.fma.f32(float [[XF]], float [[YF]], float [[Z:%.*]])
78; CHECK-NEXT:    ret float [[CALL]]
79;
80  %xf = sitofp i32 %x to float
81  %yf = sitofp i32 %y to float
82  %call = call float @llvm.amdgcn.fma.legacy(float %xf, float %yf, float %z)
83  ret float %call
84}
85
86declare float @llvm.amdgcn.fma.legacy(float, float, float)
87