[llvm] [MachineLICM] Rematerialize instructions that may be hoisted before LICM (PR #158479)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 23 07:33:04 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))
----------------
dianqk wrote:
Well, it does seem that way. I'll recheck this.
https://github.com/llvm/llvm-project/pull/158479
More information about the llvm-commits
mailing list