https://github.com/aokblast updated 
https://github.com/llvm/llvm-project/pull/237672

>From 32d74a6b95d93e0c1d1e1981190f3a0da15f7ccb Mon Sep 17 00:00:00 2001
From: ShengYi Hung <[email protected]>
Date: Sat, 31 Oct 2026 22:04:22 -0500
Subject: [PATCH] [PassBuilder] Run LoopUnrollAndJam before the vectorizers

LoopUnrollAndJam runs after LoopVectorize, which splits a vectorized
inner loop into a vector and a remainder loop. UnrollAndJam can't
handle that form, so most candidates are out of reach by the time it
runs. Move it to the start of addVectorPasses, which also covers the
full LTO pipeline. The pass is still only added under
-enable-unroll-and-jam.

With this change running over llvm-test-suites. We observe a speedup
over my Ryzen 9 9955HX in some cases (Shootout-C++-ary3 (-34.6%),
oopack_v1p8 (-6.0%)).

Assisted by: Claude # Testcases
---
 llvm/lib/Passes/PassBuilderPipelines.cpp      |  16 +-
 .../X86/unroll-and-jam-before-slp.ll          | 285 ++++++++++++++++++
 2 files changed, 292 insertions(+), 9 deletions(-)
 create mode 100644 
llvm/test/Transforms/PhaseOrdering/X86/unroll-and-jam-before-slp.ll

diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 291cbf11a6e1fd..a099d4a314b7bf 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1245,6 +1245,13 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
 void PassBuilder::addVectorPasses(OptimizationLevel Level,
                                   FunctionPassManager &FPM,
                                   ThinOrFullLTOPhase LTOPhase) {
+  // Run UnrollAndJam before the vectorizers. A vectorized inner loop is split
+  // into a vector and a remainder loop, which UnrollAndJam can't handle. We do
+  // it in a separate LPM to ensure it happens before unroll.
+  if (Opts.enable_unroll_and_jam && PTO.LoopUnrolling)
+    FPM.addPass(createFunctionToLoopPassAdaptor(
+        LoopUnrollAndJamPass(static_cast<int>(Level))));
+
   FPM.addPass(LoopVectorizePass(
       LoopVectorizeOptions(!PTO.LoopInterleaving, !PTO.LoopVectorization)));
 
@@ -1262,10 +1269,6 @@ void PassBuilder::addVectorPasses(OptimizationLevel 
Level,
     // FIXME: It would be really good to use a loop-integrated instruction
     // combiner for cleanup here so that the unrolling and LICM can be 
pipelined
     // across the loop nests.
-    // We do UnrollAndJam in a separate LPM to ensure it happens before unroll
-    if (Opts.enable_unroll_and_jam && PTO.LoopUnrolling)
-      FPM.addPass(createFunctionToLoopPassAdaptor(
-          LoopUnrollAndJamPass(static_cast<int>(Level))));
     FPM.addPass(LoopUnrollPass(LoopUnrollOptions(
         static_cast<int>(Level), /*OnlyWhenForced=*/!PTO.LoopUnrolling,
         *PTO.ForgetAllSCEVInLoopUnroll)));
@@ -1362,11 +1365,6 @@ void PassBuilder::addVectorPasses(OptimizationLevel 
Level,
     // FIXME: It would be really good to use a loop-integrated instruction
     // combiner for cleanup here so that the unrolling and LICM can be 
pipelined
     // across the loop nests.
-    // We do UnrollAndJam in a separate LPM to ensure it happens before unroll
-    if (Opts.enable_unroll_and_jam && PTO.LoopUnrolling) {
-      FPM.addPass(createFunctionToLoopPassAdaptor(
-          LoopUnrollAndJamPass(static_cast<int>(Level))));
-    }
     FPM.addPass(LoopUnrollPass(LoopUnrollOptions(
         static_cast<int>(Level), /*OnlyWhenForced=*/!PTO.LoopUnrolling,
         *PTO.ForgetAllSCEVInLoopUnroll)));
diff --git 
a/llvm/test/Transforms/PhaseOrdering/X86/unroll-and-jam-before-slp.ll 
b/llvm/test/Transforms/PhaseOrdering/X86/unroll-and-jam-before-slp.ll
new file mode 100644
index 00000000000000..04e20049ae721b
--- /dev/null
+++ b/llvm/test/Transforms/PhaseOrdering/X86/unroll-and-jam-before-slp.ll
@@ -0,0 +1,285 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 6
+; RUN: opt -passes='default<O3>' -enable-unroll-and-jam -S < %s | FileCheck %s
+
+; Unroll and jam must run before SLP vectorization. The inner loop below is a
+; strict-FP reduction that the loop vectorizer cannot handle, but after the
+; outer loop is jammed by 2, SLP can pack the two independent copies of the
+; sqrt/fdiv chain into <2 x double> operations. If SLP runs first it merges
+; the vx/vy accesses into a <2 x double> load/store, which confuses
+; DependenceAnalysis and makes unroll and jam bail out.
+;
+; Generated from:
+;
+;   struct Planet { double mass, x, y, vx, vy; };
+;
+;   void step(struct Planet *restrict next, const struct Planet *restrict p,
+;             int n, double dt) {
+;   #pragma unroll_and_jam(2)
+;     for (int i = 0; i < n; i++) {
+;       for (int j = 0; j < n; j++) {
+;         double dx = p[j].x - p[i].x;
+;         double dy = p[j].y - p[i].y;
+;         double inv = p[i].mass * p[j].mass /
+;                      __builtin_sqrt(dx * dx + dy * dy + 0.0001);
+;         double inv3 = inv * inv * inv;
+;         next[i].vx += dt * dx * inv3;
+;         next[i].vy += dt * dy * inv3;
+;       }
+;     }
+;   }
+
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+%struct.Planet = type { double, double, double, double, double }
+
+define void @step(ptr noalias noundef %next, ptr noalias noundef %p, i32 
noundef %n, double noundef %dt) #0 {
+; CHECK-LABEL: define void @step(
+; CHECK-SAME: ptr noalias nofree noundef captures(none) [[NEXT:%.*]], ptr 
noalias nofree noundef readonly captures(none) [[P:%.*]], i32 noundef 
[[N:%.*]], double noundef [[DT:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CMP4:%.*]] = icmp sgt i32 [[N]], 0
+; CHECK-NEXT:    br i1 [[CMP4]], label %[[FOR_COND1_PREHEADER_PREHEADER:.*]], 
label %[[FOR_END33:.*]]
+; CHECK:       [[FOR_COND1_PREHEADER_PREHEADER]]:
+; CHECK-NEXT:    [[WIDE_TRIP_COUNT11:%.*]] = zext nneg i32 [[N]] to i64
+; CHECK-NEXT:    [[XTRAITER:%.*]] = and i64 [[WIDE_TRIP_COUNT11]], 1
+; CHECK-NEXT:    [[TMP0:%.*]] = icmp eq i32 [[N]], 1
+; CHECK-NEXT:    br i1 [[TMP0]], label 
%[[FOR_COND1_PREHEADER_EPIL_PREHEADER:.*]], label 
%[[FOR_COND1_PREHEADER_PREHEADER_NEW:.*]]
+; CHECK:       [[FOR_COND1_PREHEADER_PREHEADER_NEW]]:
+; CHECK-NEXT:    [[UNROLL_ITER:%.*]] = and i64 [[WIDE_TRIP_COUNT11]], 
2147483646
+; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <2 x double> poison, double 
[[DT]], i64 0
+; CHECK-NEXT:    [[TMP2:%.*]] = shufflevector <2 x double> [[TMP1]], <2 x 
double> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:    br label %[[FOR_COND1_PREHEADER:.*]]
+; CHECK:       [[FOR_COND1_PREHEADER]]:
+; CHECK-NEXT:    [[INDVARS_IV8:%.*]] = phi i64 [ 0, 
%[[FOR_COND1_PREHEADER_PREHEADER_NEW]] ], [ [[INDVARS_IV_NEXT9_1:%.*]], 
%[[FOR_COND1_FOR_INC31_CRIT_EDGE:.*]] ]
+; CHECK-NEXT:    [[NITER:%.*]] = phi i64 [ 0, 
%[[FOR_COND1_PREHEADER_PREHEADER_NEW]] ], [ [[NITER_NEXT_1:%.*]], 
%[[FOR_COND1_FOR_INC31_CRIT_EDGE]] ]
+; CHECK-NEXT:    [[ARRAYIDX6:%.*]] = getelementptr inbounds nuw [40 x i8], ptr 
[[P]], i64 [[INDVARS_IV8]]
+; CHECK-NEXT:    [[X7:%.*]] = getelementptr inbounds nuw i8, ptr 
[[ARRAYIDX6]], i64 8
+; CHECK-NEXT:    [[TMP3:%.*]] = load double, ptr [[ARRAYIDX6]], align 8, !tbaa 
[[DOUBLE_TBAA0:![0-9]+]]
+; CHECK-NEXT:    [[ARRAYIDX26:%.*]] = getelementptr inbounds nuw [40 x i8], 
ptr [[NEXT]], i64 [[INDVARS_IV8]]
+; CHECK-NEXT:    [[VX:%.*]] = getelementptr inbounds nuw i8, ptr 
[[ARRAYIDX26]], i64 24
+; CHECK-NEXT:    [[TMP4:%.*]] = load <2 x double>, ptr [[X7]], align 8, !tbaa 
[[DOUBLE_TBAA5:![0-9]+]]
+; CHECK-NEXT:    [[TMP5:%.*]] = load <2 x double>, ptr [[VX]], align 8, !tbaa 
[[DOUBLE_TBAA5]]
+; CHECK-NEXT:    [[INDVARS_IV_NEXT9:%.*]] = or disjoint i64 [[INDVARS_IV8]], 1
+; CHECK-NEXT:    [[ARRAYIDX6_1:%.*]] = getelementptr inbounds nuw [40 x i8], 
ptr [[P]], i64 [[INDVARS_IV_NEXT9]]
+; CHECK-NEXT:    [[X7_1:%.*]] = getelementptr inbounds nuw i8, ptr 
[[ARRAYIDX6_1]], i64 8
+; CHECK-NEXT:    [[TMP6:%.*]] = load double, ptr [[ARRAYIDX6_1]], align 8, 
!tbaa [[DOUBLE_TBAA0]]
+; CHECK-NEXT:    [[ARRAYIDX26_1:%.*]] = getelementptr inbounds nuw [40 x i8], 
ptr [[NEXT]], i64 [[INDVARS_IV_NEXT9]]
+; CHECK-NEXT:    [[VX_1:%.*]] = getelementptr inbounds nuw i8, ptr 
[[ARRAYIDX26_1]], i64 24
+; CHECK-NEXT:    [[TMP7:%.*]] = load <2 x double>, ptr [[X7_1]], align 8, 
!tbaa [[DOUBLE_TBAA5]]
+; CHECK-NEXT:    [[TMP8:%.*]] = load <2 x double>, ptr [[VX_1]], align 8, 
!tbaa [[DOUBLE_TBAA5]]
+; CHECK-NEXT:    [[INDVARS_IV_NEXT9_1]] = add nuw nsw i64 [[INDVARS_IV8]], 2
+; CHECK-NEXT:    [[NITER_NEXT_1]] = add i64 [[NITER]], 2
+; CHECK-NEXT:    [[TMP9:%.*]] = insertelement <2 x double> poison, double 
[[TMP3]], i64 0
+; CHECK-NEXT:    [[TMP10:%.*]] = insertelement <2 x double> [[TMP9]], double 
[[TMP6]], i64 1
+; CHECK-NEXT:    br label %[[FOR_BODY4:.*]]
+; CHECK:       [[FOR_BODY4]]:
+; CHECK-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ 0, %[[FOR_COND1_PREHEADER]] ], 
[ [[INDVARS_IV_NEXT:%.*]], %[[FOR_BODY4]] ]
+; CHECK-NEXT:    [[INDVARS_IV_1:%.*]] = phi i64 [ 0, %[[FOR_COND1_PREHEADER]] 
], [ [[INDVARS_IV_NEXT_1:%.*]], %[[FOR_BODY4]] ]
+; CHECK-NEXT:    [[TMP11:%.*]] = phi <2 x double> [ [[TMP5]], 
%[[FOR_COND1_PREHEADER]] ], [ [[TMP33:%.*]], %[[FOR_BODY4]] ]
+; CHECK-NEXT:    [[TMP12:%.*]] = phi <2 x double> [ [[TMP8]], 
%[[FOR_COND1_PREHEADER]] ], [ [[TMP36:%.*]], %[[FOR_BODY4]] ]
+; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds nuw [40 x i8], ptr 
[[P]], i64 [[INDVARS_IV]]
+; CHECK-NEXT:    [[X:%.*]] = getelementptr inbounds nuw i8, ptr [[ARRAYIDX]], 
i64 8
+; CHECK-NEXT:    [[TMP13:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !tbaa 
[[DOUBLE_TBAA0]]
+; CHECK-NEXT:    [[TMP14:%.*]] = load <2 x double>, ptr [[X]], align 8, !tbaa 
[[DOUBLE_TBAA5]]
+; CHECK-NEXT:    [[TMP15:%.*]] = fsub <2 x double> [[TMP14]], [[TMP4]]
+; CHECK-NEXT:    [[TMP16:%.*]] = fmul <2 x double> [[TMP2]], [[TMP15]]
+; CHECK-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
+; CHECK-NEXT:    [[ARRAYIDX_1:%.*]] = getelementptr inbounds nuw [40 x i8], 
ptr [[P]], i64 [[INDVARS_IV_1]]
+; CHECK-NEXT:    [[X_1:%.*]] = getelementptr inbounds nuw i8, ptr 
[[ARRAYIDX_1]], i64 8
+; CHECK-NEXT:    [[TMP17:%.*]] = load double, ptr [[ARRAYIDX_1]], align 8, 
!tbaa [[DOUBLE_TBAA0]]
+; CHECK-NEXT:    [[TMP18:%.*]] = load <2 x double>, ptr [[X_1]], align 8, 
!tbaa [[DOUBLE_TBAA5]]
+; CHECK-NEXT:    [[TMP19:%.*]] = fsub <2 x double> [[TMP18]], [[TMP7]]
+; CHECK-NEXT:    [[TMP20:%.*]] = insertelement <2 x double> poison, double 
[[TMP13]], i64 0
+; CHECK-NEXT:    [[TMP21:%.*]] = insertelement <2 x double> [[TMP20]], double 
[[TMP17]], i64 1
+; CHECK-NEXT:    [[TMP22:%.*]] = fmul <2 x double> [[TMP10]], [[TMP21]]
+; CHECK-NEXT:    [[TMP23:%.*]] = shufflevector <2 x double> [[TMP15]], <2 x 
double> [[TMP19]], <2 x i32> <i32 1, i32 3>
+; CHECK-NEXT:    [[TMP24:%.*]] = fmul <2 x double> [[TMP23]], [[TMP23]]
+; CHECK-NEXT:    [[TMP25:%.*]] = shufflevector <2 x double> [[TMP15]], <2 x 
double> [[TMP19]], <2 x i32> <i32 0, i32 2>
+; CHECK-NEXT:    [[TMP26:%.*]] = tail call <2 x double> @llvm.fmuladd.v2f64(<2 
x double> [[TMP25]], <2 x double> [[TMP25]], <2 x double> [[TMP24]])
+; CHECK-NEXT:    [[TMP27:%.*]] = fadd <2 x double> [[TMP26]], splat (double 
1.000000e-04)
+; CHECK-NEXT:    [[TMP28:%.*]] = tail call <2 x double> @llvm.sqrt.v2f64(<2 x 
double> [[TMP27]])
+; CHECK-NEXT:    [[TMP29:%.*]] = fdiv <2 x double> [[TMP22]], [[TMP28]]
+; CHECK-NEXT:    [[TMP30:%.*]] = fmul <2 x double> [[TMP29]], [[TMP29]]
+; CHECK-NEXT:    [[TMP31:%.*]] = fmul <2 x double> [[TMP29]], [[TMP30]]
+; CHECK-NEXT:    [[TMP32:%.*]] = shufflevector <2 x double> [[TMP31]], <2 x 
double> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:    [[TMP33]] = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x 
double> [[TMP16]], <2 x double> [[TMP32]], <2 x double> [[TMP11]])
+; CHECK-NEXT:    [[TMP34:%.*]] = fmul <2 x double> [[TMP2]], [[TMP19]]
+; CHECK-NEXT:    [[TMP35:%.*]] = shufflevector <2 x double> [[TMP31]], <2 x 
double> poison, <2 x i32> <i32 1, i32 1>
+; CHECK-NEXT:    [[TMP36]] = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x 
double> [[TMP34]], <2 x double> [[TMP35]], <2 x double> [[TMP12]])
+; CHECK-NEXT:    [[INDVARS_IV_NEXT_1]] = add nuw nsw i64 [[INDVARS_IV_1]], 1
+; CHECK-NEXT:    [[EXITCOND_NOT_1:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT_1]], 
[[WIDE_TRIP_COUNT11]]
+; CHECK-NEXT:    br i1 [[EXITCOND_NOT_1]], label 
%[[FOR_COND1_FOR_INC31_CRIT_EDGE]], label %[[FOR_BODY4]], !llvm.loop 
[[LOOP6:![0-9]+]]
+; CHECK:       [[FOR_COND1_FOR_INC31_CRIT_EDGE]]:
+; CHECK-NEXT:    store <2 x double> [[TMP33]], ptr [[VX]], align 8, !tbaa 
[[DOUBLE_TBAA5]]
+; CHECK-NEXT:    store <2 x double> [[TMP36]], ptr [[VX_1]], align 8, !tbaa 
[[DOUBLE_TBAA5]]
+; CHECK-NEXT:    [[NITER_NCMP_1:%.*]] = icmp eq i64 [[NITER_NEXT_1]], 
[[UNROLL_ITER]]
+; CHECK-NEXT:    br i1 [[NITER_NCMP_1]], label 
%[[FOR_END33_LOOPEXIT_UNR_LCSSA:.*]], label %[[FOR_COND1_PREHEADER]], 
!llvm.loop [[LOOP7:![0-9]+]]
+; CHECK:       [[FOR_END33_LOOPEXIT_UNR_LCSSA]]:
+; CHECK-NEXT:    [[LCMP_MOD_NOT:%.*]] = icmp eq i64 [[XTRAITER]], 0
+; CHECK-NEXT:    br i1 [[LCMP_MOD_NOT]], label %[[FOR_END33]], label 
%[[FOR_COND1_PREHEADER_EPIL_PREHEADER]]
+; CHECK:       [[FOR_COND1_PREHEADER_EPIL_PREHEADER]]:
+; CHECK-NEXT:    [[INDVARS_IV8_EPIL_INIT:%.*]] = phi i64 [ 0, 
%[[FOR_COND1_PREHEADER_PREHEADER]] ], [ [[INDVARS_IV_NEXT9_1]], 
%[[FOR_END33_LOOPEXIT_UNR_LCSSA]] ]
+; CHECK-NEXT:    [[LCMP_MOD16:%.*]] = trunc i32 [[N]] to i1
+; CHECK-NEXT:    tail call void @llvm.assume(i1 [[LCMP_MOD16]])
+; CHECK-NEXT:    [[ARRAYIDX6_EPIL:%.*]] = getelementptr inbounds nuw [40 x 
i8], ptr [[P]], i64 [[INDVARS_IV8_EPIL_INIT]]
+; CHECK-NEXT:    [[X7_EPIL:%.*]] = getelementptr inbounds nuw i8, ptr 
[[ARRAYIDX6_EPIL]], i64 8
+; CHECK-NEXT:    [[TMP37:%.*]] = load double, ptr [[ARRAYIDX6_EPIL]], align 8, 
!tbaa [[DOUBLE_TBAA0]]
+; CHECK-NEXT:    [[ARRAYIDX26_EPIL:%.*]] = getelementptr inbounds nuw [40 x 
i8], ptr [[NEXT]], i64 [[INDVARS_IV8_EPIL_INIT]]
+; CHECK-NEXT:    [[VX_EPIL:%.*]] = getelementptr inbounds nuw i8, ptr 
[[ARRAYIDX26_EPIL]], i64 24
+; CHECK-NEXT:    [[TMP38:%.*]] = load <2 x double>, ptr [[X7_EPIL]], align 8, 
!tbaa [[DOUBLE_TBAA5]]
+; CHECK-NEXT:    [[TMP39:%.*]] = load <2 x double>, ptr [[VX_EPIL]], align 8, 
!tbaa [[DOUBLE_TBAA5]]
+; CHECK-NEXT:    [[TMP40:%.*]] = insertelement <2 x double> poison, double 
[[DT]], i64 0
+; CHECK-NEXT:    [[TMP41:%.*]] = shufflevector <2 x double> [[TMP40]], <2 x 
double> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:    br label %[[FOR_BODY4_EPIL:.*]]
+; CHECK:       [[FOR_BODY4_EPIL]]:
+; CHECK-NEXT:    [[INDVARS_IV_EPIL:%.*]] = phi i64 [ 0, 
%[[FOR_COND1_PREHEADER_EPIL_PREHEADER]] ], [ [[INDVARS_IV_NEXT_EPIL:%.*]], 
%[[FOR_BODY4_EPIL]] ]
+; CHECK-NEXT:    [[TMP42:%.*]] = phi <2 x double> [ [[TMP39]], 
%[[FOR_COND1_PREHEADER_EPIL_PREHEADER]] ], [ [[TMP52:%.*]], %[[FOR_BODY4_EPIL]] 
]
+; CHECK-NEXT:    [[ARRAYIDX_EPIL:%.*]] = getelementptr inbounds nuw [40 x i8], 
ptr [[P]], i64 [[INDVARS_IV_EPIL]]
+; CHECK-NEXT:    [[X_EPIL:%.*]] = getelementptr inbounds nuw i8, ptr 
[[ARRAYIDX_EPIL]], i64 8
+; CHECK-NEXT:    [[TMP43:%.*]] = load double, ptr [[ARRAYIDX_EPIL]], align 8, 
!tbaa [[DOUBLE_TBAA0]]
+; CHECK-NEXT:    [[MUL_EPIL:%.*]] = fmul double [[TMP37]], [[TMP43]]
+; CHECK-NEXT:    [[TMP44:%.*]] = load <2 x double>, ptr [[X_EPIL]], align 8, 
!tbaa [[DOUBLE_TBAA5]]
+; CHECK-NEXT:    [[TMP45:%.*]] = fsub <2 x double> [[TMP44]], [[TMP38]]
+; CHECK-NEXT:    [[FOLDEXTEXTBINOP:%.*]] = fmul <2 x double> [[TMP45]], 
[[TMP45]]
+; CHECK-NEXT:    [[MUL20_EPIL:%.*]] = extractelement <2 x double> 
[[FOLDEXTEXTBINOP]], i64 1
+; CHECK-NEXT:    [[TMP46:%.*]] = extractelement <2 x double> [[TMP45]], i64 0
+; CHECK-NEXT:    [[TMP47:%.*]] = tail call double @llvm.fmuladd.f64(double 
[[TMP46]], double [[TMP46]], double [[MUL20_EPIL]])
+; CHECK-NEXT:    [[ADD_EPIL:%.*]] = fadd double [[TMP47]], 1.000000e-04
+; CHECK-NEXT:    [[TMP48:%.*]] = tail call double @llvm.sqrt.f64(double 
[[ADD_EPIL]])
+; CHECK-NEXT:    [[DIV_EPIL:%.*]] = fdiv double [[MUL_EPIL]], [[TMP48]]
+; CHECK-NEXT:    [[MUL21_EPIL:%.*]] = fmul double [[DIV_EPIL]], [[DIV_EPIL]]
+; CHECK-NEXT:    [[MUL22_EPIL:%.*]] = fmul double [[DIV_EPIL]], [[MUL21_EPIL]]
+; CHECK-NEXT:    [[TMP49:%.*]] = fmul <2 x double> [[TMP41]], [[TMP45]]
+; CHECK-NEXT:    [[TMP50:%.*]] = insertelement <2 x double> poison, double 
[[MUL22_EPIL]], i64 0
+; CHECK-NEXT:    [[TMP51:%.*]] = shufflevector <2 x double> [[TMP50]], <2 x 
double> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:    [[TMP52]] = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x 
double> [[TMP49]], <2 x double> [[TMP51]], <2 x double> [[TMP42]])
+; CHECK-NEXT:    [[INDVARS_IV_NEXT_EPIL]] = add nuw nsw i64 
[[INDVARS_IV_EPIL]], 1
+; CHECK-NEXT:    [[EXITCOND_NOT_EPIL:%.*]] = icmp eq i64 
[[INDVARS_IV_NEXT_EPIL]], [[WIDE_TRIP_COUNT11]]
+; CHECK-NEXT:    br i1 [[EXITCOND_NOT_EPIL]], label 
%[[FOR_COND1_FOR_INC31_CRIT_EDGE_EPIL:.*]], label %[[FOR_BODY4_EPIL]], 
!llvm.loop [[LOOP6]]
+; CHECK:       [[FOR_COND1_FOR_INC31_CRIT_EDGE_EPIL]]:
+; CHECK-NEXT:    store <2 x double> [[TMP52]], ptr [[VX_EPIL]], align 8, !tbaa 
[[DOUBLE_TBAA5]]
+; CHECK-NEXT:    br label %[[FOR_END33]]
+; CHECK:       [[FOR_END33]]:
+; CHECK-NEXT:    ret void
+;
+entry:
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.inc31, %entry
+  %i.0 = phi i32 [ 0, %entry ], [ %inc32, %for.inc31 ]
+  %cmp = icmp slt i32 %i.0, %n
+  br i1 %cmp, label %for.body, label %for.cond.cleanup
+
+for.cond.cleanup:                                 ; preds = %for.cond
+  br label %for.end33
+
+for.body:                                         ; preds = %for.cond
+  br label %for.cond1
+
+for.cond1:                                        ; preds = %for.inc, %for.body
+  %j.0 = phi i32 [ 0, %for.body ], [ %inc, %for.inc ]
+  %cmp2 = icmp slt i32 %j.0, %n
+  br i1 %cmp2, label %for.body4, label %for.cond.cleanup3
+
+for.cond.cleanup3:                                ; preds = %for.cond1
+  br label %for.end
+
+for.body4:                                        ; preds = %for.cond1
+  %idxprom = sext i32 %j.0 to i64
+  %arrayidx = getelementptr inbounds %struct.Planet, ptr %p, i64 %idxprom
+  %x = getelementptr inbounds nuw %struct.Planet, ptr %arrayidx, i32 0, i32 1
+  %0 = load double, ptr %x, align 8, !tbaa !9
+  %idxprom5 = sext i32 %i.0 to i64
+  %arrayidx6 = getelementptr inbounds %struct.Planet, ptr %p, i64 %idxprom5
+  %x7 = getelementptr inbounds nuw %struct.Planet, ptr %arrayidx6, i32 0, i32 1
+  %1 = load double, ptr %x7, align 8, !tbaa !9
+  %sub = fsub double %0, %1
+  %idxprom8 = sext i32 %j.0 to i64
+  %arrayidx9 = getelementptr inbounds %struct.Planet, ptr %p, i64 %idxprom8
+  %y = getelementptr inbounds nuw %struct.Planet, ptr %arrayidx9, i32 0, i32 2
+  %2 = load double, ptr %y, align 8, !tbaa !12
+  %idxprom10 = sext i32 %i.0 to i64
+  %arrayidx11 = getelementptr inbounds %struct.Planet, ptr %p, i64 %idxprom10
+  %y12 = getelementptr inbounds nuw %struct.Planet, ptr %arrayidx11, i32 0, 
i32 2
+  %3 = load double, ptr %y12, align 8, !tbaa !12
+  %sub13 = fsub double %2, %3
+  %idxprom14 = sext i32 %i.0 to i64
+  %arrayidx15 = getelementptr inbounds %struct.Planet, ptr %p, i64 %idxprom14
+  %mass = getelementptr inbounds nuw %struct.Planet, ptr %arrayidx15, i32 0, 
i32 0
+  %4 = load double, ptr %mass, align 8, !tbaa !13
+  %idxprom16 = sext i32 %j.0 to i64
+  %arrayidx17 = getelementptr inbounds %struct.Planet, ptr %p, i64 %idxprom16
+  %mass18 = getelementptr inbounds nuw %struct.Planet, ptr %arrayidx17, i32 0, 
i32 0
+  %5 = load double, ptr %mass18, align 8, !tbaa !13
+  %mul = fmul double %4, %5
+  %mul20 = fmul double %sub13, %sub13
+  %6 = call double @llvm.fmuladd.f64(double %sub, double %sub, double %mul20)
+  %add = fadd double %6, 1.000000e-04
+  %7 = call double @llvm.sqrt.f64(double %add)
+  %div = fdiv double %mul, %7
+  %mul21 = fmul double %div, %div
+  %mul22 = fmul double %mul21, %div
+  %mul23 = fmul double %dt, %sub
+  %idxprom25 = sext i32 %i.0 to i64
+  %arrayidx26 = getelementptr inbounds %struct.Planet, ptr %next, i64 
%idxprom25
+  %vx = getelementptr inbounds nuw %struct.Planet, ptr %arrayidx26, i32 0, i32 
3
+  %8 = load double, ptr %vx, align 8, !tbaa !14
+  %9 = call double @llvm.fmuladd.f64(double %mul23, double %mul22, double %8)
+  store double %9, ptr %vx, align 8, !tbaa !14
+  %mul27 = fmul double %dt, %sub13
+  %idxprom29 = sext i32 %i.0 to i64
+  %arrayidx30 = getelementptr inbounds %struct.Planet, ptr %next, i64 
%idxprom29
+  %vy = getelementptr inbounds nuw %struct.Planet, ptr %arrayidx30, i32 0, i32 
4
+  %10 = load double, ptr %vy, align 8, !tbaa !15
+  %11 = call double @llvm.fmuladd.f64(double %mul27, double %mul22, double %10)
+  store double %11, ptr %vy, align 8, !tbaa !15
+  br label %for.inc
+
+for.inc:                                          ; preds = %for.body4
+  %inc = add nsw i32 %j.0, 1
+  br label %for.cond1, !llvm.loop !16
+
+for.end:                                          ; preds = %for.cond.cleanup3
+  br label %for.inc31
+
+for.inc31:                                        ; preds = %for.end
+  %inc32 = add nsw i32 %i.0, 1
+  br label %for.cond, !llvm.loop !17
+
+for.end33:                                        ; preds = %for.cond.cleanup
+  ret void
+}
+
+declare double @llvm.fmuladd.f64(double, double, double) #2
+
+declare double @llvm.sqrt.f64(double) #2
+
+attributes #0 = { nounwind "target-cpu"="x86-64" }
+attributes #2 = { nocallback nocreateundeforpoison nofree nosync nounwind 
speculatable willreturn memory(none) }
+
+!7 = !{!"omnipotent char", !8, i64 0}
+!8 = !{!"Simple C/C++ TBAA"}
+!9 = !{!10, !11, i64 8}
+!10 = !{!"Planet", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 
32}
+!11 = !{!"double", !7, i64 0}
+!12 = !{!10, !11, i64 16}
+!13 = !{!10, !11, i64 0}
+!14 = !{!10, !11, i64 24}
+!15 = !{!10, !11, i64 32}
+!16 = distinct !{!16}
+!17 = distinct !{!17, !18, !19}
+!18 = !{!"llvm.loop.mustprogress"}
+!19 = !{!"llvm.loop.unroll_and_jam.count", i32 2}
+;.
+; CHECK: [[DOUBLE_TBAA0]] = !{[[META1:![0-9]+]], [[META2:![0-9]+]], i64 0}
+; CHECK: [[META1]] = !{!"Planet", [[META2]], i64 0, [[META2]], i64 8, 
[[META2]], i64 16, [[META2]], i64 24, [[META2]], i64 32}
+; CHECK: [[META2]] = !{!"double", [[META3:![0-9]+]], i64 0}
+; CHECK: [[META3]] = !{!"omnipotent char", [[META4:![0-9]+]], i64 0}
+; CHECK: [[META4]] = !{!"Simple C/C++ TBAA"}
+; CHECK: [[DOUBLE_TBAA5]] = !{[[META2]], [[META2]], i64 0}
+; CHECK: [[LOOP6]] = distinct !{[[LOOP6]]}
+; CHECK: [[LOOP7]] = distinct !{[[LOOP7]], [[META8:![0-9]+]], 
[[META9:![0-9]+]], [[META10:![0-9]+]]}
+; CHECK: [[META8]] = !{!"llvm.loop.mustprogress"}
+; CHECK: [[META9]] = !{!"llvm.loop.unroll_and_jam.count", i32 2}
+; CHECK: [[META10]] = !{!"llvm.loop.unroll.disable"}
+;.

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to