[llvm] r339070 - AMDGPU: Refactor fcanonicalize combine
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 6 15:10:26 PDT 2018
Author: arsenm
Date: Mon Aug 6 15:10:26 2018
New Revision: 339070
URL: http://llvm.org/viewvc/llvm-project?rev=339070&view=rev
Log:
AMDGPU: Refactor fcanonicalize combine
This will make more complex combines easier.
Modified:
llvm/trunk/lib/Target/AMDGPU/SIISelLowering.cpp
llvm/trunk/lib/Target/AMDGPU/SIISelLowering.h
Modified: llvm/trunk/lib/Target/AMDGPU/SIISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIISelLowering.cpp?rev=339070&r1=339069&r2=339070&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/SIISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/SIISelLowering.cpp Mon Aug 6 15:10:26 2018
@@ -6852,47 +6852,19 @@ bool SITargetLowering::isCanonicalized(S
}
// Constant fold canonicalize.
-SDValue SITargetLowering::performFCanonicalizeCombine(
- SDNode *N,
- DAGCombinerInfo &DCI) const {
- SelectionDAG &DAG = DCI.DAG;
- SDValue N0 = N->getOperand(0);
-
- // fcanonicalize undef -> qnan
- if (N0.isUndef()) {
- EVT VT = N->getValueType(0);
- APFloat QNaN = APFloat::getQNaN(SelectionDAG::EVTToAPFloatSemantics(VT));
- return DAG.getConstantFP(QNaN, SDLoc(N), VT);
- }
-
- ConstantFPSDNode *CFP = isConstOrConstSplatFP(N0);
- if (!CFP) {
- SDValue N0 = N->getOperand(0);
- return isCanonicalized(DAG, N0) ? N0 : SDValue();
- }
-
- const APFloat &C = CFP->getValueAPF();
+SDValue SITargetLowering::getCanonicalConstantFP(
+ SelectionDAG &DAG, const SDLoc &SL, EVT VT, const APFloat &C) const {
// Flush denormals to 0 if not enabled.
- if (C.isDenormal()) {
- EVT VT = N->getValueType(0);
- EVT SVT = VT.getScalarType();
- if (SVT == MVT::f32 && !Subtarget->hasFP32Denormals())
- return DAG.getConstantFP(0.0, SDLoc(N), VT);
-
- if (SVT == MVT::f64 && !Subtarget->hasFP64Denormals())
- return DAG.getConstantFP(0.0, SDLoc(N), VT);
-
- if (SVT == MVT::f16 && !Subtarget->hasFP16Denormals())
- return DAG.getConstantFP(0.0, SDLoc(N), VT);
- }
+ if (C.isDenormal() && !denormalsEnabledForType(VT))
+ return DAG.getConstantFP(0.0, SL, VT);
if (C.isNaN()) {
- EVT VT = N->getValueType(0);
APFloat CanonicalQNaN = APFloat::getQNaN(C.getSemantics());
if (C.isSignaling()) {
// Quiet a signaling NaN.
- return DAG.getConstantFP(CanonicalQNaN, SDLoc(N), VT);
+ // FIXME: Is this supposed to preserve payload bits?
+ return DAG.getConstantFP(CanonicalQNaN, SL, VT);
}
// Make sure it is the canonical NaN bitpattern.
@@ -6900,10 +6872,32 @@ SDValue SITargetLowering::performFCanoni
// TODO: Can we use -1 as the canonical NaN value since it's an inline
// immediate?
if (C.bitcastToAPInt() != CanonicalQNaN.bitcastToAPInt())
- return DAG.getConstantFP(CanonicalQNaN, SDLoc(N), VT);
+ return DAG.getConstantFP(CanonicalQNaN, SL, VT);
+ }
+
+ // Already canonical.
+ return DAG.getConstantFP(C, SL, VT);
+}
+
+SDValue SITargetLowering::performFCanonicalizeCombine(
+ SDNode *N,
+ DAGCombinerInfo &DCI) const {
+ SelectionDAG &DAG = DCI.DAG;
+ SDValue N0 = N->getOperand(0);
+
+ // fcanonicalize undef -> qnan
+ if (N0.isUndef()) {
+ EVT VT = N->getValueType(0);
+ APFloat QNaN = APFloat::getQNaN(SelectionDAG::EVTToAPFloatSemantics(VT));
+ return DAG.getConstantFP(QNaN, SDLoc(N), VT);
+ }
+
+ if (ConstantFPSDNode *CFP = isConstOrConstSplatFP(N0)) {
+ EVT VT = N->getValueType(0);
+ return getCanonicalConstantFP(DAG, SDLoc(N), VT, CFP->getValueAPF());
}
- return N0;
+ return isCanonicalized(DAG, N0) ? N0 : SDValue();
}
static unsigned minMaxOpcToMin3Max3Opc(unsigned Opc) {
Modified: llvm/trunk/lib/Target/AMDGPU/SIISelLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIISelLowering.h?rev=339070&r1=339069&r2=339070&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/SIISelLowering.h (original)
+++ llvm/trunk/lib/Target/AMDGPU/SIISelLowering.h Mon Aug 6 15:10:26 2018
@@ -130,6 +130,8 @@ private:
SDValue performXorCombine(SDNode *N, DAGCombinerInfo &DCI) const;
SDValue performZeroExtendCombine(SDNode *N, DAGCombinerInfo &DCI) const;
SDValue performClassCombine(SDNode *N, DAGCombinerInfo &DCI) const;
+ SDValue getCanonicalConstantFP(SelectionDAG &DAG, const SDLoc &SL, EVT VT,
+ const APFloat &C) const;
SDValue performFCanonicalizeCombine(SDNode *N, DAGCombinerInfo &DCI) const;
SDValue performFPMed3ImmCombine(SelectionDAG &DAG, const SDLoc &SL,
More information about the llvm-commits
mailing list