From 64b91defdd5a7a67b235658b26be44edfdabb413 Mon Sep 17 00:00:00 2001 From: Hari Limaye Date: Tue, 29 Oct 2024 12:39:05 +0000 Subject: [PATCH] [FuncSpec] Handle ssa_copy intrinsic calls in InstCostVisitor Look through ssa_copy intrinsic calls when computing codesize bonus for a specialization. Also remove redundant logic to skip computing codesize bonus for ssa_copy intrinsics, now these are considered zero-cost by TTI (in PR#75294). --- llvm/lib/Transforms/IPO/FunctionSpecialization.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp index 919d3143a13f7e..1efec22624dd4f 100644 --- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp +++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp @@ -120,10 +120,6 @@ Cost InstCostVisitor::estimateBasicBlocks( continue; for (Instruction &I : *BB) { - // Disregard SSA copies. - if (auto *II = dyn_cast(&I)) - if (II->getIntrinsicID() == Intrinsic::ssa_copy) - continue; // If it's a known constant we have already accounted for it. if (KnownConstants.contains(&I)) continue; @@ -402,6 +398,14 @@ Constant *InstCostVisitor::visitFreezeInst(FreezeInst &I) { } Constant *InstCostVisitor::visitCallBase(CallBase &I) { + assert(LastVisited != KnownConstants.end() && "Invalid iterator!"); + + // Look through calls to ssa_copy intrinsics. + if (auto *II = dyn_cast(&I); + II && II->getIntrinsicID() == Intrinsic::ssa_copy) { + return LastVisited->second; + } + Function *F = I.getCalledFunction(); if (!F || !canConstantFoldCallTo(&I, F)) return nullptr;