From d037089ea6283f9ea7eb11cf6ab93309959a48ff Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Sun, 9 Mar 2025 17:25:48 +0800 Subject: [PATCH 1/2] [InstSimplify] Add pre-commit tests. NFC. --- llvm/test/Transforms/InstSimplify/fcmp.ll | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/llvm/test/Transforms/InstSimplify/fcmp.ll b/llvm/test/Transforms/InstSimplify/fcmp.ll index 64132f5fb7db7..680b35094ab3e 100644 --- a/llvm/test/Transforms/InstSimplify/fcmp.ll +++ b/llvm/test/Transforms/InstSimplify/fcmp.ll @@ -16,3 +16,15 @@ 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: ret i1 true +; + %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 +} From 47c7bb1905bb5290aa4a22691496b2d8c7403cd9 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Sun, 9 Mar 2025 17:27:06 +0800 Subject: [PATCH 2/2] [ValueTracking] Bail out on x86_fp80 when computing fpclass with knownbits --- llvm/lib/Analysis/ValueTracking.cpp | 3 ++- llvm/test/Transforms/InstSimplify/fcmp.ll | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 08dc34f89130a..2920738445d5b 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -6208,13 +6208,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 680b35094ab3e..0c2be5210a741 100644 --- a/llvm/test/Transforms/InstSimplify/fcmp.ll +++ b/llvm/test/Transforms/InstSimplify/fcmp.ll @@ -19,7 +19,12 @@ define i1 @poison2(float %x) { define i1 @pr130408(x86_fp80 %x) { ; CHECK-LABEL: @pr130408( -; CHECK-NEXT: ret i1 true +; 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