[lld] [lld][MachO] Enable LoopVectorization and SLPVectorization for ThinLTO (PR #182748)

Tal Keren via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 22 07:06:05 PST 2026


https://github.com/talkeren created https://github.com/llvm/llvm-project/pull/182748

Commit 21a4710c67a97838dd75cf60ed24da11280800f8 previously enabled LoopVectorization and SLPVectorization CodeGen options for the ELF and COFF LTO backends. Since the Mach-O LTO port did not exist at the time, it missed this configuration.

This patch adds these options to the Mach-O LTO setup for consistency with the other backends. Without this, SLP and loop vectorization passes are silently skipped during Mach-O LTO for O2 and O3 builds.

>From 53b30f9b0d84ae82c206aabd868a8340f8ee60d2 Mon Sep 17 00:00:00 2001
From: Tal Keren <tkeren at paloaltonetworks.com>
Date: Sun, 22 Feb 2026 16:30:04 +0200
Subject: [PATCH] [lld][MachO] Enable LoopVectorization and SLPVectorization
 for ThinLTO

Commit 21a4710c67a97838dd75cf60ed24da11280800f8 previously enabled
LoopVectorization and SLPVectorization CodeGen options for the ELF
and COFF LTO backends. Since the Mach-O LTO port did not exist at
the time, it missed this configuration.

This patch adds these options to the Mach-O LTO setup for consistency
with the other backends. Without this, SLP and loop vectorization
passes are silently skipped during Mach-O LTO for O2 and O3 builds.
---
 lld/MachO/LTO.cpp                      |  4 +++
 lld/test/MachO/lto-slp-vectorize-pm.ll | 48 ++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
 create mode 100644 lld/test/MachO/lto-slp-vectorize-pm.ll

diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp
index 2c360374ef3cc..1283b98f29eaf 100644
--- a/lld/MachO/LTO.cpp
+++ b/lld/MachO/LTO.cpp
@@ -61,6 +61,10 @@ static lto::Config createConfig() {
   c.DisableVerify = config->disableVerify;
   c.OptLevel = config->ltoo;
   c.CGOptLevel = config->ltoCgo;
+
+  c.PTO.LoopVectorization = c.OptLevel > 1;
+  c.PTO.SLPVectorization = c.OptLevel > 1;
+  
   if (config->saveTemps)
     checkError(c.addSaveTemps(config->outputFile.str() + ".",
                               /*UseInputModulePath=*/true));
diff --git a/lld/test/MachO/lto-slp-vectorize-pm.ll b/lld/test/MachO/lto-slp-vectorize-pm.ll
new file mode 100644
index 0000000000000..7a07a1b8dd245
--- /dev/null
+++ b/lld/test/MachO/lto-slp-vectorize-pm.ll
@@ -0,0 +1,48 @@
+; REQUIRES: x86
+; RUN: opt -module-summary %s -o %t.o
+
+; Test SLP and Loop Vectorization are enabled by default at O2 and O3
+; RUN: %lld --lto-debug-pass-manager --lto-O0 -save-temps -dylib -o %t1.o %t.o 2>&1 | FileCheck %s --check-prefix=CHECK-O0-SLP
+; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-O0-LPV
+
+; RUN: %lld --lto-debug-pass-manager --lto-O1 -save-temps -dylib -o %t2.o %t.o 2>&1 | FileCheck %s --check-prefix=CHECK-O1-SLP
+; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-O1-LPV
+
+; RUN: %lld --lto-debug-pass-manager --lto-O2 -save-temps -dylib -o %t3.o %t.o 2>&1 | FileCheck %s --check-prefix=CHECK-O2-SLP
+; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-O2-LPV
+
+; RUN: %lld --lto-debug-pass-manager --lto-O3 -save-temps -dylib -o %t4.o %t.o 2>&1 | FileCheck %s --check-prefix=CHECK-O3-SLP
+; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-O3-LPV
+
+; CHECK-O0-SLP-NOT: Running pass: SLPVectorizerPass
+; CHECK-O1-SLP-NOT: Running pass: SLPVectorizerPass
+; CHECK-O2-SLP: Running pass: SLPVectorizerPass
+; CHECK-O3-SLP: Running pass: SLPVectorizerPass
+; CHECK-O0-LPV-NOT: = !{!"llvm.loop.isvectorized", i32 1}
+; CHECK-O1-LPV-NOT: = !{!"llvm.loop.isvectorized", i32 1}
+; CHECK-O2-LPV: = !{!"llvm.loop.isvectorized", i32 1}
+; CHECK-O3-LPV: = !{!"llvm.loop.isvectorized", i32 1}
+
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.15.0"
+
+define i32 @foo(ptr %a) {
+entry:
+  br label %for.body
+
+for.body:
+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
+  %red.05 = phi i32 [ 0, %entry ], [ %add, %for.body ]
+  %arrayidx = getelementptr inbounds i32, ptr %a, i64 %indvars.iv
+  %0 = load i32, ptr %arrayidx, align 4
+  %add = add nsw i32 %0, %red.05
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond = icmp eq i64 %indvars.iv.next, 255
+  br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
+
+for.end:
+  ret i32 %add
+}
+
+!0 = distinct !{!0, !1}
+!1 = !{!"llvm.loop.unroll.disable", i1 true}



More information about the llvm-commits mailing list