From: Nikita Popov Date: Wed, 16 Mar 2022 09:36:00 +0000 (+0100) Subject: [RelLookupTableConverter] Avoid querying TTI for declarations X-Git-Tag: upstream/15.0.7~13488 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=20531b3a6b091b8dd2e3992aec11ac10581e91e2;p=platform%2Fupstream%2Fllvm.git [RelLookupTableConverter] Avoid querying TTI for declarations This code queries TTI on a single function, which is considered to be representative. This is a bit odd, but probably fine in practice. However, I think we should at least avoid querying declarations, which e.g. will generally lack target attributes, and for which we don't seem to ever query TTI in other places. --- diff --git a/llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp b/llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp index fd52285124c1..037f42f5b050 100644 --- a/llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp +++ b/llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp @@ -170,13 +170,17 @@ static void convertToRelLookupTable(GlobalVariable &LookupTable) { // Convert lookup tables to relative lookup tables in the module. static bool convertToRelativeLookupTables( Module &M, function_ref GetTTI) { - Module::iterator FI = M.begin(); - if (FI == M.end()) - return false; + for (Function &F : M) { + if (F.isDeclaration()) + continue; - // Check if we have a target that supports relative lookup tables. - if (!GetTTI(*FI).shouldBuildRelLookupTables()) - return false; + // Check if we have a target that supports relative lookup tables. + if (!GetTTI(F).shouldBuildRelLookupTables()) + return false; + + // We assume that the result is independent of the checked function. + break; + } bool Changed = false;