Skip to content

Commit 664f84e

Browse files
committed
[FPEnv][SelectionDAG] Refactor strict FP node construction
Small refactoring in visitConstrainedFPIntrinsic that should make it easier to create DAG nodes requiring extra arguments. That is the case currently only for STRICT_FP_ROUND, but may be the case for additional nodes (in particular compares) in the future. Extracted from the patch for D69281. NFC.
1 parent 9ba1661 commit 664f84e

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6894,6 +6894,26 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
68946894
void SelectionDAGBuilder::visitConstrainedFPIntrinsic(
68956895
const ConstrainedFPIntrinsic &FPI) {
68966896
SDLoc sdl = getCurSDLoc();
6897+
6898+
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
6899+
SmallVector<EVT, 4> ValueVTs;
6900+
ComputeValueVTs(TLI, DAG.getDataLayout(), FPI.getType(), ValueVTs);
6901+
ValueVTs.push_back(MVT::Other); // Out chain
6902+
6903+
SDValue Chain = getRoot();
6904+
SmallVector<SDValue, 4> Opers;
6905+
Opers.push_back(Chain);
6906+
if (FPI.isUnaryOp()) {
6907+
Opers.push_back(getValue(FPI.getArgOperand(0)));
6908+
} else if (FPI.isTernaryOp()) {
6909+
Opers.push_back(getValue(FPI.getArgOperand(0)));
6910+
Opers.push_back(getValue(FPI.getArgOperand(1)));
6911+
Opers.push_back(getValue(FPI.getArgOperand(2)));
6912+
} else {
6913+
Opers.push_back(getValue(FPI.getArgOperand(0)));
6914+
Opers.push_back(getValue(FPI.getArgOperand(1)));
6915+
}
6916+
68976917
unsigned Opcode;
68986918
switch (FPI.getIntrinsicID()) {
68996919
default: llvm_unreachable("Impossible intrinsic"); // Can't reach here.
@@ -6923,6 +6943,8 @@ void SelectionDAGBuilder::visitConstrainedFPIntrinsic(
69236943
break;
69246944
case Intrinsic::experimental_constrained_fptrunc:
69256945
Opcode = ISD::STRICT_FP_ROUND;
6946+
Opers.push_back(DAG.getTargetConstant(0, sdl,
6947+
TLI.getPointerTy(DAG.getDataLayout())));
69266948
break;
69276949
case Intrinsic::experimental_constrained_fpext:
69286950
Opcode = ISD::STRICT_FP_EXTEND;
@@ -6994,31 +7016,9 @@ void SelectionDAGBuilder::visitConstrainedFPIntrinsic(
69947016
Opcode = ISD::STRICT_FTRUNC;
69957017
break;
69967018
}
6997-
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
6998-
SDValue Chain = getRoot();
6999-
SmallVector<EVT, 4> ValueVTs;
7000-
ComputeValueVTs(TLI, DAG.getDataLayout(), FPI.getType(), ValueVTs);
7001-
ValueVTs.push_back(MVT::Other); // Out chain
70027019

70037020
SDVTList VTs = DAG.getVTList(ValueVTs);
7004-
SDValue Result;
7005-
if (Opcode == ISD::STRICT_FP_ROUND)
7006-
Result = DAG.getNode(Opcode, sdl, VTs,
7007-
{ Chain, getValue(FPI.getArgOperand(0)),
7008-
DAG.getTargetConstant(0, sdl,
7009-
TLI.getPointerTy(DAG.getDataLayout())) });
7010-
else if (FPI.isUnaryOp())
7011-
Result = DAG.getNode(Opcode, sdl, VTs,
7012-
{ Chain, getValue(FPI.getArgOperand(0)) });
7013-
else if (FPI.isTernaryOp())
7014-
Result = DAG.getNode(Opcode, sdl, VTs,
7015-
{ Chain, getValue(FPI.getArgOperand(0)),
7016-
getValue(FPI.getArgOperand(1)),
7017-
getValue(FPI.getArgOperand(2)) });
7018-
else
7019-
Result = DAG.getNode(Opcode, sdl, VTs,
7020-
{ Chain, getValue(FPI.getArgOperand(0)),
7021-
getValue(FPI.getArgOperand(1)) });
7021+
SDValue Result = DAG.getNode(Opcode, sdl, VTs, Opers);
70227022

70237023
if (FPI.getExceptionBehavior() !=
70247024
ConstrainedFPIntrinsic::ExceptionBehavior::ebIgnore) {

0 commit comments

Comments
 (0)