[InstCombine] Report change in non zero phi transform
authorNikita Popov <nikita.ppv@gmail.com>
Sun, 29 Mar 2020 20:10:31 +0000 (22:10 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 31 Mar 2020 19:52:40 +0000 (21:52 +0200)
We need to inform InstCombine (and transitively the pass manager)
that we changed an instruction.

llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp

index 6c2aead..9cdb68d 100644 (file)
@@ -1194,15 +1194,22 @@ Instruction *InstCombiner::visitPHINode(PHINode &PN) {
     if (CmpInst && isa<IntegerType>(PN.getType()) && CmpInst->isEquality() &&
         match(CmpInst->getOperand(1), m_Zero())) {
       ConstantInt *NonZeroConst = nullptr;
+      bool MadeChange = false;
       for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) {
         Instruction *CtxI = PN.getIncomingBlock(i)->getTerminator();
         Value *VA = PN.getIncomingValue(i);
         if (isKnownNonZero(VA, DL, 0, &AC, CtxI, &DT)) {
           if (!NonZeroConst)
             NonZeroConst = GetAnyNonZeroConstInt(PN);
-          PN.setIncomingValue(i, NonZeroConst);
+
+          if (NonZeroConst != VA) {
+            PN.setIncomingValue(i, NonZeroConst);
+            MadeChange = true;
+          }
         }
       }
+      if (MadeChange)
+        return &PN;
     }
   }