[llvm] [MachineSink] Add option for aggressive loop sinking (PR #117247)
Jeffrey Byrnes via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 22 13:54:42 PST 2024
================
@@ -1574,6 +1615,149 @@ bool MachineSinking::hasStoreBetween(MachineBasicBlock *From,
return HasAliasedStore;
}
+/// Copy paste from DeadMachineInstructionElimImpl
+
+bool MachineSinking::isDead(const MachineInstr *MI) const {
+ // Instructions without side-effects are dead iff they only define dead regs.
+ // This function is hot and this loop returns early in the common case,
+ // so only perform additional checks before this if absolutely necessary.
+ for (const MachineOperand &MO : MI->all_defs()) {
+ Register Reg = MO.getReg();
+ if (Reg.isPhysical()) {
+ return false;
+ } else {
+ if (MO.isDead()) {
+#ifndef NDEBUG
+ // Basic check on the register. All of them should be 'undef'.
+ for (auto &U : MRI->use_nodbg_operands(Reg))
+ assert(U.isUndef() && "'Undef' use on a 'dead' register is found!");
+#endif
+ continue;
+ }
+ for (const MachineInstr &Use : MRI->use_nodbg_instructions(Reg)) {
----------------
jrbyrnes wrote:
Maybe it's supposed to work but doesn't? Calling hasOneNonDBGUser on the %8 def in `%8:sreg_64 = S_MOV_B64 -1` returns true for the single user `%9:sreg_64 = S_AND_B64 $exec, %8:sreg_64, implicit-def dead $scc`
https://godbolt.org/z/MMMnaTxdP -- !(MRI->hasAtMostUserInstrs(Reg,0) seems to have the behavior we want though.
https://github.com/llvm/llvm-project/pull/117247
More information about the llvm-commits
mailing list