From 07e063e44c2348d23b2d7f249e7da3be56c20760 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Mon, 6 Apr 2015 17:15:41 +0000 Subject: [PATCH] [DAGCombiner] Add support for FCEIL, FFLOOR and FTRUNC vector constant folding Differential Revision: http://reviews.llvm.org/D8715 llvm-svn: 234179 --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 9 ++-- .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 4 ++ llvm/test/CodeGen/X86/vec_floor.ll | 46 +++++++++++++++++++ 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index e0866ef4ee75..71fae7b049a3 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -8194,11 +8194,10 @@ SDValue DAGCombiner::visitFP_EXTEND(SDNode *N) { SDValue DAGCombiner::visitFCEIL(SDNode *N) { SDValue N0 = N->getOperand(0); - ConstantFPSDNode *N0CFP = dyn_cast(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 *N) { SDValue DAGCombiner::visitFTRUNC(SDNode *N) { SDValue N0 = N->getOperand(0); - ConstantFPSDNode *N0CFP = dyn_cast(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 *N) { SDValue DAGCombiner::visitFFLOOR(SDNode *N) { SDValue N0 = N->getOperand(0); - ConstantFPSDNode *N0CFP = dyn_cast(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(); diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 644411706f40..fdfdd15ad67d 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -2853,6 +2853,9 @@ SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, 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 Opcode, SDLoc DL, } if (Ops.size() == VT.getVectorNumElements()) return getNode(ISD::BUILD_VECTOR, DL, VT, Ops); + break; } } } diff --git a/llvm/test/CodeGen/X86/vec_floor.ll b/llvm/test/CodeGen/X86/vec_floor.ll index 4db68bd18223..f35c4ab4a76e 100644 --- a/llvm/test/CodeGen/X86/vec_floor.ll +++ b/llvm/test/CodeGen/X86/vec_floor.ll @@ -180,3 +180,49 @@ define <8 x float> @nearbyint_v8f32(<8 x float> %p) 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> ) + 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> ) + 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> ) + 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> ) + 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> ) + 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> ) + ret <4 x float> %t +}