Skip to content

Commit c99be91

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

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
@@ -17283,6 +17283,9 @@ SDValue DAGCombiner::visitFSUB(SDNode *N) {
1728317283
// prefer it.
1728417284
SDValue DAGCombiner::combineFMulOrFDivWithIntPow2(SDNode *N) {
1728517285
EVT VT = N->getValueType(0);
17286+
if (!APFloat::isIEEELikeFP(VT.getFltSemantics()))
17287+
return SDValue();
17288+
1728617289
SDValue ConstOp, Pow2Op;
1728717290

1728817291
std::optional<int> Mantissa;
@@ -17309,8 +17312,8 @@ SDValue DAGCombiner::combineFMulOrFDivWithIntPow2(SDNode *N) {
1730917312

1731017313
const APFloat &APF = CFP->getValueAPF();
1731117314

17312-
// Make sure we have normal/ieee constant.
17313-
if (!APF.isNormal() || !APF.isIEEE())
17315+
// Make sure we have normal constant.
17316+
if (!APF.isNormal())
1731417317
return false;
1731517318

1731617319
// 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
@@ -1662,3 +1662,31 @@ define float @fdiv_pow_shl_cnt32_okay(i32 %cnt) nounwind {
16621662
%mul = fdiv float 0x3a20000000000000, %conv
16631663
ret float %mul
16641664
}
1665+
1666+
define x86_fp80 @pr128528(i1 %cond) {
1667+
; CHECK-SSE-LABEL: pr128528:
1668+
; CHECK-SSE: # %bb.0:
1669+
; CHECK-SSE-NEXT: testb $1, %dil
1670+
; CHECK-SSE-NEXT: movl $8, %eax
1671+
; CHECK-SSE-NEXT: movl $1, %ecx
1672+
; CHECK-SSE-NEXT: cmovnel %eax, %ecx
1673+
; CHECK-SSE-NEXT: movl %ecx, -{{[0-9]+}}(%rsp)
1674+
; CHECK-SSE-NEXT: fildl -{{[0-9]+}}(%rsp)
1675+
; CHECK-SSE-NEXT: fmull {{\.?LCPI[0-9]+_[0-9]+}}(%rip)
1676+
; CHECK-SSE-NEXT: retq
1677+
;
1678+
; CHECK-AVX-LABEL: pr128528:
1679+
; CHECK-AVX: # %bb.0:
1680+
; CHECK-AVX-NEXT: testb $1, %dil
1681+
; CHECK-AVX-NEXT: movl $8, %eax
1682+
; CHECK-AVX-NEXT: movl $1, %ecx
1683+
; CHECK-AVX-NEXT: cmovnel %eax, %ecx
1684+
; CHECK-AVX-NEXT: movl %ecx, -{{[0-9]+}}(%rsp)
1685+
; CHECK-AVX-NEXT: fildl -{{[0-9]+}}(%rsp)
1686+
; CHECK-AVX-NEXT: fmull {{\.?LCPI[0-9]+_[0-9]+}}(%rip)
1687+
; CHECK-AVX-NEXT: retq
1688+
%sub9 = select i1 %cond, i32 8, i32 1
1689+
%conv = uitofp i32 %sub9 to x86_fp80
1690+
%mul = fmul x86_fp80 %conv, 0xK4007D055555555555800
1691+
ret x86_fp80 %mul
1692+
}

0 commit comments

Comments
 (0)