Skip to content

Commit

Permalink
[SelectionDAG] Add SPLAT_VECTOR to SelectionDAG::isConstantFPBuildVec…
Browse files Browse the repository at this point in the history
…torOrConstantFP.

Matches what is done for the int version.

Reviewed By: sdesmalen

Differential Revision: https://reviews.llvm.org/D119793
  • Loading branch information
topperc committed Feb 16, 2022
1 parent f150d29 commit 1daa66d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Expand Up @@ -11117,6 +11117,10 @@ SDNode *SelectionDAG::isConstantFPBuildVectorOrConstantFP(SDValue N) const {
if (ISD::isBuildVectorOfConstantFPSDNodes(N.getNode()))
return N.getNode();

if ((N.getOpcode() == ISD::SPLAT_VECTOR) &&
isa<ConstantFPSDNode>(N.getOperand(0)))
return N.getNode();

return nullptr;
}

Expand Down
22 changes: 22 additions & 0 deletions llvm/test/CodeGen/RISCV/rvv/combine-splats.ll
Expand Up @@ -109,3 +109,25 @@ define <vscale x 8 x i16> @combine_vec_lshr_lshr(<vscale x 8 x i16> %x) {
%v2 = lshr <vscale x 8 x i16> %v1, %splat2
ret <vscale x 8 x i16> %v2
}

; fold (fmul x, 1.0) -> x
define <vscale x 2 x float> @combine_fmul_one(<vscale x 2 x float> %x) {
; CHECK-LABEL: combine_fmul_one:
; CHECK: # %bb.0:
; CHECK-NEXT: ret
%ins = insertelement <vscale x 2 x float> poison, float 1.0, i32 0
%splat = shufflevector <vscale x 2 x float> %ins, <vscale x 2 x float> poison, <vscale x 2 x i32> zeroinitializer
%v = fmul <vscale x 2 x float> %x, %splat
ret <vscale x 2 x float> %v
}

; fold (fmul 1.0, x) -> x
define <vscale x 2 x float> @combine_fmul_one_commuted(<vscale x 2 x float> %x) {
; CHECK-LABEL: combine_fmul_one_commuted:
; CHECK: # %bb.0:
; CHECK-NEXT: ret
%ins = insertelement <vscale x 2 x float> poison, float 1.0, i32 0
%splat = shufflevector <vscale x 2 x float> %ins, <vscale x 2 x float> poison, <vscale x 2 x i32> zeroinitializer
%v = fmul <vscale x 2 x float> %splat, %x
ret <vscale x 2 x float> %v
}

0 comments on commit 1daa66d

Please sign in to comment.