[llvm] [CodeGen] Do not remove IMPLICIT_DEF unless all uses have undef flag added (PR #188133)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 27 04:25:56 PDT 2026


================
@@ -102,29 +102,44 @@ void ProcessImplicitDefs::processImplicitDef(MachineInstr *MI) {
   }
 
   // This is a physreg implicit-def.
-  // Look for the first instruction to use or define an alias.
-  MachineBasicBlock::instr_iterator UserMI = MI->getIterator();
-  MachineBasicBlock::instr_iterator UserE = MI->getParent()->instr_end();
-  bool Found = false;
-  for (++UserMI; UserMI != UserE; ++UserMI) {
-    for (MachineOperand &MO : UserMI->operands()) {
+  // Try to add undef flag to all uses.  If all uses are updated remove
+  // implicit-def.
+  MachineBasicBlock::instr_iterator SearchMI = MI->getIterator();
+  MachineBasicBlock::instr_iterator SearchE = MI->getParent()->instr_end();
+  bool ImplicitDefIsDead = false;
+  bool SearchedWholeBlock = true;
+  constexpr unsigned SearchLimit = 60000;
+  unsigned Count = 0;
+  for (++SearchMI; SearchMI != SearchE; ++SearchMI) {
+    bool DefinesReg = false;
----------------
jayfoad wrote:

Don't need a separate bool for this. You can just set ImplicitDefIsDead in the operand loop, and do `if (ImplicitDefIsDead) break` after the operand loop.

https://github.com/llvm/llvm-project/pull/188133


More information about the llvm-commits mailing list