[llvm] [InstCombine] Avoid infinite loop when negating phi nodes (PR #104581)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 16 05:23:59 PDT 2024


================
@@ -309,6 +310,9 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) {
     auto *PHI = cast<PHINode>(I);
     SmallVector<Value *, 4> NegatedIncomingValues(PHI->getNumOperands());
     for (auto I : zip(PHI->incoming_values(), NegatedIncomingValues)) {
+      // Don't negate indvars to avoid infinite loops.
+      if (DT.dominates(PHI, std::get<0>(I)))
----------------
nikic wrote:

```suggestion
      if (DT.dominates(PHI->getParent(), std::get<0>(I)))
```
Shouldn't make a difference here, but I don't think using value dominance really makes sense in this context.

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


More information about the llvm-commits mailing list