https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/130489
Backport 029e10289a02b438f1a22f401c94ed60ab4bb704 Requested by: @dtcxzyw >From 5229bbb52b2585be2c1a2e4bf9fcf2fa73ce3fea Mon Sep 17 00:00:00 2001 From: Yingwei Zheng <dtcxzyw2...@gmail.com> Date: Sun, 9 Mar 2025 21:10:35 +0800 Subject: [PATCH] [ValueTracking] Bail out on x86_fp80 when computing fpclass with knownbits (#130477) In https://github.com/llvm/llvm-project/pull/97762, we assume the minimum possible value of X is NaN implies X is NaN. But it doesn't hold for x86_fp80 format. If the knownbits of X are `?'011111111111110'????????????????????????????????????????????????????????????????`, the minimum possible value of X is NaN/unnormal. However, it can be a normal value. Closes https://github.com/llvm/llvm-project/issues/130408. (cherry picked from commit 029e10289a02b438f1a22f401c94ed60ab4bb704) --- llvm/lib/Analysis/ValueTracking.cpp | 3 ++- llvm/test/Transforms/InstSimplify/fcmp.ll | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 8a674914641a8..4e79f41df2eb9 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -6135,13 +6135,14 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts, else if (Bits.isNegative()) Known.signBitMustBeOne(); - if (Ty->isIEEE()) { + if (Ty->isIEEELikeFPTy()) { // IEEE floats are NaN when all bits of the exponent plus at least one of // the fraction bits are 1. This means: // - If we assume unknown bits are 0 and the value is NaN, it will // always be NaN // - If we assume unknown bits are 1 and the value is not NaN, it can // never be NaN + // Note: They do not hold for x86_fp80 format. if (APFloat(Ty->getFltSemantics(), Bits.One).isNaN()) Known.KnownFPClasses = fcNan; else if (!APFloat(Ty->getFltSemantics(), ~Bits.Zero).isNaN()) diff --git a/llvm/test/Transforms/InstSimplify/fcmp.ll b/llvm/test/Transforms/InstSimplify/fcmp.ll index 64132f5fb7db7..0c2be5210a741 100644 --- a/llvm/test/Transforms/InstSimplify/fcmp.ll +++ b/llvm/test/Transforms/InstSimplify/fcmp.ll @@ -16,3 +16,20 @@ define i1 @poison2(float %x) { %v = fcmp ueq float %x, poison ret i1 %v } + +define i1 @pr130408(x86_fp80 %x) { +; CHECK-LABEL: @pr130408( +; CHECK-NEXT: [[BITS:%.*]] = bitcast x86_fp80 [[X:%.*]] to i80 +; CHECK-NEXT: [[MASKED:%.*]] = and i80 [[BITS]], -604444463063240877801473 +; CHECK-NEXT: [[OR:%.*]] = or i80 [[MASKED]], 302194561415509874573312 +; CHECK-NEXT: [[FP:%.*]] = bitcast i80 [[OR]] to x86_fp80 +; CHECK-NEXT: [[RES:%.*]] = fcmp uno x86_fp80 [[FP]], 0xK00000000000000000000 +; CHECK-NEXT: ret i1 [[RES]] +; + %bits = bitcast x86_fp80 %x to i80 + %masked = and i80 %bits, -604444463063240877801473 + %or = or i80 %masked, 302194561415509874573312 + %fp = bitcast i80 %or to x86_fp80 + %res = fcmp uno x86_fp80 %fp, 0xK00000000000000000000 + ret i1 %res +} _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits