135 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -mtriple=amdgcn-amd-amdhsa -passes=instcombine -S | FileCheck %s3 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+008; CHECK-NEXT: ret float [[CALL]]9;10 %call = call float @llvm.amdgcn.fma.legacy(float %x, float 0.0, float %z)11 ret float %call12}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+0018; 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 %call22}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 %call31}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+0037; CHECK-NEXT: ret float [[CALL]]38;39 %call = call float @llvm.amdgcn.fma.legacy(float -0.0, float %y, float %z)40 ret float %call41}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 %call50}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 %call60}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 %call70}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 float76; CHECK-NEXT: [[YF:%.*]] = sitofp i32 [[Y:%.*]] to float77; 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 float81 %yf = sitofp i32 %y to float82 %call = call float @llvm.amdgcn.fma.legacy(float %xf, float %yf, float %z)83 ret float %call84}85 86; Combine to fma because neither argument can be infinity or NaN based on assumptions87define 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]], 0x7FF000000000000091; CHECK-NEXT: [[FABS_Y:%.*]] = call float @llvm.fabs.f32(float [[Y:%.*]])92; CHECK-NEXT: [[IS_FINITE_Y:%.*]] = fcmp one float [[FABS_Y]], 0x7FF000000000000093; 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]]97;98 %fabs.x = call float @llvm.fabs.f32(float %x)99 %is.finite.x = fcmp one float %fabs.x, 0x7FF0000000000000100 %fabs.y = call float @llvm.fabs.f32(float %y)101 %is.finite.y = fcmp one float %fabs.y, 0x7FF0000000000000102 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)105 ret float %call106}107 108define float @test_poison_x_y(float %x, float %y) {109; CHECK-LABEL: @test_poison_x_y(110; CHECK-NEXT: ret float poison111;112 %call = call float @llvm.amdgcn.fma.legacy(float poison, float %x, float %y)113 ret float %call114}115 116define float @test_x_poison_y(float %x, float %y) {117; CHECK-LABEL: @test_x_poison_y(118; CHECK-NEXT: ret float poison119;120 %call = call float @llvm.amdgcn.fma.legacy(float %x, float poison, float %y)121 ret float %call122}123 124define float @test_x_y_poison_y(float %x, float %y) {125; CHECK-LABEL: @test_x_y_poison_y(126; CHECK-NEXT: ret float poison127;128 %call = call float @llvm.amdgcn.fma.legacy(float %x, float %y, float poison)129 ret float %call130}131 132declare float @llvm.amdgcn.fma.legacy(float, float, float)133declare float @llvm.fabs.f32(float)134declare void @llvm.assume(i1 noundef)135