Skip to content

Commit 2f329d8

Browse files
committed
[DAG] foldConstantFPMath - accept ArrayRef<SDValue> Ops instead of explicit N1/N2 ops
First step towards adding unary/ternary fp ops handling, and not just binops
1 parent 7f34355 commit 2f329d8

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,10 +1919,10 @@ class SelectionDAG {
19191919
SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
19201920
ArrayRef<SDValue> Ops);
19211921

1922-
/// Fold floating-point operations with 2 operands when both operands are
1923-
/// constants and/or undefined.
1922+
/// Fold floating-point operations when all operands are constants and/or
1923+
/// undefined.
19241924
SDValue foldConstantFPMath(unsigned Opcode, const SDLoc &DL, EVT VT,
1925-
SDValue N1, SDValue N2);
1925+
ArrayRef<SDValue> Ops);
19261926

19271927
/// Constant fold a setcc to true or false.
19281928
SDValue FoldSetCC(EVT VT, SDValue N1, SDValue N2, ISD::CondCode Cond,

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6236,7 +6236,7 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
62366236

62376237
// Handle binops special cases.
62386238
if (NumOps == 2) {
6239-
if (SDValue CFP = foldConstantFPMath(Opcode, DL, VT, Ops[0], Ops[1]))
6239+
if (SDValue CFP = foldConstantFPMath(Opcode, DL, VT, Ops))
62406240
return CFP;
62416241

62426242
if (auto *C1 = dyn_cast<ConstantSDNode>(Ops[0])) {
@@ -6429,11 +6429,17 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
64296429
}
64306430

64316431
SDValue SelectionDAG::foldConstantFPMath(unsigned Opcode, const SDLoc &DL,
6432-
EVT VT, SDValue N1, SDValue N2) {
6432+
EVT VT, ArrayRef<SDValue> Ops) {
6433+
// TODO: Add support for unary/ternary fp opcodes.
6434+
if (Ops.size() != 2)
6435+
return SDValue();
6436+
64336437
// TODO: We don't do any constant folding for strict FP opcodes here, but we
64346438
// should. That will require dealing with a potentially non-default
64356439
// rounding mode, checking the "opStatus" return value from the APFloat
64366440
// math calculations, and possibly other variations.
6441+
SDValue N1 = Ops[0];
6442+
SDValue N2 = Ops[1];
64376443
ConstantFPSDNode *N1CFP = isConstOrConstSplatFP(N1, /*AllowUndefs*/ false);
64386444
ConstantFPSDNode *N2CFP = isConstOrConstSplatFP(N2, /*AllowUndefs*/ false);
64396445
if (N1CFP && N2CFP) {

0 commit comments

Comments
 (0)