[llvm] [MachineLICM] Rematerialize instructions that may be hoisted before LICM (PR #158479)
James Nagurne via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 19 12:34:06 PDT 2025
================
@@ -167,3 +167,48 @@ bool llvm::isCycleInvariant(const MachineCycle *Cycle, MachineInstr &I) {
// If we got this far, the instruction is cycle invariant!
return true;
}
+
+bool llvm::mayLoadFromGOTOrConstantPool(MachineInstr &MI) {
+ assert(MI.mayLoad() && "Expected MI that loads!");
+
+ // If we lost memory operands, conservatively assume that the instruction
+ // reads from everything..
+ if (MI.memoperands_empty())
+ return true;
+
+ for (MachineMemOperand *MemOp : MI.memoperands())
+ if (const PseudoSourceValue *PSV = MemOp->getPseudoValue())
+ if (PSV->isGOT() || PSV->isConstantPool())
+ return true;
+
+ return false;
+}
+
+bool llvm::isSinkIntoCycleCandidate(MachineInstr &MI, MachineCycle *Cycle,
+ MachineRegisterInfo *MRI,
+ const TargetInstrInfo *TII) {
+ // Not sinking meta instruction.
+ if (MI.isMetaInstruction())
+ return false;
+ // Instruction not a candidate for this target.
+ if (!TII->shouldSink(MI))
+ return false;
+ // Instruction is not cycle invariant.
+ if (!isCycleInvariant(Cycle, MI))
+ return false;
+ // Instruction not safe to move.
+ bool DontMoveAcrossStore = true;
+ if (!MI.isSafeToMove(DontMoveAcrossStore))
----------------
DragonDisciple wrote:
Is there any way to make this less restrictive than always assuming an aliasing store? Some way to do analysis such that we can determine that moving across a store isn't an issue? In my personal case, which is a matrix multiplication loading from/storing to global arrays, this condition blocks sinking.
Pre-ISel, PRE/LICM is happy to hoist everything out and cause problems, but once we get here, we would be unable to sink things back in.
https://github.com/llvm/llvm-project/pull/158479
More information about the llvm-commits
mailing list