[PATCH] D49966: [X86] Performing DAG pruning before selection of LEA instructions.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 29 22:04:46 PDT 2018


craig.topper added inline comments.


================
Comment at: lib/Target/X86/X86ISelDAGToDAG.cpp:747
+      SDValue NewAdd = CurDAG->getNode(ISD::ADD, DL, VT, OpsAdd);
+      CurDAG->ReplaceAllUsesOfValueWith(SDValue(N, 0), NewAdd);
+      return true;
----------------
You can't call ReplaceAllUses with the caller holding an iterator pointing to the node after N. The replacement can trigger a CSE update that can invalidate the iterator.

You eventually need to delete N and the subtract once you've replaced it. I'm not sure anything will remove it before it goes through instruction selection. But the iterator in the caller makes that hard. You can't delete N until the iterator is moved past it. But you can't delete the subtract instruction because the iterator might be pointing at it. So I think if this optimization makes any changes, you need to call RemoveDeadNodes after the loop. Since that would be the only time it's safe to remove both.


================
Comment at: lib/Target/X86/X86ISelDAGToDAG.cpp:769
                                     N->getOperand(0), N->getOperand(1));
       --I;
       CurDAG->ReplaceAllUsesOfValueWith(SDValue(N, 0), Res);
----------------
Your new code needs to do the --I, Replace, ++I, Delete that's done here. Otherwise I might get invalidated by the Delete.


Repository:
  rL LLVM

https://reviews.llvm.org/D49966





More information about the llvm-commits mailing list