From 8d25e98111eaab61ec280127e84d4ecfa4fe7d04 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Thu, 10 Jul 2025 15:57:16 +0100 Subject: [PATCH] [TTI/{RISCV,AArch64}] Strip redundant unroll prefs The loop vectorizer emits a llvm.loop.unroll.disable metadata, effectively disabling loop unrolling. Strip redundant code that over-eagerly checks for vector instructions in the loop or the llvm.loop.isvectorized metadata. The patch is non-functional over the full compiler flow. --- .../AArch64/AArch64TargetTransformInfo.cpp | 19 ------------------- .../Target/RISCV/RISCVTargetTransformInfo.cpp | 9 --------- 2 files changed, 28 deletions(-) diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp index 20e7726558117..cd0059050200c 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -4894,25 +4894,6 @@ void AArch64TTIImpl::getUnrollingPreferences( // Disable partial & runtime unrolling on -Os. UP.PartialOptSizeThreshold = 0; - // Scan the loop: don't unroll loops with calls as this could prevent - // inlining. Don't unroll vector loops either, as they don't benefit much from - // unrolling. - for (auto *BB : L->getBlocks()) { - for (auto &I : *BB) { - // Don't unroll vectorised loop. - if (I.getType()->isVectorTy()) - return; - - if (isa(I)) { - if (isa(I) || isa(I)) - if (const Function *F = cast(I).getCalledFunction()) - if (!isLoweredToCall(F)) - continue; - return; - } - } - } - // Apply subtarget-specific unrolling preferences. switch (ST->getProcFamily()) { case AArch64Subtarget::AppleA14: diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp index 56ead92187b04..2fb422e5a8a61 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp @@ -2565,20 +2565,11 @@ void RISCVTTIImpl::getUnrollingPreferences( if (L->getNumBlocks() > 4) return; - // Don't unroll vectorized loops, including the remainder loop - if (getBooleanLoopAttribute(L, "llvm.loop.isvectorized")) - return; - // Scan the loop: don't unroll loops with calls as this could prevent // inlining. InstructionCost Cost = 0; for (auto *BB : L->getBlocks()) { for (auto &I : *BB) { - // Initial setting - Don't unroll loops containing vectorized - // instructions. - if (I.getType()->isVectorTy()) - return; - if (isa(I) || isa(I)) { if (const Function *F = cast(I).getCalledFunction()) { if (!isLoweredToCall(F))