[llvm] 2f329d8 - [DAG] foldConstantFPMath - accept ArrayRef<SDValue> Ops instead of explicit N1/N2 ops
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 17 08:32:31 PDT 2023
Author: Simon Pilgrim
Date: 2023-10-17T16:31:46+01:00
New Revision: 2f329d88bc2e6e6fc1d79a723bf150df49e04684
URL: https://github.com/llvm/llvm-project/commit/2f329d88bc2e6e6fc1d79a723bf150df49e04684
DIFF: https://github.com/llvm/llvm-project/commit/2f329d88bc2e6e6fc1d79a723bf150df49e04684.diff
LOG: [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
Added:
Modified:
llvm/include/llvm/CodeGen/SelectionDAG.h
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h
index 2c629f3f96a0c3d..e867448b9d55124 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAG.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -1919,10 +1919,10 @@ class SelectionDAG {
SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
ArrayRef<SDValue> Ops);
- /// Fold floating-point operations with 2 operands when both operands are
- /// constants and/or undefined.
+ /// Fold floating-point operations when all operands are constants and/or
+ /// undefined.
SDValue foldConstantFPMath(unsigned Opcode, const SDLoc &DL, EVT VT,
- SDValue N1, SDValue N2);
+ ArrayRef<SDValue> Ops);
/// Constant fold a setcc to true or false.
SDValue FoldSetCC(EVT VT, SDValue N1, SDValue N2, ISD::CondCode Cond,
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 3f06d0bd4eaa1d5..01da5c0ec49eeb4 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -6236,7 +6236,7 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
// Handle binops special cases.
if (NumOps == 2) {
- if (SDValue CFP = foldConstantFPMath(Opcode, DL, VT, Ops[0], Ops[1]))
+ if (SDValue CFP = foldConstantFPMath(Opcode, DL, VT, Ops))
return CFP;
if (auto *C1 = dyn_cast<ConstantSDNode>(Ops[0])) {
@@ -6429,11 +6429,17 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
}
SDValue SelectionDAG::foldConstantFPMath(unsigned Opcode, const SDLoc &DL,
- EVT VT, SDValue N1, SDValue N2) {
+ EVT VT, ArrayRef<SDValue> Ops) {
+ // TODO: Add support for unary/ternary fp opcodes.
+ if (Ops.size() != 2)
+ return SDValue();
+
// TODO: We don't do any constant folding for strict FP opcodes here, but we
// should. That will require dealing with a potentially non-default
// rounding mode, checking the "opStatus" return value from the APFloat
// math calculations, and possibly other variations.
+ SDValue N1 = Ops[0];
+ SDValue N2 = Ops[1];
ConstantFPSDNode *N1CFP = isConstOrConstSplatFP(N1, /*AllowUndefs*/ false);
ConstantFPSDNode *N2CFP = isConstOrConstSplatFP(N2, /*AllowUndefs*/ false);
if (N1CFP && N2CFP) {
More information about the llvm-commits
mailing list