Skip to content

Commit 3ec1b1a

Browse files
committed
[DAG] visitFP_EXTEND - use FoldConstantArithmetic to attempt to constant fold
Don't rely on isConstantFPBuildVectorOrConstantFP followed by getNode() will constant fold - FoldConstantArithmetic will do all of this for us.
1 parent 3a1df05 commit 3ec1b1a

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18230,42 +18230,40 @@ SDValue DAGCombiner::visitFP_ROUND(SDNode *N) {
1823018230
SDValue DAGCombiner::visitFP_EXTEND(SDNode *N) {
1823118231
SDValue N0 = N->getOperand(0);
1823218232
EVT VT = N->getValueType(0);
18233+
SDLoc DL(N);
1823318234

1823418235
if (VT.isVector())
18235-
if (SDValue FoldedVOp = SimplifyVCastOp(N, SDLoc(N)))
18236+
if (SDValue FoldedVOp = SimplifyVCastOp(N, DL))
1823618237
return FoldedVOp;
1823718238

1823818239
// If this is fp_round(fpextend), don't fold it, allow ourselves to be folded.
18239-
if (N->hasOneUse() &&
18240-
N->use_begin()->getOpcode() == ISD::FP_ROUND)
18240+
if (N->hasOneUse() && N->use_begin()->getOpcode() == ISD::FP_ROUND)
1824118241
return SDValue();
1824218242

1824318243
// fold (fp_extend c1fp) -> c1fp
18244-
if (DAG.isConstantFPBuildVectorOrConstantFP(N0))
18245-
return DAG.getNode(ISD::FP_EXTEND, SDLoc(N), VT, N0);
18244+
if (SDValue C = DAG.FoldConstantArithmetic(ISD::FP_EXTEND, DL, VT, {N0}))
18245+
return C;
1824618246

1824718247
// fold (fp_extend (fp16_to_fp op)) -> (fp16_to_fp op)
1824818248
if (N0.getOpcode() == ISD::FP16_TO_FP &&
1824918249
TLI.getOperationAction(ISD::FP16_TO_FP, VT) == TargetLowering::Legal)
18250-
return DAG.getNode(ISD::FP16_TO_FP, SDLoc(N), VT, N0.getOperand(0));
18250+
return DAG.getNode(ISD::FP16_TO_FP, DL, VT, N0.getOperand(0));
1825118251

1825218252
// Turn fp_extend(fp_round(X, 1)) -> x since the fp_round doesn't affect the
1825318253
// value of X.
18254-
if (N0.getOpcode() == ISD::FP_ROUND
18255-
&& N0.getConstantOperandVal(1) == 1) {
18254+
if (N0.getOpcode() == ISD::FP_ROUND && N0.getConstantOperandVal(1) == 1) {
1825618255
SDValue In = N0.getOperand(0);
1825718256
if (In.getValueType() == VT) return In;
1825818257
if (VT.bitsLT(In.getValueType()))
18259-
return DAG.getNode(ISD::FP_ROUND, SDLoc(N), VT,
18260-
In, N0.getOperand(1));
18261-
return DAG.getNode(ISD::FP_EXTEND, SDLoc(N), VT, In);
18258+
return DAG.getNode(ISD::FP_ROUND, DL, VT, In, N0.getOperand(1));
18259+
return DAG.getNode(ISD::FP_EXTEND, DL, VT, In);
1826218260
}
1826318261

1826418262
// fold (fpext (load x)) -> (fpext (fptrunc (extload x)))
1826518263
if (ISD::isNormalLoad(N0.getNode()) && N0.hasOneUse() &&
1826618264
TLI.isLoadExtLegalOrCustom(ISD::EXTLOAD, VT, N0.getValueType())) {
1826718265
LoadSDNode *LN0 = cast<LoadSDNode>(N0);
18268-
SDValue ExtLoad = DAG.getExtLoad(ISD::EXTLOAD, SDLoc(N), VT,
18266+
SDValue ExtLoad = DAG.getExtLoad(ISD::EXTLOAD, DL, VT,
1826918267
LN0->getChain(),
1827018268
LN0->getBasePtr(), N0.getValueType(),
1827118269
LN0->getMemOperand());

0 commit comments

Comments
 (0)