[llvm] r234179 - [DAGCombiner] Add support for FCEIL, FFLOOR and FTRUNC vector constant folding
Simon Pilgrim
llvm-dev at redking.me.uk
Mon Apr 6 10:15:41 PDT 2015
Author: rksimon
Date: Mon Apr 6 12:15:41 2015
New Revision: 234179
URL: http://llvm.org/viewvc/llvm-project?rev=234179&view=rev
Log:
[DAGCombiner] Add support for FCEIL, FFLOOR and FTRUNC vector constant folding
Differential Revision: http://reviews.llvm.org/D8715
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/trunk/test/CodeGen/X86/vec_floor.ll
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=234179&r1=234178&r2=234179&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Mon Apr 6 12:15:41 2015
@@ -8194,11 +8194,10 @@ SDValue DAGCombiner::visitFP_EXTEND(SDNo
SDValue DAGCombiner::visitFCEIL(SDNode *N) {
SDValue N0 = N->getOperand(0);
- ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N0);
EVT VT = N->getValueType(0);
// fold (fceil c1) -> fceil(c1)
- if (N0CFP)
+ if (isConstantFPBuildVectorOrConstantFP(N0))
return DAG.getNode(ISD::FCEIL, SDLoc(N), VT, N0);
return SDValue();
@@ -8206,11 +8205,10 @@ SDValue DAGCombiner::visitFCEIL(SDNode *
SDValue DAGCombiner::visitFTRUNC(SDNode *N) {
SDValue N0 = N->getOperand(0);
- ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N0);
EVT VT = N->getValueType(0);
// fold (ftrunc c1) -> ftrunc(c1)
- if (N0CFP)
+ if (isConstantFPBuildVectorOrConstantFP(N0))
return DAG.getNode(ISD::FTRUNC, SDLoc(N), VT, N0);
return SDValue();
@@ -8218,11 +8216,10 @@ SDValue DAGCombiner::visitFTRUNC(SDNode
SDValue DAGCombiner::visitFFLOOR(SDNode *N) {
SDValue N0 = N->getOperand(0);
- ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N0);
EVT VT = N->getValueType(0);
// fold (ffloor c1) -> ffloor(c1)
- if (N0CFP)
+ if (isConstantFPBuildVectorOrConstantFP(N0))
return DAG.getNode(ISD::FFLOOR, SDLoc(N), VT, N0);
return SDValue();
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=234179&r1=234178&r2=234179&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Mon Apr 6 12:15:41 2015
@@ -2853,6 +2853,9 @@ SDValue SelectionDAG::getNode(unsigned O
break;
case ISD::FNEG:
case ISD::FABS:
+ case ISD::FCEIL:
+ case ISD::FTRUNC:
+ case ISD::FFLOOR:
case ISD::FP_EXTEND:
case ISD::TRUNCATE:
case ISD::UINT_TO_FP:
@@ -2870,6 +2873,7 @@ SDValue SelectionDAG::getNode(unsigned O
}
if (Ops.size() == VT.getVectorNumElements())
return getNode(ISD::BUILD_VECTOR, DL, VT, Ops);
+ break;
}
}
}
Modified: llvm/trunk/test/CodeGen/X86/vec_floor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/vec_floor.ll?rev=234179&r1=234178&r2=234179&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/vec_floor.ll (original)
+++ llvm/trunk/test/CodeGen/X86/vec_floor.ll Mon Apr 6 12:15:41 2015
@@ -180,3 +180,49 @@ define <8 x float> @nearbyint_v8f32(<8 x
ret <8 x float> %t
}
declare <8 x float> @llvm.nearbyint.v8f32(<8 x float> %p)
+
+;
+; Constant Folding
+;
+
+define <2 x double> @const_floor_v2f64() {
+ ; CHECK: const_floor_v2f64
+ ; CHECK: movaps {{.*#+}} xmm0 = [-2.000000e+00,2.000000e+00]
+ %t = call <2 x double> @llvm.floor.v2f64(<2 x double> <double -1.5, double 2.5>)
+ ret <2 x double> %t
+}
+
+define <4 x float> @const_floor_v4f32() {
+ ; CHECK: const_floor_v4f32
+ ; CHECK: movaps {{.*#+}} xmm0 = [-4.000000e+00,6.000000e+00,-9.000000e+00,2.000000e+00]
+ %t = call <4 x float> @llvm.floor.v4f32(<4 x float> <float -3.5, float 6.0, float -9.0, float 2.5>)
+ ret <4 x float> %t
+}
+
+define <2 x double> @const_ceil_v2f64() {
+ ; CHECK: const_ceil_v2f64
+ ; CHECK: movaps {{.*#+}} xmm0 = [-1.000000e+00,3.000000e+00]
+ %t = call <2 x double> @llvm.ceil.v2f64(<2 x double> <double -1.5, double 2.5>)
+ ret <2 x double> %t
+}
+
+define <4 x float> @const_ceil_v4f32() {
+ ; CHECK: const_ceil_v4f32
+ ; CHECK: movaps {{.*#+}} xmm0 = [-3.000000e+00,6.000000e+00,-9.000000e+00,3.000000e+00]
+ %t = call <4 x float> @llvm.ceil.v4f32(<4 x float> <float -3.5, float 6.0, float -9.0, float 2.5>)
+ ret <4 x float> %t
+}
+
+define <2 x double> @const_trunc_v2f64() {
+ ; CHECK: const_trunc_v2f64
+ ; CHECK: movaps {{.*#+}} xmm0 = [-1.000000e+00,2.000000e+00]
+ %t = call <2 x double> @llvm.trunc.v2f64(<2 x double> <double -1.5, double 2.5>)
+ ret <2 x double> %t
+}
+
+define <4 x float> @const_trunc_v4f32() {
+ ; CHECK: const_trunc_v4f32
+ ; CHECK: movaps {{.*#+}} xmm0 = [-3.000000e+00,6.000000e+00,-9.000000e+00,2.000000e+00]
+ %t = call <4 x float> @llvm.trunc.v4f32(<4 x float> <float -3.5, float 6.0, float -9.0, float 2.5>)
+ ret <4 x float> %t
+}
More information about the llvm-commits
mailing list