Skip to content

[ValueTracking] Bail out on x86_fp80 when computing fpclass with knownbits #130477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
17 changes: 17 additions & 0 deletions llvm/test/Transforms/InstSimplify/fcmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading