Extended Description
As stated in LangRef, if either operand for llvm.minnum is a NaN, returns the other non-NaN operand. If llvm.minnum is attached with nnan flag, when an argument is a NaN, it produces a poison value.
See below the incorrect transformation. When input %x is NaN, the source program returns 0.0, while the target program returns poison. Target is more poisonous than source.
llvm/test/Transforms/InstCombine/minnum.ll
define float @minnum_f32_1_minnum_p0_val_nnan_ninf(float %x) {
; CHECK-LABEL: @minnum_f32_1_minnum_p0_val_nnan_ninf(
; CHECK-NEXT: [[TMP1:%.]] = call nnan ninf float @llvm.minnum.f32(float [[X:%.]], float 0.000000e+00)
; CHECK-NEXT: ret float [[TMP1]]
;
%y = call float @llvm.minnum.f32(float 0.0, float %x)
%z = call nnan ninf float @llvm.minnum.f32(float %y, float 1.0)
ret float %z
}
Extended Description
As stated in LangRef, if either operand for llvm.minnum is a NaN, returns the other non-NaN operand. If llvm.minnum is attached with nnan flag, when an argument is a NaN, it produces a poison value.
See below the incorrect transformation. When input %x is NaN, the source program returns 0.0, while the target program returns poison. Target is more poisonous than source.
llvm/test/Transforms/InstCombine/minnum.ll
define float @minnum_f32_1_minnum_p0_val_nnan_ninf(float %x) {
; CHECK-LABEL: @minnum_f32_1_minnum_p0_val_nnan_ninf(
; CHECK-NEXT: [[TMP1:%.]] = call nnan ninf float @llvm.minnum.f32(float [[X:%.]], float 0.000000e+00)
; CHECK-NEXT: ret float [[TMP1]]
;
%y = call float @llvm.minnum.f32(float 0.0, float %x)
%z = call nnan ninf float @llvm.minnum.f32(float %y, float 1.0)
ret float %z
}