@@ -1326,10 +1326,14 @@ static int alignTo(int Num, int PowOf2) {
13261326static bool mayAlias (MachineInstr &MIa,
13271327 SmallVectorImpl<MachineInstr *> &MemInsns,
13281328 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 ());
13311332 return true ;
1333+ }
1334+ }
13321335
1336+ LLVM_DEBUG (dbgs () << " No aliases found\n " );
13331337 return false ;
13341338}
13351339
@@ -1757,9 +1761,11 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
17571761 // Remember any instructions that read/write memory between FirstMI and MI.
17581762 SmallVector<MachineInstr *, 4 > MemInsns;
17591763
1764+ LLVM_DEBUG (dbgs () << " Find match for: " ; FirstMI.dump ());
17601765 for (unsigned Count = 0 ; MBBI != E && Count < Limit;
17611766 MBBI = next_nodbg (MBBI, E)) {
17621767 MachineInstr &MI = *MBBI;
1768+ LLVM_DEBUG (dbgs () << " Analysing 2nd insn: " ; MI.dump ());
17631769
17641770 UsedInBetween.accumulate (MI);
17651771
@@ -1859,6 +1865,8 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
18591865 LiveRegUnits::accumulateUsedDefed (MI, ModifiedRegUnits,
18601866 UsedRegUnits, TRI);
18611867 MemInsns.push_back (&MI);
1868+ LLVM_DEBUG (dbgs () << " Offset doesn't fit in immediate, "
1869+ << " keep looking.\n " );
18621870 continue ;
18631871 }
18641872 // If the alignment requirements of the paired (scaled) instruction
@@ -1868,6 +1876,9 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
18681876 LiveRegUnits::accumulateUsedDefed (MI, ModifiedRegUnits,
18691877 UsedRegUnits, TRI);
18701878 MemInsns.push_back (&MI);
1879+ LLVM_DEBUG (dbgs ()
1880+ << " Offset doesn't fit due to alignment requirements, "
1881+ << " keep looking.\n " );
18711882 continue ;
18721883 }
18731884 }
@@ -1884,14 +1895,22 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
18841895 const bool SameLoadReg = MayLoad && TRI->isSuperOrSubRegisterEq (
18851896 Reg, getLdStRegOp (MI).getReg ());
18861897
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)) {
18951914 // For pairs loading into the same reg, try to find a renaming
18961915 // opportunity to allow the renaming of Reg between FirstMI and MI
18971916 // and combine MI into FirstMI; otherwise bail and keep looking.
@@ -1904,6 +1923,8 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
19041923 LiveRegUnits::accumulateUsedDefed (MI, ModifiedRegUnits,
19051924 UsedRegUnits, TRI);
19061925 MemInsns.push_back (&MI);
1926+ LLVM_DEBUG (dbgs () << " Can't find reg for renaming, "
1927+ << " keep looking.\n " );
19071928 continue ;
19081929 }
19091930 Flags.setRenameReg (*RenameReg);
@@ -1919,10 +1940,15 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
19191940 // between the two instructions and none of the instructions between the
19201941 // first and the second alias with the first, we can combine the first
19211942 // 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 ()));
19251945
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)) {
19261952 if (ModifiedRegUnits.available (getLdStRegOp (FirstMI).getReg ())) {
19271953 Flags.setMergeForward (true );
19281954 Flags.clearRenameReg ();
@@ -1938,8 +1964,8 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
19381964 MBBIWithRenameReg = MBBI;
19391965 }
19401966 }
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 " );
19431969 }
19441970 }
19451971
@@ -1948,16 +1974,20 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
19481974
19491975 // If the instruction wasn't a matching load or store. Stop searching if we
19501976 // 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 " );
19521979 return E;
1980+ }
19531981
19541982 // Update modified / uses register units.
19551983 LiveRegUnits::accumulateUsedDefed (MI, ModifiedRegUnits, UsedRegUnits, TRI);
19561984
19571985 // Otherwise, if the base register is modified, we have no match, so
19581986 // return early.
1959- if (!ModifiedRegUnits.available (BaseReg))
1987+ if (!ModifiedRegUnits.available (BaseReg)) {
1988+ LLVM_DEBUG (dbgs () << " Base reg is modified, stop looking.\n " );
19601989 return E;
1990+ }
19611991
19621992 // Update list of instructions that read/write memory.
19631993 if (MI.mayLoadOrStore ())
0 commit comments