Skip to content

Commit

Permalink
[X86] Fold (v2i64 (scalar_to_vector (i64 (bitcast (double))))) -> (bi…
Browse files Browse the repository at this point in the history
…tcast (v2f64 scalar_to_vector))

This can occur more frequently after the MMX retirement if anyone is still using MMX intrinsics that now wrap to SSE
  • Loading branch information
RKSimon committed Nov 29, 2024
1 parent 59f57be commit 55dd475
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 10 additions & 4 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58359,10 +58359,16 @@ static SDValue combineScalarToVector(SDNode *N, SelectionDAG &DAG,
DAG.getZExtOrTrunc(ZeroExt, DL, MVT::i32))));
}

// Combine (v2i64 (scalar_to_vector (i64 (bitconvert (mmx))))) to MOVQ2DQ.
if (VT == MVT::v2i64 && Src.getOpcode() == ISD::BITCAST &&
Src.getOperand(0).getValueType() == MVT::x86mmx)
return DAG.getNode(X86ISD::MOVQ2DQ, DL, VT, Src.getOperand(0));
if (VT == MVT::v2i64 && Src.getOpcode() == ISD::BITCAST) {
SDValue SrcOp = Src.getOperand(0);
// Combine (v2i64 (scalar_to_vector (i64 (bitcast (double))))) to MOVQ.
if (SrcOp.getValueType() == MVT::f64)
return DAG.getBitcast(
VT, DAG.getNode(ISD::SCALAR_TO_VECTOR, DL, MVT::v2f64, SrcOp));
// Combine (v2i64 (scalar_to_vector (i64 (bitcast (mmx))))) to MOVQ2DQ.
if (SrcOp.getValueType() == MVT::x86mmx)
return DAG.getNode(X86ISD::MOVQ2DQ, DL, VT, SrcOp);
}

// See if we're broadcasting the scalar value, in which case just reuse that.
// Ensure the same SDValue from the SDNode use is being used.
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/CodeGen/X86/mmx-cvt.ll
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ define noundef <2 x i64> @cvt_f64_v2i64(double %a0) {
;
; X64-LABEL: cvt_f64_v2i64:
; X64: # %bb.0:
; X64-NEXT: movq %xmm0, %rax
; X64-NEXT: movq %rax, %xmm0
; X64-NEXT: movq {{.*#+}} xmm0 = xmm0[0],zero
; X64-NEXT: retq
%bc = bitcast double %a0 to <1 x i64>
%r = shufflevector <1 x i64> %bc, <1 x i64> zeroinitializer, <2 x i32> <i32 0, i32 1>
Expand Down

0 comments on commit 55dd475

Please sign in to comment.