Skip to content

Commit 44d1dbd

Browse files
authored
[X86][DAGCombiner] Skip x87 fp80 values in combineFMulOrFDivWithIntPow2 (#128618)
f80 is not a valid IEEE floating-point type. Closes #128528.
1 parent d21b2e6 commit 44d1dbd

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

llvm/include/llvm/ADT/APFloat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ struct APFloatBase {
353353
static bool semanticsHasSignedRepr(const fltSemantics &);
354354
static bool semanticsHasInf(const fltSemantics &);
355355
static bool semanticsHasNaN(const fltSemantics &);
356+
static bool isIEEELikeFP(const fltSemantics &);
356357

357358
// Returns true if any number described by \p Src can be precisely represented
358359
// by a normal (not subnormal) value in \p Dst.

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17271,6 +17271,9 @@ SDValue DAGCombiner::visitFSUB(SDNode *N) {
1727117271
// prefer it.
1727217272
SDValue DAGCombiner::combineFMulOrFDivWithIntPow2(SDNode *N) {
1727317273
EVT VT = N->getValueType(0);
17274+
if (!APFloat::isIEEELikeFP(VT.getFltSemantics()))
17275+
return SDValue();
17276+
1727417277
SDValue ConstOp, Pow2Op;
1727517278

1727617279
std::optional<int> Mantissa;
@@ -17297,8 +17300,8 @@ SDValue DAGCombiner::combineFMulOrFDivWithIntPow2(SDNode *N) {
1729717300

1729817301
const APFloat &APF = CFP->getValueAPF();
1729917302

17300-
// Make sure we have normal/ieee constant.
17301-
if (!APF.isNormal() || !APF.isIEEE())
17303+
// Make sure we have normal constant.
17304+
if (!APF.isNormal())
1730217305
return false;
1730317306

1730417307
// Make sure the floats exponent is within the bounds that this transform

llvm/lib/Support/APFloat.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,11 @@ bool APFloatBase::semanticsHasNaN(const fltSemantics &semantics) {
353353
return semantics.nonFiniteBehavior != fltNonfiniteBehavior::FiniteOnly;
354354
}
355355

356+
bool APFloatBase::isIEEELikeFP(const fltSemantics &semantics) {
357+
// Keep in sync with Type::isIEEELikeFPTy
358+
return SemanticsToEnum(semantics) <= S_IEEEquad;
359+
}
360+
356361
bool APFloatBase::isRepresentableAsNormalIn(const fltSemantics &Src,
357362
const fltSemantics &Dst) {
358363
// Exponent range must be larger.

llvm/test/CodeGen/X86/fold-int-pow2-with-fmul-or-fdiv.ll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,3 +1688,31 @@ define float @fdiv_pow_shl_cnt32_okay(i32 %cnt) nounwind {
16881688
%mul = fdiv float 0x3a20000000000000, %conv
16891689
ret float %mul
16901690
}
1691+
1692+
define x86_fp80 @pr128528(i1 %cond) {
1693+
; CHECK-SSE-LABEL: pr128528:
1694+
; CHECK-SSE: # %bb.0:
1695+
; CHECK-SSE-NEXT: testb $1, %dil
1696+
; CHECK-SSE-NEXT: movl $8, %eax
1697+
; CHECK-SSE-NEXT: movl $1, %ecx
1698+
; CHECK-SSE-NEXT: cmovnel %eax, %ecx
1699+
; CHECK-SSE-NEXT: movl %ecx, -{{[0-9]+}}(%rsp)
1700+
; CHECK-SSE-NEXT: fildl -{{[0-9]+}}(%rsp)
1701+
; CHECK-SSE-NEXT: fmull {{\.?LCPI[0-9]+_[0-9]+}}(%rip)
1702+
; CHECK-SSE-NEXT: retq
1703+
;
1704+
; CHECK-AVX-LABEL: pr128528:
1705+
; CHECK-AVX: # %bb.0:
1706+
; CHECK-AVX-NEXT: testb $1, %dil
1707+
; CHECK-AVX-NEXT: movl $8, %eax
1708+
; CHECK-AVX-NEXT: movl $1, %ecx
1709+
; CHECK-AVX-NEXT: cmovnel %eax, %ecx
1710+
; CHECK-AVX-NEXT: movl %ecx, -{{[0-9]+}}(%rsp)
1711+
; CHECK-AVX-NEXT: fildl -{{[0-9]+}}(%rsp)
1712+
; CHECK-AVX-NEXT: fmull {{\.?LCPI[0-9]+_[0-9]+}}(%rip)
1713+
; CHECK-AVX-NEXT: retq
1714+
%sub9 = select i1 %cond, i32 8, i32 1
1715+
%conv = uitofp i32 %sub9 to x86_fp80
1716+
%mul = fmul x86_fp80 %conv, 0xK4007D055555555555800
1717+
ret x86_fp80 %mul
1718+
}

0 commit comments

Comments
 (0)