diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -11117,6 +11117,10 @@ if (ISD::isBuildVectorOfConstantFPSDNodes(N.getNode())) return N.getNode(); + if ((N.getOpcode() == ISD::SPLAT_VECTOR) && + isa(N.getOperand(0))) + return N.getNode(); + return nullptr; } diff --git a/llvm/test/CodeGen/RISCV/rvv/combine-splats.ll b/llvm/test/CodeGen/RISCV/rvv/combine-splats.ll --- a/llvm/test/CodeGen/RISCV/rvv/combine-splats.ll +++ b/llvm/test/CodeGen/RISCV/rvv/combine-splats.ll @@ -109,3 +109,25 @@ %v2 = lshr %v1, %splat2 ret %v2 } + +; fold (fmul x, 1.0) -> x +define @combine_fmul_one( %x) { +; CHECK-LABEL: combine_fmul_one: +; CHECK: # %bb.0: +; CHECK-NEXT: ret + %ins = insertelement poison, float 1.0, i32 0 + %splat = shufflevector %ins, poison, zeroinitializer + %v = fmul %x, %splat + ret %v +} + +; fold (fmul 1.0, x) -> x +define @combine_fmul_one_commuted( %x) { +; CHECK-LABEL: combine_fmul_one_commuted: +; CHECK: # %bb.0: +; CHECK-NEXT: ret + %ins = insertelement poison, float 1.0, i32 0 + %splat = shufflevector %ins, poison, zeroinitializer + %v = fmul %splat, %x + ret %v +}