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 3 4; Simplify to +0.0. 5define float @test_zero(float %x) { 6; CHECK-LABEL: @test_zero( 7; CHECK-NEXT: ret float 0.000000e+00 8; 9 %call = call float @llvm.amdgcn.fmul.legacy(float %x, float 0.0) 10 ret float %call 11} 12 13; Simplify to +0.0. 14define float @test_negzero(float %y) { 15; CHECK-LABEL: @test_negzero( 16; CHECK-NEXT: ret float 0.000000e+00 17; 18 %call = call float @llvm.amdgcn.fmul.legacy(float -0.0, float %y) 19 ret float %call 20} 21 22; Combine to fmul because the constant is finite and non-zero. 23define float @test_const(float %x) { 24; CHECK-LABEL: @test_const( 25; CHECK-NEXT: [[CALL:%.*]] = fmul float [[X:%.*]], 9.950000e+01 26; CHECK-NEXT: ret float [[CALL]] 27; 28 %call = call float @llvm.amdgcn.fmul.legacy(float %x, float 99.5) 29 ret float %call 30} 31 32; Combine to fmul because the constant is finite and non-zero, preserving fmf. 33define float @test_const_fmf(float %x) { 34; CHECK-LABEL: @test_const_fmf( 35; CHECK-NEXT: [[CALL:%.*]] = fmul contract float [[X:%.*]], 9.950000e+01 36; CHECK-NEXT: ret float [[CALL]] 37; 38 %call = call contract float @llvm.amdgcn.fmul.legacy(float %x, float 99.5) 39 ret float %call 40} 41 42; Combine to fmul because neither argument can be infinity or NaN. 43define float @test_finite(i32 %x, i32 %y) { 44; CHECK-LABEL: @test_finite( 45; CHECK-NEXT: [[XF:%.*]] = sitofp i32 [[X:%.*]] to float 46; CHECK-NEXT: [[YF:%.*]] = sitofp i32 [[Y:%.*]] to float 47; CHECK-NEXT: [[CALL:%.*]] = fmul float [[XF]], [[YF]] 48; CHECK-NEXT: ret float [[CALL]] 49; 50 %xf = sitofp i32 %x to float 51 %yf = sitofp i32 %y to float 52 %call = call float @llvm.amdgcn.fmul.legacy(float %xf, float %yf) 53 ret float %call 54} 55 56; Combine to fmul because neither argument can be infinity or NaN based on assumptions 57define float @test_finite_assumed(float %x, float %y) { 58; CHECK-LABEL: @test_finite_assumed( 59; CHECK-NEXT: [[FABS_X:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]]) 60; CHECK-NEXT: [[IS_FINITE_X:%.*]] = fcmp one float [[FABS_X]], 0x7FF0000000000000 61; CHECK-NEXT: [[FABS_Y:%.*]] = call float @llvm.fabs.f32(float [[Y:%.*]]) 62; CHECK-NEXT: [[IS_FINITE_Y:%.*]] = fcmp one float [[FABS_Y]], 0x7FF0000000000000 63; CHECK-NEXT: call void @llvm.assume(i1 [[IS_FINITE_X]]) 64; CHECK-NEXT: call void @llvm.assume(i1 [[IS_FINITE_Y]]) 65; CHECK-NEXT: [[CALL:%.*]] = fmul float [[X]], [[Y]] 66; CHECK-NEXT: ret float [[CALL]] 67; 68 %fabs.x = call float @llvm.fabs.f32(float %x) 69 %is.finite.x = fcmp one float %fabs.x, 0x7FF0000000000000 70 %fabs.y = call float @llvm.fabs.f32(float %y) 71 %is.finite.y = fcmp one float %fabs.y, 0x7FF0000000000000 72 call void @llvm.assume(i1 %is.finite.x) 73 call void @llvm.assume(i1 %is.finite.y) 74 %call = call float @llvm.amdgcn.fmul.legacy(float %x, float %y) 75 ret float %call 76} 77 78declare float @llvm.amdgcn.fmul.legacy(float, float) 79declare float @llvm.fabs.f32(float) 80declare void @llvm.assume(i1 noundef) 81