97 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.5define float @test_zero(float %x) {6; CHECK-LABEL: @test_zero(7; CHECK-NEXT: ret float 0.000000e+008;9 %call = call float @llvm.amdgcn.fmul.legacy(float %x, float 0.0)10 ret float %call11}12 13; Simplify to +0.0.14define float @test_negzero(float %y) {15; CHECK-LABEL: @test_negzero(16; CHECK-NEXT: ret float 0.000000e+0017;18 %call = call float @llvm.amdgcn.fmul.legacy(float -0.0, float %y)19 ret float %call20}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+0126; CHECK-NEXT: ret float [[CALL]]27;28 %call = call float @llvm.amdgcn.fmul.legacy(float %x, float 99.5)29 ret float %call30}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+0136; CHECK-NEXT: ret float [[CALL]]37;38 %call = call contract float @llvm.amdgcn.fmul.legacy(float %x, float 99.5)39 ret float %call40}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 float46; CHECK-NEXT: [[YF:%.*]] = sitofp i32 [[Y:%.*]] to float47; CHECK-NEXT: [[CALL:%.*]] = fmul float [[XF]], [[YF]]48; CHECK-NEXT: ret float [[CALL]]49;50 %xf = sitofp i32 %x to float51 %yf = sitofp i32 %y to float52 %call = call float @llvm.amdgcn.fmul.legacy(float %xf, float %yf)53 ret float %call54}55 56; Combine to fmul because neither argument can be infinity or NaN based on assumptions57define 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]], 0x7FF000000000000061; CHECK-NEXT: [[FABS_Y:%.*]] = call float @llvm.fabs.f32(float [[Y:%.*]])62; CHECK-NEXT: [[IS_FINITE_Y:%.*]] = fcmp one float [[FABS_Y]], 0x7FF000000000000063; 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, 0x7FF000000000000070 %fabs.y = call float @llvm.fabs.f32(float %y)71 %is.finite.y = fcmp one float %fabs.y, 0x7FF000000000000072 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 %call76}77 78define float @test_poison_var(float %x) {79; CHECK-LABEL: @test_poison_var(80; CHECK-NEXT: ret float poison81;82 %call = call float @llvm.amdgcn.fmul.legacy(float poison, float %x)83 ret float %call84}85 86define float @test_var_poison(float %x) {87; CHECK-LABEL: @test_var_poison(88; CHECK-NEXT: ret float poison89;90 %call = call float @llvm.amdgcn.fmul.legacy(float %x, float poison)91 ret float %call92}93 94declare float @llvm.amdgcn.fmul.legacy(float, float)95declare float @llvm.fabs.f32(float)96declare void @llvm.assume(i1 noundef)97