1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -mtriple=amdgcn-amd-amdhsa -passes=instcombine -S | FileCheck %s
4 ; Simplify to +0.0 + z.
5 define 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]]
10 %call = call float @llvm.amdgcn.fma.legacy(float %x, float 0.0, float %z)
14 ; Simplify to +0.0 + z, preserving fmf.
15 define 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]]
20 %call = call contract float @llvm.amdgcn.fma.legacy(float %x, float 0.0, float %z)
25 define float @test_zero_nsz(float %x, float %z) {
26 ; CHECK-LABEL: @test_zero_nsz(
27 ; CHECK-NEXT: ret float [[Z:%.*]]
29 %call = call nsz float @llvm.amdgcn.fma.legacy(float %x, float 0.0, float %z)
33 ; Simplify to +0.0 + z.
34 define 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]]
39 %call = call float @llvm.amdgcn.fma.legacy(float -0.0, float %y, float %z)
44 define float @test_negzero_nsz(float %y, float %z) {
45 ; CHECK-LABEL: @test_negzero_nsz(
46 ; CHECK-NEXT: ret float [[Z:%.*]]
48 %call = call nsz float @llvm.amdgcn.fma.legacy(float -0.0, float %y, float %z)
52 ; Combine to fma because the constant is finite and non-zero.
53 define 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]]
58 %call = call float @llvm.amdgcn.fma.legacy(float %x, float 99.5, float %z)
62 ; Combine to fma because the constant is finite and non-zero, preserving fmf.
63 define 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]]
68 %call = call contract float @llvm.amdgcn.fma.legacy(float %x, float 99.5, float %z)
72 ; Combine to fma because neither argument can be infinity or NaN.
73 define 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]]
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)
86 ; Combine to fma because neither argument can be infinity or NaN based on assumptions
87 define float @test_finite_assumed(float %x, float %y, float %z) {
88 ; CHECK-LABEL: @test_finite_assumed(
89 ; CHECK-NEXT: [[FABS_X:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
90 ; CHECK-NEXT: [[IS_FINITE_X:%.*]] = fcmp one float [[FABS_X]], 0x7FF0000000000000
91 ; CHECK-NEXT: [[FABS_Y:%.*]] = call float @llvm.fabs.f32(float [[Y:%.*]])
92 ; CHECK-NEXT: [[IS_FINITE_Y:%.*]] = fcmp one float [[FABS_Y]], 0x7FF0000000000000
93 ; CHECK-NEXT: call void @llvm.assume(i1 [[IS_FINITE_X]])
94 ; CHECK-NEXT: call void @llvm.assume(i1 [[IS_FINITE_Y]])
95 ; CHECK-NEXT: [[CALL:%.*]] = call float @llvm.fma.f32(float [[X]], float [[Y]], float [[Z:%.*]])
96 ; CHECK-NEXT: ret float [[CALL]]
98 %fabs.x = call float @llvm.fabs.f32(float %x)
99 %is.finite.x = fcmp one float %fabs.x, 0x7FF0000000000000
100 %fabs.y = call float @llvm.fabs.f32(float %y)
101 %is.finite.y = fcmp one float %fabs.y, 0x7FF0000000000000
102 call void @llvm.assume(i1 %is.finite.x)
103 call void @llvm.assume(i1 %is.finite.y)
104 %call = call float @llvm.amdgcn.fma.legacy(float %x, float %y, float %z)
108 declare float @llvm.amdgcn.fma.legacy(float, float, float)
109 declare float @llvm.fabs.f32(float)
110 declare void @llvm.assume(i1 noundef)