[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:26:31 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))
+ return false;
+ // Dont sink GOT or constant pool loads.
+ if (MI.mayLoad() && !mayLoadFromGOTOrConstantPool(MI))
----------------
DragonDisciple wrote:
Is this conditional reversed?
If it's a load, and it doesn't load from GOT or constant pool, return false.
Looking at the definition, this predicate definitely returns true for GOT/CP loads, so I think this is a logical error.
This was likely copy-pasted from MachineSink, because that's where I saw this first.
https://github.com/llvm/llvm-project/pull/158479
More information about the llvm-commits
mailing list