From a7322a2171e99fe9c465c3e13c49563b19402ae0 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 10 Mar 2023 16:15:49 +0100 Subject: [PATCH] [LICM] Delay fetching of preheader (NFC) 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index a79e395..b181fae 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -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 -- 2.7.4