Skip to content

Commit 5b38ecf

Browse files
committed
[DAG] BaseIndexOffset::equalBaseIndex - early out on failed matches. NFCI.
If we successfully cast only the first base node as GlobalAddressSDNode / ConstantPoolSDNode / FrameIndexSDNode then we can early out as we know that base won't cast as a later type. Noticed while investigating profiles for potential compile time improvements.
1 parent 43e0723 commit 5b38ecf

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,18 @@ bool BaseIndexOffset::equalBaseIndex(const BaseIndexOffset &Other,
3838
return true;
3939

4040
// Match GlobalAddresses
41-
if (auto *A = dyn_cast<GlobalAddressSDNode>(Base))
41+
if (auto *A = dyn_cast<GlobalAddressSDNode>(Base)) {
4242
if (auto *B = dyn_cast<GlobalAddressSDNode>(Other.Base))
4343
if (A->getGlobal() == B->getGlobal()) {
4444
Off += B->getOffset() - A->getOffset();
4545
return true;
4646
}
4747

48+
return false;
49+
}
50+
4851
// Match Constants
49-
if (auto *A = dyn_cast<ConstantPoolSDNode>(Base))
52+
if (auto *A = dyn_cast<ConstantPoolSDNode>(Base)) {
5053
if (auto *B = dyn_cast<ConstantPoolSDNode>(Other.Base)) {
5154
bool IsMatch =
5255
A->isMachineConstantPoolEntry() == B->isMachineConstantPoolEntry();
@@ -62,7 +65,8 @@ bool BaseIndexOffset::equalBaseIndex(const BaseIndexOffset &Other,
6265
}
6366
}
6467

65-
const MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
68+
return false;
69+
}
6670

6771
// Match FrameIndexes.
6872
if (auto *A = dyn_cast<FrameIndexSDNode>(Base))
@@ -73,6 +77,7 @@ bool BaseIndexOffset::equalBaseIndex(const BaseIndexOffset &Other,
7377
// Non-equal FrameIndexes - If both frame indices are fixed
7478
// we know their relative offsets and can compare them. Otherwise
7579
// we must be conservative.
80+
const MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
7681
if (MFI.isFixedObjectIndex(A->getIndex()) &&
7782
MFI.isFixedObjectIndex(B->getIndex())) {
7883
Off += MFI.getObjectOffset(B->getIndex()) -
@@ -81,6 +86,7 @@ bool BaseIndexOffset::equalBaseIndex(const BaseIndexOffset &Other,
8186
}
8287
}
8388
}
89+
8490
return false;
8591
}
8692

0 commit comments

Comments
 (0)