[PATCH] D149136: [LICM] Don't duplicate instructions just because they're free

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 25 04:35:44 PDT 2023


mkazantsev added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/LICM.cpp:1379
 
-  return CostI == TargetTransformInfo::TCC_Free;
+  return false;
 }
----------------
This function has a very clear semantics of checking cost, and I don't think that legality concerns should be taken into account here. The legality check seems missing here:
```
      // Check to see if we can sink this instruction to the exit blocks
      // of the loop.  We can do this if the all users of the instruction are
      // outside of the loop.  In this case, it doesn't even matter if the
      // operands of the instruction are loop invariant.
      //
      bool FreeInLoop = false;
      bool LoopNestMode = OutermostLoop != nullptr;
      if (!I.mayHaveSideEffects() &&
          isNotUsedOrFreeInLoop(I, LoopNestMode ? OutermostLoop : CurLoop,
                                SafetyInfo, TTI, FreeInLoop, LoopNestMode) &&
          canSinkOrHoistInst(I, AA, DT, CurLoop, MSSAU, true, Flags, ORE)) {
        if (sink(I, LI, DT, CurLoop, SafetyInfo, MSSAU, ORE)) {
          if (!FreeInLoop) {
            ++II;
            salvageDebugInfo(I);
            eraseInstruction(I, *SafetyInfo, MSSAU);
          }
          Changed = true;
        }
      }
```
There should be check on legality of duplication somewhere around here.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149136/new/

https://reviews.llvm.org/D149136



More information about the llvm-commits mailing list