[llvm] [KnownFPClass] Fix KnownFPClass::frexp subnormal mode handling (PR #219114)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 23:07:01 PDT 2026


================
@@ -491,7 +502,8 @@ define nofpclass(ninf nnorm nsub nzero) half @ret_only_positive_or_nan__frexp_se
 ; CHECK-LABEL: define nofpclass(ninf nzero nsub nnorm) half @ret_only_positive_or_nan__frexp_select_negative_or_unknown(
 ; CHECK-SAME: i1 [[COND:%.*]], half [[UNKNOWN:%.*]]) {
 ; CHECK-NEXT:    [[NEGATIVE:%.*]] = call half @returns_negative()
-; CHECK-NEXT:    [[FREXP:%.*]] = call { half, i32 } @llvm.frexp.f16.i32(half [[UNKNOWN]])
+; CHECK-NEXT:    [[SELECT:%.*]] = select i1 [[COND]], half [[UNKNOWN]], half [[NEGATIVE]]
+; CHECK-NEXT:    [[FREXP:%.*]] = call { half, i32 } @llvm.frexp.f16.i32(half [[SELECT]])
 ; CHECK-NEXT:    [[FREXP_MANT:%.*]] = extractvalue { half, i32 } [[FREXP]], 0
 ; CHECK-NEXT:    ret half [[FREXP_MANT]]
----------------
ZERICO2005 wrote:

My current fix causes `InstCombineSimplifyDemanded` to act as if the denormal mode is always `dynamic`. This means it is no longer able to fold this code because negative-subnormal could become positive-zero. This could be fixed in a follow-up PR by removing `fcNegSubnormal` or `fcPosSubnormal` from `DemandedMask` if it is safe to do so by checking the denormal mode.

https://github.com/llvm/llvm-project/pull/219114


More information about the llvm-commits mailing list