Skip to content

Commit 53b597c

Browse files
committed
[SelectionDAG] Merge constant SDNode arithmetic into foldConstantArithmetic
This is the second patch as part of https://bugs.llvm.org/show_bug.cgi?id=36544 Merging in the ConstantSDNode variant of FoldConstantArithmetic. After this, I will begin merging in FoldConstantVectorArithmetic I've ensured this patch can build & pass all lit tests in Windows and Linux environments. Patch by @justice_adams (Justice Adams) Differential Revision: https://reviews.llvm.org/D74881
1 parent 7b0a568 commit 53b597c

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,10 +1503,6 @@ class SelectionDAG {
15031503
SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
15041504
ArrayRef<SDValue> Ops);
15051505

1506-
SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
1507-
const ConstantSDNode *C1,
1508-
const ConstantSDNode *C2);
1509-
15101506
SDValue FoldConstantVectorArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT,
15111507
ArrayRef<SDValue> Ops,
15121508
const SDNodeFlags Flags = SDNodeFlags());

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4820,17 +4820,6 @@ static llvm::Optional<APInt> FoldValue(unsigned Opcode, const APInt &C1,
48204820
return llvm::None;
48214821
}
48224822

4823-
SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
4824-
EVT VT, const ConstantSDNode *C1,
4825-
const ConstantSDNode *C2) {
4826-
if (C1->isOpaque() || C2->isOpaque())
4827-
return SDValue();
4828-
if (Optional<APInt> Folded =
4829-
FoldValue(Opcode, C1->getAPIntValue(), C2->getAPIntValue()))
4830-
return getConstant(Folded.getValue(), DL, VT);
4831-
return SDValue();
4832-
}
4833-
48344823
SDValue SelectionDAG::FoldSymbolOffset(unsigned Opcode, EVT VT,
48354824
const GlobalAddressSDNode *GA,
48364825
const SDNode *N2) {
@@ -4899,7 +4888,15 @@ SDValue SelectionDAG::FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL,
48994888
// Handle the case of two scalars.
49004889
if (auto *C1 = dyn_cast<ConstantSDNode>(N1)) {
49014890
if (auto *C2 = dyn_cast<ConstantSDNode>(N2)) {
4902-
SDValue Folded = FoldConstantArithmetic(Opcode, DL, VT, C1, C2);
4891+
if (C1->isOpaque() || C2->isOpaque())
4892+
return SDValue();
4893+
4894+
Optional<APInt> FoldAttempt =
4895+
FoldValue(Opcode, C1->getAPIntValue(), C2->getAPIntValue());
4896+
if (!FoldAttempt)
4897+
return SDValue();
4898+
4899+
SDValue Folded = getConstant(FoldAttempt.getValue(), DL, VT);
49034900
assert((!Folded || !VT.isVector()) &&
49044901
"Can't fold vectors ops with scalar operands");
49054902
return Folded;

0 commit comments

Comments
 (0)