Skip to content

[X86][DAGCombiner] Skip x87 fp80 values in combineFMulOrFDivWithIntPow2 #128618

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 4 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 7 additions & 2 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17271,6 +17271,11 @@ SDValue DAGCombiner::visitFSUB(SDNode *N) {
// prefer it.
SDValue DAGCombiner::combineFMulOrFDivWithIntPow2(SDNode *N) {
EVT VT = N->getValueType(0);
const fltSemantics &Sem = VT.getFltSemantics();
if (&Sem == &APFloat::x87DoubleExtended() ||
&Sem == &APFloat::PPCDoubleDouble())
return SDValue();

SDValue ConstOp, Pow2Op;

std::optional<int> Mantissa;
Expand All @@ -17297,8 +17302,8 @@ SDValue DAGCombiner::combineFMulOrFDivWithIntPow2(SDNode *N) {

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

// Make sure we have normal/ieee constant.
if (!APF.isNormal() || !APF.isIEEE())
// Make sure we have normal constant.
if (!APF.isNormal())
return false;

// Make sure the floats exponent is within the bounds that this transform
Expand Down
28 changes: 28 additions & 0 deletions llvm/test/CodeGen/X86/fold-int-pow2-with-fmul-or-fdiv.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1688,3 +1688,31 @@ define float @fdiv_pow_shl_cnt32_okay(i32 %cnt) nounwind {
%mul = fdiv float 0x3a20000000000000, %conv
ret float %mul
}

define x86_fp80 @pr128528(i1 %cond) {
; CHECK-SSE-LABEL: pr128528:
; CHECK-SSE: # %bb.0:
; CHECK-SSE-NEXT: testb $1, %dil
; CHECK-SSE-NEXT: movl $8, %eax
; CHECK-SSE-NEXT: movl $1, %ecx
; CHECK-SSE-NEXT: cmovnel %eax, %ecx
; CHECK-SSE-NEXT: movl %ecx, -{{[0-9]+}}(%rsp)
; CHECK-SSE-NEXT: fildl -{{[0-9]+}}(%rsp)
; CHECK-SSE-NEXT: fmull {{\.?LCPI[0-9]+_[0-9]+}}(%rip)
; CHECK-SSE-NEXT: retq
;
; CHECK-AVX-LABEL: pr128528:
; CHECK-AVX: # %bb.0:
; CHECK-AVX-NEXT: testb $1, %dil
; CHECK-AVX-NEXT: movl $8, %eax
; CHECK-AVX-NEXT: movl $1, %ecx
; CHECK-AVX-NEXT: cmovnel %eax, %ecx
; CHECK-AVX-NEXT: movl %ecx, -{{[0-9]+}}(%rsp)
; CHECK-AVX-NEXT: fildl -{{[0-9]+}}(%rsp)
; CHECK-AVX-NEXT: fmull {{\.?LCPI[0-9]+_[0-9]+}}(%rip)
; CHECK-AVX-NEXT: retq
%sub9 = select i1 %cond, i32 8, i32 1
%conv = uitofp i32 %sub9 to x86_fp80
%mul = fmul x86_fp80 %conv, 0xK4007D055555555555800
ret x86_fp80 %mul
}