[LICM] Delay fetching of preheader (NFC)
authorNikita Popov <npopov@redhat.com>
Fri, 10 Mar 2023 15:15:49 +0000 (16:15 +0100)
committerNikita Popov <npopov@redhat.com>
Fri, 10 Mar 2023 15:16:48 +0000 (16:16 +0100)
Only fetch preheader once we want to actually hoist. It turns out
that calculating the preheader is expensive enough to affect
overall compile-time if you do it for every single instruction.

Addresses the compile-time regression from D143726.

llvm/lib/Transforms/Scalar/LICM.cpp

index a79e395..b181fae 100644 (file)
@@ -2415,8 +2415,6 @@ bool pointerInvalidatedByBlock(BasicBlock &BB, MemorySSA &MSSA, MemoryUse &MU) {
 
 static bool hoistMinMax(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo,
                         MemorySSAUpdater &MSSAU) {
-  auto *Preheader = L.getLoopPreheader();
-  assert(Preheader && "Loop is not in simplify form?");
   bool Inverse = false;
   bool IsLogical = false;
   using namespace PatternMatch;
@@ -2465,6 +2463,8 @@ static bool hoistMinMax(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo,
   Intrinsic::ID id = ICmpInst::isSigned(P1)
                          ? (UseMin ? Intrinsic::smin : Intrinsic::smax)
                          : (UseMin ? Intrinsic::umin : Intrinsic::umax);
+  auto *Preheader = L.getLoopPreheader();
+  assert(Preheader && "Loop is not in simplify form?");
   IRBuilder<> Builder(Preheader->getTerminator());
   // We are about to create a new guaranteed use for RHS2 which might not exist
   // before (if it was a non-taken input of logical and/or instruction). If it