[llvm] 1daa66d - [SelectionDAG] Add SPLAT_VECTOR to SelectionDAG::isConstantFPBuildVectorOrConstantFP.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 16 09:22:24 PST 2022
Author: Craig Topper
Date: 2022-02-16T09:22:11-08:00
New Revision: 1daa66d3fda96a7c6b670e05b9240a03fb8bd8a7
URL: https://github.com/llvm/llvm-project/commit/1daa66d3fda96a7c6b670e05b9240a03fb8bd8a7
DIFF: https://github.com/llvm/llvm-project/commit/1daa66d3fda96a7c6b670e05b9240a03fb8bd8a7.diff
LOG: [SelectionDAG] Add SPLAT_VECTOR to SelectionDAG::isConstantFPBuildVectorOrConstantFP.
Matches what is done for the int version.
Reviewed By: sdesmalen
Differential Revision: https://reviews.llvm.org/D119793
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/test/CodeGen/RISCV/rvv/combine-splats.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 32d961d9bf04..6c142fee38b5 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -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;
}
diff --git a/llvm/test/CodeGen/RISCV/rvv/combine-splats.ll b/llvm/test/CodeGen/RISCV/rvv/combine-splats.ll
index 969f37b338d5..f2d3af73b335 100644
--- a/llvm/test/CodeGen/RISCV/rvv/combine-splats.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/combine-splats.ll
@@ -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
+}
More information about the llvm-commits
mailing list