diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/llvm/lib/CodeGen/MachineInstr.cpp @@ -1234,14 +1234,14 @@ const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo(); const MachineFrameInfo &MFI = MF->getFrameInfo(); - // If neither instruction stores to memory, they can't alias in any - // meaningful way, even if they read from the same address. - if (!mayStore() && !Other.mayStore()) + // If both instructions are loads, they can't alias in any meaningful way, + // even if they read from the same address. + if (mayLoad() && !mayStore() && Other.mayLoad() && !Other.mayStore()) return false; // Both instructions must be memory operations to be able to alias. if (!mayLoadOrStore() || !Other.mayLoadOrStore()) - return false; + return true; // Let the target decide if memory accesses cannot possibly overlap. if (TII->areMemAccessesTriviallyDisjoint(*this, Other))