[llvm] Fix incorrect codegen with respect to GEPs #85333 (PR #88440)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 28 22:30:04 PDT 2024


================
@@ -719,21 +719,22 @@ GVNSink::analyzeInstructionForSinking(LockstepReverseIterator &LRI,
   // try and continue making progress.
   Instruction *I0 = NewInsts[0];
 
-  // If all instructions that are going to participate don't have the same
-  // number of operands, we can't do any useful PHI analysis for all operands.
-  auto hasDifferentNumOperands = [&I0](Instruction *I) {
-    return I->getNumOperands() != I0->getNumOperands();
+  auto hasDifferentOperands = [&I0](Instruction *I) {
+    return !I0->isSameOperationAs(I);
   };
-  if (any_of(NewInsts, hasDifferentNumOperands))
+
+  if (any_of(NewInsts, hasDifferentOperands))
     return std::nullopt;
 
   for (unsigned OpNum = 0, E = I0->getNumOperands(); OpNum != E; ++OpNum) {
     ModelledPHI PHI(NewInsts, OpNum, ActivePreds);
     if (PHI.areAllIncomingValuesSame())
       continue;
-    if (!canReplaceOperandWithVariable(I0, OpNum))
-      // We can 't create a PHI from this instruction!
-      return std::nullopt;
+    for (auto &Candidate : NewInsts) {
----------------
nikic wrote:

This change seems unrelated -- does it have test coverage?

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


More information about the llvm-commits mailing list