@@ -1326,10 +1326,14 @@ static int alignTo(int Num, int PowOf2) {
1326
1326
static bool mayAlias (MachineInstr &MIa,
1327
1327
SmallVectorImpl<MachineInstr *> &MemInsns,
1328
1328
AliasAnalysis *AA) {
1329
- for (MachineInstr *MIb : MemInsns)
1330
- if (MIa.mayAlias (AA, *MIb, /* UseTBAA*/ false ))
1329
+ for (MachineInstr *MIb : MemInsns) {
1330
+ if (MIa.mayAlias (AA, *MIb, /* UseTBAA*/ false )) {
1331
+ LLVM_DEBUG (dbgs () << " Aliasing with: " ; MIb->dump ());
1331
1332
return true ;
1333
+ }
1334
+ }
1332
1335
1336
+ LLVM_DEBUG (dbgs () << " No aliases found\n " );
1333
1337
return false ;
1334
1338
}
1335
1339
@@ -1757,9 +1761,11 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
1757
1761
// Remember any instructions that read/write memory between FirstMI and MI.
1758
1762
SmallVector<MachineInstr *, 4 > MemInsns;
1759
1763
1764
+ LLVM_DEBUG (dbgs () << " Find match for: " ; FirstMI.dump ());
1760
1765
for (unsigned Count = 0 ; MBBI != E && Count < Limit;
1761
1766
MBBI = next_nodbg (MBBI, E)) {
1762
1767
MachineInstr &MI = *MBBI;
1768
+ LLVM_DEBUG (dbgs () << " Analysing 2nd insn: " ; MI.dump ());
1763
1769
1764
1770
UsedInBetween.accumulate (MI);
1765
1771
@@ -1859,6 +1865,8 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
1859
1865
LiveRegUnits::accumulateUsedDefed (MI, ModifiedRegUnits,
1860
1866
UsedRegUnits, TRI);
1861
1867
MemInsns.push_back (&MI);
1868
+ LLVM_DEBUG (dbgs () << " Offset doesn't fit in immediate, "
1869
+ << " keep looking.\n " );
1862
1870
continue ;
1863
1871
}
1864
1872
// If the alignment requirements of the paired (scaled) instruction
@@ -1868,6 +1876,9 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
1868
1876
LiveRegUnits::accumulateUsedDefed (MI, ModifiedRegUnits,
1869
1877
UsedRegUnits, TRI);
1870
1878
MemInsns.push_back (&MI);
1879
+ LLVM_DEBUG (dbgs ()
1880
+ << " Offset doesn't fit due to alignment requirements, "
1881
+ << " keep looking.\n " );
1871
1882
continue ;
1872
1883
}
1873
1884
}
@@ -1884,14 +1895,22 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
1884
1895
const bool SameLoadReg = MayLoad && TRI->isSuperOrSubRegisterEq (
1885
1896
Reg, getLdStRegOp (MI).getReg ());
1886
1897
1887
- // If the Rt of the second instruction was not modified or used between
1888
- // the two instructions and none of the instructions between the second
1889
- // and first alias with the second, we can combine the second into the
1890
- // first.
1891
- if (ModifiedRegUnits.available (getLdStRegOp (MI).getReg ()) &&
1892
- !(MI.mayLoad () && !SameLoadReg &&
1893
- !UsedRegUnits.available (getLdStRegOp (MI).getReg ())) &&
1894
- !mayAlias (MI, MemInsns, AA)) {
1898
+ // If the Rt of the second instruction (destination register of the
1899
+ // load) was not modified or used between the two instructions and none
1900
+ // of the instructions between the second and first alias with the
1901
+ // second, we can combine the second into the first.
1902
+ bool RtNotModified =
1903
+ ModifiedRegUnits.available (getLdStRegOp (MI).getReg ());
1904
+ bool RtNotUsed = !(MI.mayLoad () && !SameLoadReg &&
1905
+ !UsedRegUnits.available (getLdStRegOp (MI).getReg ()));
1906
+
1907
+ LLVM_DEBUG (dbgs () << " Checking, can combine 2nd into 1st insn:\n "
1908
+ << " Reg '" << getLdStRegOp (MI) << " ' not modified: "
1909
+ << (RtNotModified ? " true" : " false" ) << " \n "
1910
+ << " Reg '" << getLdStRegOp (MI) << " ' not used: "
1911
+ << (RtNotUsed ? " true" : " false" ) << " \n " );
1912
+
1913
+ if (RtNotModified && RtNotUsed && !mayAlias (MI, MemInsns, AA)) {
1895
1914
// For pairs loading into the same reg, try to find a renaming
1896
1915
// opportunity to allow the renaming of Reg between FirstMI and MI
1897
1916
// and combine MI into FirstMI; otherwise bail and keep looking.
@@ -1904,6 +1923,8 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
1904
1923
LiveRegUnits::accumulateUsedDefed (MI, ModifiedRegUnits,
1905
1924
UsedRegUnits, TRI);
1906
1925
MemInsns.push_back (&MI);
1926
+ LLVM_DEBUG (dbgs () << " Can't find reg for renaming, "
1927
+ << " keep looking.\n " );
1907
1928
continue ;
1908
1929
}
1909
1930
Flags.setRenameReg (*RenameReg);
@@ -1919,10 +1940,15 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
1919
1940
// between the two instructions and none of the instructions between the
1920
1941
// first and the second alias with the first, we can combine the first
1921
1942
// into the second.
1922
- if (!(MayLoad &&
1923
- !UsedRegUnits.available (getLdStRegOp (FirstMI).getReg ())) &&
1924
- !mayAlias (FirstMI, MemInsns, AA)) {
1943
+ RtNotModified = !(
1944
+ MayLoad && !UsedRegUnits.available (getLdStRegOp (FirstMI).getReg ()));
1925
1945
1946
+ LLVM_DEBUG (dbgs () << " Checking, can combine 1st into 2nd insn:\n "
1947
+ << " Reg '" << getLdStRegOp (FirstMI)
1948
+ << " ' not modified: "
1949
+ << (RtNotModified ? " true" : " false" ) << " \n " );
1950
+
1951
+ if (RtNotModified && !mayAlias (FirstMI, MemInsns, AA)) {
1926
1952
if (ModifiedRegUnits.available (getLdStRegOp (FirstMI).getReg ())) {
1927
1953
Flags.setMergeForward (true );
1928
1954
Flags.clearRenameReg ();
@@ -1938,8 +1964,8 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
1938
1964
MBBIWithRenameReg = MBBI;
1939
1965
}
1940
1966
}
1941
- // Unable to combine these instructions due to interference in between.
1942
- // Keep looking.
1967
+ LLVM_DEBUG ( dbgs () << " Unable to combine these instructions due to "
1968
+ << " interference in between, keep looking.\n " );
1943
1969
}
1944
1970
}
1945
1971
@@ -1948,16 +1974,20 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
1948
1974
1949
1975
// If the instruction wasn't a matching load or store. Stop searching if we
1950
1976
// encounter a call instruction that might modify memory.
1951
- if (MI.isCall ())
1977
+ if (MI.isCall ()) {
1978
+ LLVM_DEBUG (dbgs () << " Found a call, stop looking.\n " );
1952
1979
return E;
1980
+ }
1953
1981
1954
1982
// Update modified / uses register units.
1955
1983
LiveRegUnits::accumulateUsedDefed (MI, ModifiedRegUnits, UsedRegUnits, TRI);
1956
1984
1957
1985
// Otherwise, if the base register is modified, we have no match, so
1958
1986
// return early.
1959
- if (!ModifiedRegUnits.available (BaseReg))
1987
+ if (!ModifiedRegUnits.available (BaseReg)) {
1988
+ LLVM_DEBUG (dbgs () << " Base reg is modified, stop looking.\n " );
1960
1989
return E;
1990
+ }
1961
1991
1962
1992
// Update list of instructions that read/write memory.
1963
1993
if (MI.mayLoadOrStore ())
0 commit comments