[PATCH] D31678: [InstCombine] Fix change flag handling to report all IR changes up to the pass manager or preseved analyses

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 4 14:05:13 PDT 2017


craig.topper created this revision.

Currently InstCombine does not report dead code elimination or constant folding during the worklist building up to the pass manager or preserved analysis reporting. With one caveat, constant folding operands does report as a change and forces another iteration of the InstCombine pass. Since the return flag is currently based on iteration count being greater than 1, those modifications would be reported.

This patch adds a change flag to DCE and constant folding in the worklist build. Additionally we no longer treat changes during worklist building as a reason to run another iteration. Now the return value is based on a change flag instead of the iteration count.


https://reviews.llvm.org/D31678

Files:
  lib/Transforms/InstCombine/InstructionCombining.cpp


Index: lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- lib/Transforms/InstCombine/InstructionCombining.cpp
+++ lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3006,6 +3006,7 @@
         ++NumDeadInst;
         DEBUG(dbgs() << "IC: DCE: " << *Inst << '\n');
         Inst->eraseFromParent();
+        MadeIRChange = true;
         continue;
       }
 
@@ -3019,6 +3020,7 @@
           ++NumConstProp;
           if (isInstructionTriviallyDead(Inst, TLI))
             Inst->eraseFromParent();
+          MadeIRChange = true;
           continue;
         }
 
@@ -3142,27 +3144,28 @@
 
   // Lower dbg.declare intrinsics otherwise their value may be clobbered
   // by instcombiner.
-  bool DbgDeclaresChanged = LowerDbgDeclare(F);
+  bool MadeIRChange = LowerDbgDeclare(F);
 
   // Iterate while there is work to do.
   int Iteration = 0;
   for (;;) {
     ++Iteration;
     DEBUG(dbgs() << "\n\nINSTCOMBINE ITERATION #" << Iteration << " on "
                  << F.getName() << "\n");
 
-    bool Changed = prepareICWorklistFromFunction(F, DL, &TLI, Worklist);
+    MadeIRChange |= prepareICWorklistFromFunction(F, DL, &TLI, Worklist);
 
     InstCombiner IC(Worklist, &Builder, F.optForMinSize(), ExpensiveCombines,
                     AA, AC, TLI, DT, DL, LI);
     IC.MaxArraySizeForCombine = MaxArraySize;
-    Changed |= IC.run();
 
-    if (!Changed)
+    if (!IC.run())
       break;
+
+    MadeIRChange = true;
   }
 
-  return DbgDeclaresChanged || Iteration > 1;
+  return MadeIRChange;
 }
 
 PreservedAnalyses InstCombinePass::run(Function &F,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31678.94117.patch
Type: text/x-patch
Size: 1642 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170404/e6314f28/attachment.bin>


More information about the llvm-commits mailing list