| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 | |
| ; RUN: opt -passes=instsimplify -S < %s | FileCheck %s | |
| ; Record current IR constant folding under different denormal environments. | |
| ; FIXME: Honor the function's denormal environment in every constant fold. | |
| ; Scalar binary arithmetic, vector addition, and fcmp already honor input FTZ. | |
| ; FIXME: fmuladd, fma, ceil, and all six min/max variants should also store +0. | |
| ; In particular, ceil(min-subnormal) should use a flushed input, producing +0 | |
| ; instead of 1. | |
| define void @preservesign(ptr %fadd_res, ptr %fsub_res, ptr %fmul_res, ptr %fdiv_res, ptr %fmuladd_res, ptr %fma_res, ptr %ceil_res, ptr %fcmp_res, ptr %vector_add_res, ptr %minnum_res, ptr %maxnum_res, ptr %minimum_res, ptr %maximum_res, ptr %minimumnum_res, ptr %maximumnum_res) denormal_fpenv(float: preservesign) { | |
| ; CHECK-LABEL: define void @preservesign( | |
| ; CHECK-SAME: ptr [[FADD_RES:%.*]], ptr [[FSUB_RES:%.*]], ptr [[FMUL_RES:%.*]], ptr [[FDIV_RES:%.*]], ptr [[FMULADD_RES:%.*]], ptr [[FMA_RES:%.*]], ptr [[CEIL_RES:%.*]], ptr [[FCMP_RES:%.*]], ptr [[VECTOR_ADD_RES:%.*]], ptr [[MINNUM_RES:%.*]], ptr [[MAXNUM_RES:%.*]], ptr [[MINIMUM_RES:%.*]], ptr [[MAXIMUM_RES:%.*]], ptr [[MINIMUMNUM_RES:%.*]], ptr [[MAXIMUMNUM_RES:%.*]]) #[[ATTR0:[0-9]+]] { | |
| ; CHECK-NEXT: store float 0.000000e+00, ptr [[FADD_RES]], align 4 | |
| ; CHECK-NEXT: store float 0.000000e+00, ptr [[FSUB_RES]], align 4 | |
| ; CHECK-NEXT: store float 0.000000e+00, ptr [[FMUL_RES]], align 4 | |
| ; CHECK-NEXT: store float 0.000000e+00, ptr [[FDIV_RES]], align 4 | |
| ; CHECK-NEXT: store float 1.401300e-45, ptr [[FMULADD_RES]], align 4 | |
| ; CHECK-NEXT: store float 1.401300e-45, ptr [[FMA_RES]], align 4 | |
| ; CHECK-NEXT: store float 1.000000e+00, ptr [[CEIL_RES]], align 4 | |
| ; CHECK-NEXT: store i1 true, ptr [[FCMP_RES]], align 1 | |
| ; CHECK-NEXT: store <2 x float> zeroinitializer, ptr [[VECTOR_ADD_RES]], align 8 | |
| ; CHECK-NEXT: store float 1.401300e-45, ptr [[MINNUM_RES]], align 4 | |
| ; CHECK-NEXT: store float 1.401300e-45, ptr [[MAXNUM_RES]], align 4 | |
| ; CHECK-NEXT: store float 1.401300e-45, ptr [[MINIMUM_RES]], align 4 | |
| ; CHECK-NEXT: store float 1.401300e-45, ptr [[MAXIMUM_RES]], align 4 | |
| ; CHECK-NEXT: store float 1.401300e-45, ptr [[MINIMUMNUM_RES]], align 4 | |
| ; CHECK-NEXT: store float 1.401300e-45, ptr [[MAXIMUMNUM_RES]], align 4 | |
| ; CHECK-NEXT: ret void | |
| ; | |
| %fadd = fadd float f0x00000001, f0x00000001 | |
| store float %fadd, ptr %fadd_res | |
| %fsub = fsub float f0x00000001, f0x80000001 | |
| store float %fsub, ptr %fsub_res | |
| %fmul = fmul float f0x00000001, 2.0 | |
| store float %fmul, ptr %fmul_res | |
| %fdiv = fdiv float f0x00000001, 0.5 | |
| store float %fdiv, ptr %fdiv_res | |
| %fmuladd = call float @llvm.fmuladd.f32(float f0x00000001, float 1.0, float 0.0) | |
| store float %fmuladd, ptr %fmuladd_res | |
| %fma = call float @llvm.fma.f32(float f0x00000001, float 1.0, float 0.0) | |
| store float %fma, ptr %fma_res | |
| %ceil = call float @llvm.ceil.f32(float f0x00000001) | |
| store float %ceil, ptr %ceil_res | |
| %fcmp = fcmp oeq float f0x00000001, 0.0 | |
| store i1 %fcmp, ptr %fcmp_res | |
| %vector_add = fadd <2 x float> <float f0x00000001, float 0.0>, <float 0.0, float f0x00000001> | |
| store <2 x float> %vector_add, ptr %vector_add_res | |
| %minnum = call float @llvm.minnum.f32(float f0x00000001, float 1.0) | |
| store float %minnum, ptr %minnum_res | |
| %maxnum = call float @llvm.maxnum.f32(float f0x00000001, float 0.0) | |
| store float %maxnum, ptr %maxnum_res | |
| %minimum = call float @llvm.minimum.f32(float f0x00000001, float 1.0) | |
| store float %minimum, ptr %minimum_res | |
| %maximum = call float @llvm.maximum.f32(float f0x00000001, float 0.0) | |
| store float %maximum, ptr %maximum_res | |
| %minimumnum = call float @llvm.minimumnum.f32(float f0x00000001, float 1.0) | |
| store float %minimumnum, ptr %minimumnum_res | |
| %maximumnum = call float @llvm.maximumnum.f32(float f0x00000001, float 0.0) | |
| store float %maximumnum, ptr %maximumnum_res | |
| ret void | |
| } | |
| ; fmul correctly remains unfolded because its result depends on dynamic FTZ. | |
| ; FIXME: Keep minnum unfolded too: its result can be min-subnormal or +0. | |
| define void @dynamic(ptr %minnum_res, ptr %fmul_res) denormal_fpenv(float: dynamic) { | |
| ; CHECK-LABEL: define void @dynamic( | |
| ; CHECK-SAME: ptr [[MINNUM_RES:%.*]], ptr [[FMUL_RES:%.*]]) #[[ATTR1:[0-9]+]] { | |
| ; CHECK-NEXT: store float 1.401300e-45, ptr [[MINNUM_RES]], align 4 | |
| ; CHECK-NEXT: [[FMUL:%.*]] = fmul float 1.401300e-45, 2.000000e+00 | |
| ; CHECK-NEXT: store float [[FMUL]], ptr [[FMUL_RES]], align 4 | |
| ; CHECK-NEXT: ret void | |
| ; | |
| %minnum = call float @llvm.minnum.f32(float f0x00000001, float 1.0) | |
| store float %minnum, ptr %minnum_res | |
| %fmul = fmul float f0x00000001, 2.0 | |
| store float %fmul, ptr %fmul_res | |
| ret void | |
| } |