[llvm-branch-commits] [llvm] [SLP] Pass a lane as the vector cost context only if all lanes agree (PR #241758)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Nov 12 02:22:38 PST 2026


https://github.com/michaelselehov updated https://github.com/llvm/llvm-project/pull/241758

>From 4497cb75b613dd481daff90440167daa5e6d6367 Mon Sep 17 00:00:00 2001
From: Michael Selehov <michael.selehov at amd.com>
Date: Wed, 11 Nov 2026 09:30:14 -0600
Subject: [PATCH 1/2] [SLP][NFC] Add tests for the vector cost context of mixed
 lanes

Assisted-by: Claude Opus
---
 .../AArch64/and-bsl-ctx-mixed-lanes.ll        | 81 +++++++++++++++
 .../AMDGPU/fdiv-afn-ctx-lanes.ll              | 98 +++++++++++++++++++
 .../AMDGPU/fmul-fusion-ctx-mixed-lanes.ll     | 53 ++++++++++
 .../X86/remark-alt-cmp-ctx-lanes.ll           | 62 ++++++++++++
 4 files changed, 294 insertions(+)
 create mode 100644 llvm/test/Transforms/SLPVectorizer/AArch64/and-bsl-ctx-mixed-lanes.ll
 create mode 100644 llvm/test/Transforms/SLPVectorizer/AMDGPU/fdiv-afn-ctx-lanes.ll
 create mode 100644 llvm/test/Transforms/SLPVectorizer/AMDGPU/fmul-fusion-ctx-mixed-lanes.ll
 create mode 100644 llvm/test/Transforms/SLPVectorizer/X86/remark-alt-cmp-ctx-lanes.ll

diff --git a/llvm/test/Transforms/SLPVectorizer/AArch64/and-bsl-ctx-mixed-lanes.ll b/llvm/test/Transforms/SLPVectorizer/AArch64/and-bsl-ctx-mixed-lanes.ll
new file mode 100644
index 0000000000000..be287c280fad0
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/AArch64/and-bsl-ctx-mixed-lanes.ll
@@ -0,0 +1,81 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -passes=slp-vectorizer -mtriple=aarch64-unknown-linux-gnu < %s | FileCheck %s
+
+; One lane is a bit select, or(and(x, m), and(y, not m)), the other one is not,
+; because its second and uses a different mask. The cost of the vector ands
+; must not depend on which of the two lanes comes first.
+
+define void @bsl_lane0(ptr %x, i64 %y, i64 %m0, i64 %m1, i64 %w1, ptr %out) {
+;
+; CHECK-LABEL: define void @bsl_lane0(
+; CHECK-SAME: ptr [[X:%.*]], i64 [[Y:%.*]], i64 [[M0:%.*]], i64 [[M1:%.*]], i64 [[W1:%.*]], ptr [[OUT:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TMP0:%.*]] = insertelement <2 x i64> poison, i64 [[M0]], i64 0
+; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <2 x i64> [[TMP0]], i64 [[W1]], i64 1
+; CHECK-NEXT:    [[TMP2:%.*]] = xor <2 x i64> [[TMP1]], splat (i64 -1)
+; CHECK-NEXT:    [[TMP3:%.*]] = load <2 x i64>, ptr [[X]], align 8
+; CHECK-NEXT:    [[TMP4:%.*]] = insertelement <2 x i64> [[TMP1]], i64 [[M1]], i64 1
+; CHECK-NEXT:    [[TMP5:%.*]] = and <2 x i64> [[TMP3]], [[TMP4]]
+; CHECK-NEXT:    [[TMP6:%.*]] = insertelement <2 x i64> poison, i64 [[Y]], i64 0
+; CHECK-NEXT:    [[TMP7:%.*]] = shufflevector <2 x i64> [[TMP6]], <2 x i64> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:    [[TMP8:%.*]] = and <2 x i64> [[TMP7]], [[TMP2]]
+; CHECK-NEXT:    [[TMP9:%.*]] = or <2 x i64> [[TMP5]], [[TMP8]]
+; CHECK-NEXT:    store <2 x i64> [[TMP9]], ptr [[OUT]], align 8
+; CHECK-NEXT:    ret void
+;
+entry:
+  %x0 = load i64, ptr %x, align 8
+  %px1 = getelementptr inbounds i64, ptr %x, i64 1
+  %x1 = load i64, ptr %px1, align 8
+  %n0 = xor i64 %m0, -1
+  %n1 = xor i64 %w1, -1
+  %a0 = and i64 %x0, %m0
+  %a1 = and i64 %x1, %m1
+  %b0 = and i64 %y, %n0
+  %b1 = and i64 %y, %n1
+  %o0 = or i64 %a0, %b0
+  %o1 = or i64 %a1, %b1
+  store i64 %o0, ptr %out, align 8
+  %po1 = getelementptr inbounds i64, ptr %out, i64 1
+  store i64 %o1, ptr %po1, align 8
+  ret void
+}
+
+define void @bsl_lane1(ptr %x, i64 %y, i64 %m0, i64 %m1, i64 %w0, ptr %out) {
+;
+; CHECK-LABEL: define void @bsl_lane1(
+; CHECK-SAME: ptr [[X:%.*]], i64 [[Y:%.*]], i64 [[M0:%.*]], i64 [[M1:%.*]], i64 [[W0:%.*]], ptr [[OUT:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[X0:%.*]] = load i64, ptr [[X]], align 8
+; CHECK-NEXT:    [[PX1:%.*]] = getelementptr inbounds i64, ptr [[X]], i64 1
+; CHECK-NEXT:    [[X1:%.*]] = load i64, ptr [[PX1]], align 8
+; CHECK-NEXT:    [[N0:%.*]] = xor i64 [[W0]], -1
+; CHECK-NEXT:    [[N1:%.*]] = xor i64 [[M1]], -1
+; CHECK-NEXT:    [[A0:%.*]] = and i64 [[X0]], [[M0]]
+; CHECK-NEXT:    [[A1:%.*]] = and i64 [[X1]], [[M1]]
+; CHECK-NEXT:    [[B0:%.*]] = and i64 [[Y]], [[N0]]
+; CHECK-NEXT:    [[B1:%.*]] = and i64 [[Y]], [[N1]]
+; CHECK-NEXT:    [[O0:%.*]] = or i64 [[A0]], [[B0]]
+; CHECK-NEXT:    [[O1:%.*]] = or i64 [[A1]], [[B1]]
+; CHECK-NEXT:    store i64 [[O0]], ptr [[OUT]], align 8
+; CHECK-NEXT:    [[PO1:%.*]] = getelementptr inbounds i64, ptr [[OUT]], i64 1
+; CHECK-NEXT:    store i64 [[O1]], ptr [[PO1]], align 8
+; CHECK-NEXT:    ret void
+;
+entry:
+  %x0 = load i64, ptr %x, align 8
+  %px1 = getelementptr inbounds i64, ptr %x, i64 1
+  %x1 = load i64, ptr %px1, align 8
+  %n0 = xor i64 %w0, -1
+  %n1 = xor i64 %m1, -1
+  %a0 = and i64 %x0, %m0
+  %a1 = and i64 %x1, %m1
+  %b0 = and i64 %y, %n0
+  %b1 = and i64 %y, %n1
+  %o0 = or i64 %a0, %b0
+  %o1 = or i64 %a1, %b1
+  store i64 %o0, ptr %out, align 8
+  %po1 = getelementptr inbounds i64, ptr %out, i64 1
+  store i64 %o1, ptr %po1, align 8
+  ret void
+}
diff --git a/llvm/test/Transforms/SLPVectorizer/AMDGPU/fdiv-afn-ctx-lanes.ll b/llvm/test/Transforms/SLPVectorizer/AMDGPU/fdiv-afn-ctx-lanes.ll
new file mode 100644
index 0000000000000..8b9554af55bae
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/AMDGPU/fdiv-afn-ctx-lanes.ll
@@ -0,0 +1,98 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -mtriple=amdgpu9.42-amd-amdhsa -passes=slp-vectorizer < %s | FileCheck %s
+
+; An fdiv with afn has a cheap lowering. In fdiv_all_afn every lane has afn,
+; so the vector fdiv keeps the cheap cost of its context. In fdiv_mixed only
+; lane 0 has afn, so the vector fdiv must not take that cost from lane 0.
+
+define void @fdiv_mixed(ptr %a, ptr %b, ptr %out) {
+; CHECK-LABEL: define void @fdiv_mixed(
+; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[OUT:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[AP1:%.*]] = getelementptr inbounds float, ptr [[A]], i64 2
+; CHECK-NEXT:    [[BP1:%.*]] = getelementptr inbounds float, ptr [[B]], i64 2
+; CHECK-NEXT:    [[TMP3:%.*]] = load <2 x float>, ptr [[A]], align 4
+; CHECK-NEXT:    [[TMP4:%.*]] = load <2 x float>, ptr [[B]], align 4
+; CHECK-NEXT:    [[TMP5:%.*]] = fdiv <2 x float> [[TMP3]], [[TMP4]]
+; CHECK-NEXT:    [[O1:%.*]] = getelementptr inbounds float, ptr [[OUT]], i64 2
+; CHECK-NEXT:    [[TMP0:%.*]] = load <2 x float>, ptr [[AP1]], align 4
+; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x float>, ptr [[BP1]], align 4
+; CHECK-NEXT:    [[TMP2:%.*]] = fdiv <2 x float> [[TMP0]], [[TMP1]]
+; CHECK-NEXT:    store <2 x float> [[TMP5]], ptr [[OUT]], align 4
+; CHECK-NEXT:    store <2 x float> [[TMP2]], ptr [[O1]], align 4
+; CHECK-NEXT:    ret void
+;
+entry:
+  %a0 = load float, ptr %a, align 4
+  %ap1 = getelementptr inbounds float, ptr %a, i64 1
+  %a1 = load float, ptr %ap1, align 4
+  %ap2 = getelementptr inbounds float, ptr %a, i64 2
+  %a2 = load float, ptr %ap2, align 4
+  %ap3 = getelementptr inbounds float, ptr %a, i64 3
+  %a3 = load float, ptr %ap3, align 4
+  %b0 = load float, ptr %b, align 4
+  %bp1 = getelementptr inbounds float, ptr %b, i64 1
+  %b1 = load float, ptr %bp1, align 4
+  %bp2 = getelementptr inbounds float, ptr %b, i64 2
+  %b2 = load float, ptr %bp2, align 4
+  %bp3 = getelementptr inbounds float, ptr %b, i64 3
+  %b3 = load float, ptr %bp3, align 4
+  %d0 = fdiv afn float %a0, %b0
+  %d1 = fdiv float %a1, %b1
+  %d2 = fdiv float %a2, %b2
+  %d3 = fdiv float %a3, %b3
+  store float %d0, ptr %out, align 4
+  %o1 = getelementptr inbounds float, ptr %out, i64 1
+  store float %d1, ptr %o1, align 4
+  %o2 = getelementptr inbounds float, ptr %out, i64 2
+  store float %d2, ptr %o2, align 4
+  %o3 = getelementptr inbounds float, ptr %out, i64 3
+  store float %d3, ptr %o3, align 4
+  ret void
+}
+
+define void @fdiv_all_afn(ptr %a, ptr %b, ptr %out) {
+; CHECK-LABEL: define void @fdiv_all_afn(
+; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[OUT:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[AP2:%.*]] = getelementptr inbounds float, ptr [[A]], i64 2
+; CHECK-NEXT:    [[BP2:%.*]] = getelementptr inbounds float, ptr [[B]], i64 2
+; CHECK-NEXT:    [[TMP0:%.*]] = load <2 x float>, ptr [[A]], align 4
+; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x float>, ptr [[B]], align 4
+; CHECK-NEXT:    [[TMP2:%.*]] = fdiv afn <2 x float> [[TMP0]], [[TMP1]]
+; CHECK-NEXT:    [[O2:%.*]] = getelementptr inbounds float, ptr [[OUT]], i64 2
+; CHECK-NEXT:    [[TMP3:%.*]] = load <2 x float>, ptr [[AP2]], align 4
+; CHECK-NEXT:    [[TMP4:%.*]] = load <2 x float>, ptr [[BP2]], align 4
+; CHECK-NEXT:    [[TMP5:%.*]] = fdiv afn <2 x float> [[TMP3]], [[TMP4]]
+; CHECK-NEXT:    store <2 x float> [[TMP2]], ptr [[OUT]], align 4
+; CHECK-NEXT:    store <2 x float> [[TMP5]], ptr [[O2]], align 4
+; CHECK-NEXT:    ret void
+;
+entry:
+  %a0 = load float, ptr %a, align 4
+  %ap1 = getelementptr inbounds float, ptr %a, i64 1
+  %a1 = load float, ptr %ap1, align 4
+  %ap2 = getelementptr inbounds float, ptr %a, i64 2
+  %a2 = load float, ptr %ap2, align 4
+  %ap3 = getelementptr inbounds float, ptr %a, i64 3
+  %a3 = load float, ptr %ap3, align 4
+  %b0 = load float, ptr %b, align 4
+  %bp1 = getelementptr inbounds float, ptr %b, i64 1
+  %b1 = load float, ptr %bp1, align 4
+  %bp2 = getelementptr inbounds float, ptr %b, i64 2
+  %b2 = load float, ptr %bp2, align 4
+  %bp3 = getelementptr inbounds float, ptr %b, i64 3
+  %b3 = load float, ptr %bp3, align 4
+  %d0 = fdiv afn float %a0, %b0
+  %d1 = fdiv afn float %a1, %b1
+  %d2 = fdiv afn float %a2, %b2
+  %d3 = fdiv afn float %a3, %b3
+  store float %d0, ptr %out, align 4
+  %o1 = getelementptr inbounds float, ptr %out, i64 1
+  store float %d1, ptr %o1, align 4
+  %o2 = getelementptr inbounds float, ptr %out, i64 2
+  store float %d2, ptr %o2, align 4
+  %o3 = getelementptr inbounds float, ptr %out, i64 3
+  store float %d3, ptr %o3, align 4
+  ret void
+}
diff --git a/llvm/test/Transforms/SLPVectorizer/AMDGPU/fmul-fusion-ctx-mixed-lanes.ll b/llvm/test/Transforms/SLPVectorizer/AMDGPU/fmul-fusion-ctx-mixed-lanes.ll
new file mode 100644
index 0000000000000..95e84c99925bc
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/AMDGPU/fmul-fusion-ctx-mixed-lanes.ll
@@ -0,0 +1,53 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -mtriple=amdgpu9.42-amd-amdhsa -passes=slp-vectorizer < %s | FileCheck %s
+
+; gfx942 has no packed f64 ALU, so a scalar fmul that feeds a fusable fadd is
+; free. The vector fmul must not get that discount from the context of lane 0
+; alone. In mixed_lanes the fmuls in lanes 1-3 have a second use and do not
+; fuse, so the vector fmul is not free and the reduction must stay scalar.
+
+define double @mixed_lanes(ptr noalias %e, ptr %a, ptr %b) {
+; CHECK-LABEL: define double @mixed_lanes(
+; CHECK-SAME: ptr noalias [[E:%.*]], ptr [[A:%.*]], ptr [[B:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = load <4 x double>, ptr [[A]], align 8
+; CHECK-NEXT:    [[TMP2:%.*]] = load <4 x double>, ptr [[B]], align 8
+; CHECK-NEXT:    [[TMP3:%.*]] = fmul reassoc contract <4 x double> [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    [[M1:%.*]] = extractelement <4 x double> [[TMP3]], i64 1
+; CHECK-NEXT:    store double [[M1]], ptr [[E]], align 8
+; CHECK-NEXT:    [[E2:%.*]] = getelementptr inbounds double, ptr [[E]], i64 1
+; CHECK-NEXT:    [[M2:%.*]] = extractelement <4 x double> [[TMP3]], i64 2
+; CHECK-NEXT:    store double [[M2]], ptr [[E2]], align 8
+; CHECK-NEXT:    [[E3:%.*]] = getelementptr inbounds double, ptr [[E]], i64 2
+; CHECK-NEXT:    [[M3:%.*]] = extractelement <4 x double> [[TMP3]], i64 3
+; CHECK-NEXT:    store double [[M3]], ptr [[E3]], align 8
+; CHECK-NEXT:    [[S3:%.*]] = call reassoc contract double @llvm.vector.reduce.fadd.v4f64(double -0.000000e+00, <4 x double> [[TMP3]])
+; CHECK-NEXT:    ret double [[S3]]
+;
+  %a0 = load double, ptr %a
+  %b0 = load double, ptr %b
+  %ap1 = getelementptr inbounds double, ptr %a, i64 1
+  %bp1 = getelementptr inbounds double, ptr %b, i64 1
+  %a1 = load double, ptr %ap1
+  %b1 = load double, ptr %bp1
+  %ap2 = getelementptr inbounds double, ptr %a, i64 2
+  %bp2 = getelementptr inbounds double, ptr %b, i64 2
+  %a2 = load double, ptr %ap2
+  %b2 = load double, ptr %bp2
+  %ap3 = getelementptr inbounds double, ptr %a, i64 3
+  %bp3 = getelementptr inbounds double, ptr %b, i64 3
+  %a3 = load double, ptr %ap3
+  %b3 = load double, ptr %bp3
+  %m0 = fmul reassoc contract double %a0, %b0
+  %m1 = fmul reassoc contract double %a1, %b1
+  %m2 = fmul reassoc contract double %a2, %b2
+  %m3 = fmul reassoc contract double %a3, %b3
+  store double %m1, ptr %e
+  %e2 = getelementptr inbounds double, ptr %e, i64 1
+  store double %m2, ptr %e2
+  %e3 = getelementptr inbounds double, ptr %e, i64 2
+  store double %m3, ptr %e3
+  %s1 = fadd reassoc contract double %m0, %m1
+  %s2 = fadd reassoc contract double %s1, %m2
+  %s3 = fadd reassoc contract double %s2, %m3
+  ret double %s3
+}
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/remark-alt-cmp-ctx-lanes.ll b/llvm/test/Transforms/SLPVectorizer/X86/remark-alt-cmp-ctx-lanes.ll
new file mode 100644
index 0000000000000..37def1ad04f60
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/remark-alt-cmp-ctx-lanes.ll
@@ -0,0 +1,62 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -pass-remarks-output=%t < %s | FileCheck %s
+; RUN: FileCheck --input-file=%t --check-prefix=YAML %s
+
+; An alternate node of eq and ne compares. The two ne lanes differ: one compares
+; with a constant and one with a variable, and X86 prices them differently. The
+; cost of the vector ne must not come from one of the ne lanes alone.
+
+; YAML-LABEL: --- !Passed
+; YAML-NEXT:  Pass:            slp-vectorizer
+; YAML-NEXT:  Name:            StoresVectorized
+; YAML-NEXT:  Function:        alt_cmp_ne_lanes
+; YAML-NEXT:  Args:
+; YAML-NEXT:    - String:          'Stores SLP vectorized with cost '
+; YAML-NEXT:    - Cost:            '-6'
+; YAML-NEXT:    - String:          ' and with tree size '
+; YAML-NEXT:    - TreeSize:        '6'
+
+define void @alt_cmp_ne_lanes(ptr %a, ptr %b, ptr %out) {
+; CHECK-LABEL: define void @alt_cmp_ne_lanes(
+; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[OUT:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TMP0:%.*]] = load <4 x i32>, ptr [[A]], align 4
+; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x i32>, ptr [[B]], align 4
+; CHECK-NEXT:    [[TMP2:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
+; CHECK-NEXT:    [[TMP3:%.*]] = shufflevector <4 x i32> <i32 poison, i32 0, i32 poison, i32 poison>, <4 x i32> [[TMP2]], <4 x i32> <i32 4, i32 1, i32 poison, i32 poison>
+; CHECK-NEXT:    [[TMP4:%.*]] = shufflevector <4 x i32> [[TMP3]], <4 x i32> [[TMP2]], <4 x i32> <i32 0, i32 1, i32 4, i32 5>
+; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq <4 x i32> [[TMP0]], [[TMP4]]
+; CHECK-NEXT:    [[TMP6:%.*]] = icmp ne <4 x i32> [[TMP0]], [[TMP4]]
+; CHECK-NEXT:    [[TMP7:%.*]] = shufflevector <4 x i1> [[TMP5]], <4 x i1> [[TMP6]], <4 x i32> <i32 0, i32 5, i32 2, i32 7>
+; CHECK-NEXT:    [[TMP8:%.*]] = zext <4 x i1> [[TMP7]] to <4 x i32>
+; CHECK-NEXT:    store <4 x i32> [[TMP8]], ptr [[OUT]], align 4
+; CHECK-NEXT:    ret void
+;
+entry:
+  %a0 = load i32, ptr %a, align 4
+  %ap1 = getelementptr inbounds i32, ptr %a, i64 1
+  %a1 = load i32, ptr %ap1, align 4
+  %ap2 = getelementptr inbounds i32, ptr %a, i64 2
+  %a2 = load i32, ptr %ap2, align 4
+  %ap3 = getelementptr inbounds i32, ptr %a, i64 3
+  %a3 = load i32, ptr %ap3, align 4
+  %b0 = load i32, ptr %b, align 4
+  %bp1 = getelementptr inbounds i32, ptr %b, i64 1
+  %b1 = load i32, ptr %bp1, align 4
+  %c0 = icmp eq i32 %a0, %b0
+  %c1 = icmp ne i32 %a1, 0
+  %c2 = icmp eq i32 %a2, %b0
+  %c3 = icmp ne i32 %a3, %b1
+  %z0 = zext i1 %c0 to i32
+  %z1 = zext i1 %c1 to i32
+  %z2 = zext i1 %c2 to i32
+  %z3 = zext i1 %c3 to i32
+  store i32 %z0, ptr %out, align 4
+  %o1 = getelementptr inbounds i32, ptr %out, i64 1
+  store i32 %z1, ptr %o1, align 4
+  %o2 = getelementptr inbounds i32, ptr %out, i64 2
+  store i32 %z2, ptr %o2, align 4
+  %o3 = getelementptr inbounds i32, ptr %out, i64 3
+  store i32 %z3, ptr %o3, align 4
+  ret void
+}

>From 3a1a876f1e4a677737208fa6422f42c242d4c302 Mon Sep 17 00:00:00 2001
From: Michael Selehov <michael.selehov at amd.com>
Date: Wed, 11 Nov 2026 10:11:52 -0600
Subject: [PATCH 2/2] [SLP] Pass a lane as the vector cost context only if all
 lanes agree

getEntryCost prices a vector instruction with one scalar lane as the
context, while each scalar lane is priced in its own context. A target
that reads the context, like the users of an fmul that fuses into an fma
on AMDGPU or a bit select on AArch64, gives the whole vector the property
of that one lane.

Pass the lane as the context only if the vector cost is the same with any
of the represented lanes as the context.

Assisted-by: Claude Opus
---
 .../Transforms/Vectorize/SLPVectorizer.cpp    | 134 ++++++++++++++----
 .../AArch64/and-bsl-ctx-mixed-lanes.ll        |  25 ++--
 .../AMDGPU/fdiv-afn-ctx-lanes.ll              |  21 ++-
 .../AMDGPU/fmul-fusion-ctx-mixed-lanes.ll     |  28 +++-
 .../X86/remark-alt-cmp-ctx-lanes.ll           |   2 +-
 5 files changed, 153 insertions(+), 57 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index fbdb3501a9f7e..a615abc41d385 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -16676,6 +16676,26 @@ static std::optional<unsigned> getCastOpcodeForDemotedOperand(unsigned Opcode,
   }
 }
 
+/// Returns \p Cost with \p Repr as the context if every lane of \p VL that
+/// \p Repr represents gives the same cost as its context, and \p Cost without
+/// a context otherwise.
+static InstructionCost getCostInAgreedContext(
+    ArrayRef<Value *> VL, Instruction *Repr,
+    function_ref<bool(Instruction *)> IsReprLane,
+    function_ref<InstructionCost(const Instruction *)> Cost) {
+  if (!Repr || !IsReprLane(Repr) || !is_contained(VL, Repr))
+    return Cost(nullptr);
+  const InstructionCost ReprCost = Cost(Repr);
+  SmallPtrSet<Instruction *, 8> Checked;
+  Checked.insert(Repr);
+  for (Value *V : VL) {
+    auto *I = dyn_cast<Instruction>(V);
+    if (I && IsReprLane(I) && Checked.insert(I).second && Cost(I) != ReprCost)
+      return Cost(nullptr);
+  }
+  return ReprCost;
+}
+
 InstructionCost
 BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
                       SmallPtrSetImpl<Value *> &CheckedExtracts) {
@@ -17317,8 +17337,16 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
                                 SrcVecTy->getScalarType(),
                                 TTI::getCastContextHint(VL0), CostKind) == 0)
         VI = nullptr;
-      return CommonCost + TTI->getCastInstrCost(VecOpcode, VecTy, SrcVecTy, CCH,
-                                                CostKind, VI);
+      return CommonCost +
+             getCostInAgreedContext(
+                 E->Scalars, VI,
+                 [&](Instruction *I) {
+                   return I->getOpcode() == Opcode && !E->isCopyableElement(I);
+                 },
+                 [&](const Instruction *CtxI) {
+                   return TTI->getCastInstrCost(VecOpcode, VecTy, SrcVecTy, CCH,
+                                                CostKind, CtxI);
+                 });
     };
     return GetCostDiff(GetScalarCost, GetVectorCost);
   }
@@ -17469,13 +17497,21 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
         }
       }
       if (!VecCost.isValid()) {
-        VecCost = TTI->getCmpSelInstrCost(
-            E->getOpcode(), VecTy, MaskTy, VecPred, CostKind,
-            TTI::getOperandInfo(
-                E->getOperand(ShuffleOrOp == Instruction::Select ? 1 : 0)),
-            TTI::getOperandInfo(
-                E->getOperand(ShuffleOrOp == Instruction::Select ? 2 : 1)),
-            VL0);
+        TTI::OperandValueInfo Op1Info = TTI::getOperandInfo(
+            E->getOperand(ShuffleOrOp == Instruction::Select ? 1 : 0));
+        TTI::OperandValueInfo Op2Info = TTI::getOperandInfo(
+            E->getOperand(ShuffleOrOp == Instruction::Select ? 2 : 1));
+        VecCost = getCostInAgreedContext(
+            E->Scalars, VL0,
+            [&](Instruction *I) {
+              return I->getOpcode() == E->getOpcode() &&
+                     !E->isCopyableElement(I);
+            },
+            [&](const Instruction *CtxI) {
+              return TTI->getCmpSelInstrCost(E->getOpcode(), VecTy, MaskTy,
+                                             VecPred, CostKind, Op1Info,
+                                             Op2Info, CtxI);
+            });
         if (IsBitTest)
           VecCost +=
               TTI->getArithmeticInstrCost(Instruction::And, VecTy, CostKind);
@@ -17807,9 +17843,20 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
       unsigned OpIdx = isa<UnaryOperator>(VL0) ? 0 : 1;
       TTI::OperandValueInfo Op1Info = TTI::getOperandInfo(E->getOperand(0));
       TTI::OperandValueInfo Op2Info = TTI::getOperandInfo(E->getOperand(OpIdx));
-      InstructionCost Cost = TTI->getArithmeticInstrCost(
-          ShuffleOrOp, VecTy, CostKind, Op1Info, Op2Info, {},
-          VL0->getOpcode() == ShuffleOrOp ? VL0 : nullptr, TLI);
+      auto GetBinOpCost = [&](TTI::OperandValueInfo LHSInfo,
+                              TTI::OperandValueInfo RHSInfo) {
+        return getCostInAgreedContext(
+            E->Scalars, VL0,
+            [&](Instruction *I) {
+              return I->getOpcode() == ShuffleOrOp && !E->isCopyableElement(I);
+            },
+            [&](const Instruction *CtxI) {
+              return TTI->getArithmeticInstrCost(ShuffleOrOp, VecTy, CostKind,
+                                                 LHSInfo, RHSInfo, {}, CtxI,
+                                                 TLI);
+            });
+      };
+      InstructionCost Cost = GetBinOpCost(Op1Info, Op2Info);
       // N columns need N-1 vector combines; price extra columns
       // conservatively, skipping identity-only columns (not combined by
       // codegen).
@@ -17823,10 +17870,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
             continue;
           // The first operand is the running fold, a computed value with no
           // static properties to model.
-          Cost += TTI->getArithmeticInstrCost(
-              ShuffleOrOp, VecTy, CostKind, {},
-              TTI::getOperandInfo(E->getOperand(Idx)), {},
-              VL0->getOpcode() == ShuffleOrOp ? VL0 : nullptr, TLI);
+          Cost += GetBinOpCost({}, TTI::getOperandInfo(E->getOperand(Idx)));
         }
       }
       return Cost + CommonCost;
@@ -18156,6 +18200,21 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
       // VecCost is equal to sum of the cost of creating 2 vectors
       // and the cost of creating shuffle.
       InstructionCost VecCost = 0;
+      // Lanes are split the way the alternate shuffle mask splits them; for
+      // compares this tells the predicates apart, not only the opcodes.
+      auto GetAltCost =
+          [&](Instruction *Repr,
+              function_ref<InstructionCost(const Instruction *)> Cost) {
+            const bool IsAlt = Repr == E->getAltOp();
+            return getCostInAgreedContext(
+                E->Scalars, Repr,
+                [&](Instruction *I) {
+                  return !E->isCopyableElement(I) &&
+                         isAlternateInstruction(I, E->getMainOp(),
+                                                E->getAltOp(), *TLI) == IsAlt;
+                },
+                Cost);
+          };
       if (TryFindNodeWithEqualOperands()) {
         LLVM_DEBUG({
           dbgs() << "SLP: diamond match for alternate node found.\n";
@@ -18174,16 +18233,19 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
         // folded column is uniform.
         auto ChainCost = [&](unsigned Opcode) {
           InstructionCost Cost = 0;
+          Instruction *Repr =
+              Opcode == E->getOpcode() ? E->getMainOp() : E->getAltOp();
           TTI::OperandValueInfo RunningInfo =
               TTI::getOperandInfo(E->getOperand(0));
           for (unsigned Idx : seq<unsigned>(1, E->getNumOperands())) {
             TTI::OperandValueInfo ColInfo =
                 TTI::getOperandInfo(E->getOperand(Idx));
             if (!RunningInfo.isConstant() || !ColInfo.isConstant())
-              Cost += TTIRef.getArithmeticInstrCost(
-                  Opcode, VecTy, CostKind, RunningInfo, ColInfo, {},
-                  Opcode == E->getOpcode() ? E->getMainOp() : E->getAltOp(),
-                  TLI);
+              Cost += GetAltCost(Repr, [&](const Instruction *CtxI) {
+                return TTIRef.getArithmeticInstrCost(Opcode, VecTy, CostKind,
+                                                     RunningInfo, ColInfo, {},
+                                                     CtxI, TLI);
+              });
             TTI::OperandValueKind Kind = TTI::OK_AnyValue;
             if (RunningInfo.isConstant() && ColInfo.isConstant())
               Kind = RunningInfo.Kind == TTI::OK_UniformConstantValue &&
@@ -18201,13 +18263,16 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
         auto *MaskTy = getWidenedType(Builder.getInt1Ty(), VL.size());
         TTI::OperandValueInfo Op0Info = TTI::getOperandInfo(E->getOperand(0));
         TTI::OperandValueInfo Op1Info = TTI::getOperandInfo(E->getOperand(1));
-        VecCost = TTIRef.getCmpSelInstrCost(E->getOpcode(), VecTy, MaskTy,
-                                            CI0->getPredicate(), CostKind,
-                                            Op0Info, Op1Info, VL0);
-        VecCost += TTIRef.getCmpSelInstrCost(
-            E->getOpcode(), VecTy, MaskTy,
-            cast<CmpInst>(E->getAltOp())->getPredicate(), CostKind, Op0Info,
-            Op1Info, E->getAltOp());
+        auto CmpCost = [&](Instruction *Repr, CmpInst::Predicate Pred) {
+          return GetAltCost(Repr, [&](const Instruction *CtxI) {
+            return TTIRef.getCmpSelInstrCost(E->getOpcode(), VecTy, MaskTy,
+                                             Pred, CostKind, Op0Info, Op1Info,
+                                             CtxI);
+          });
+        };
+        VecCost = CmpCost(VL0, CI0->getPredicate()) +
+                  CmpCost(E->getAltOp(),
+                          cast<CmpInst>(E->getAltOp())->getPredicate());
       } else {
         Type *SrcTy =
             getWidenedType(E->getMainOp()->getOperand(0)->getType(), VL.size());
@@ -18254,10 +18319,17 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
         if (Opcode0 == Opcode1)
           return VecCost +
                  TTIRef.getCastInstrCost(Opcode0, VecTy, SrcTy, CCH, CostKind);
-        VecCost += TTIRef.getCastInstrCost(Opcode0, VecTy, SrcTy, CCH, CostKind,
-                                           E->getMainOp());
-        VecCost += TTIRef.getCastInstrCost(Opcode1, VecTy, SrcTy, CCH, CostKind,
-                                           E->getAltOp());
+        // A demoted cast is not the instruction it was demoted from, so the
+        // original cast is no context for it.
+        auto CastCost = [&](unsigned Opcode, Instruction *Repr) {
+          return GetAltCost(Repr->getOpcode() == Opcode ? Repr : nullptr,
+                            [&](const Instruction *CtxI) {
+                              return TTIRef.getCastInstrCost(
+                                  Opcode, VecTy, SrcTy, CCH, CostKind, CtxI);
+                            });
+        };
+        VecCost += CastCost(Opcode0, E->getMainOp()) +
+                   CastCost(Opcode1, E->getAltOp());
       }
       SmallVector<int> Mask;
       E->buildAltOpShuffleMask(
diff --git a/llvm/test/Transforms/SLPVectorizer/AArch64/and-bsl-ctx-mixed-lanes.ll b/llvm/test/Transforms/SLPVectorizer/AArch64/and-bsl-ctx-mixed-lanes.ll
index be287c280fad0..d8b22e20b73f3 100644
--- a/llvm/test/Transforms/SLPVectorizer/AArch64/and-bsl-ctx-mixed-lanes.ll
+++ b/llvm/test/Transforms/SLPVectorizer/AArch64/and-bsl-ctx-mixed-lanes.ll
@@ -10,17 +10,20 @@ define void @bsl_lane0(ptr %x, i64 %y, i64 %m0, i64 %m1, i64 %w1, ptr %out) {
 ; CHECK-LABEL: define void @bsl_lane0(
 ; CHECK-SAME: ptr [[X:%.*]], i64 [[Y:%.*]], i64 [[M0:%.*]], i64 [[M1:%.*]], i64 [[W1:%.*]], ptr [[OUT:%.*]]) {
 ; CHECK-NEXT:  [[ENTRY:.*:]]
-; CHECK-NEXT:    [[TMP0:%.*]] = insertelement <2 x i64> poison, i64 [[M0]], i64 0
-; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <2 x i64> [[TMP0]], i64 [[W1]], i64 1
-; CHECK-NEXT:    [[TMP2:%.*]] = xor <2 x i64> [[TMP1]], splat (i64 -1)
-; CHECK-NEXT:    [[TMP3:%.*]] = load <2 x i64>, ptr [[X]], align 8
-; CHECK-NEXT:    [[TMP4:%.*]] = insertelement <2 x i64> [[TMP1]], i64 [[M1]], i64 1
-; CHECK-NEXT:    [[TMP5:%.*]] = and <2 x i64> [[TMP3]], [[TMP4]]
-; CHECK-NEXT:    [[TMP6:%.*]] = insertelement <2 x i64> poison, i64 [[Y]], i64 0
-; CHECK-NEXT:    [[TMP7:%.*]] = shufflevector <2 x i64> [[TMP6]], <2 x i64> poison, <2 x i32> zeroinitializer
-; CHECK-NEXT:    [[TMP8:%.*]] = and <2 x i64> [[TMP7]], [[TMP2]]
-; CHECK-NEXT:    [[TMP9:%.*]] = or <2 x i64> [[TMP5]], [[TMP8]]
-; CHECK-NEXT:    store <2 x i64> [[TMP9]], ptr [[OUT]], align 8
+; CHECK-NEXT:    [[X0:%.*]] = load i64, ptr [[X]], align 8
+; CHECK-NEXT:    [[PX1:%.*]] = getelementptr inbounds i64, ptr [[X]], i64 1
+; CHECK-NEXT:    [[X1:%.*]] = load i64, ptr [[PX1]], align 8
+; CHECK-NEXT:    [[N0:%.*]] = xor i64 [[M0]], -1
+; CHECK-NEXT:    [[N1:%.*]] = xor i64 [[W1]], -1
+; CHECK-NEXT:    [[A0:%.*]] = and i64 [[X0]], [[M0]]
+; CHECK-NEXT:    [[A1:%.*]] = and i64 [[X1]], [[M1]]
+; CHECK-NEXT:    [[B0:%.*]] = and i64 [[Y]], [[N0]]
+; CHECK-NEXT:    [[B1:%.*]] = and i64 [[Y]], [[N1]]
+; CHECK-NEXT:    [[O0:%.*]] = or i64 [[A0]], [[B0]]
+; CHECK-NEXT:    [[O1:%.*]] = or i64 [[A1]], [[B1]]
+; CHECK-NEXT:    store i64 [[O0]], ptr [[OUT]], align 8
+; CHECK-NEXT:    [[PO1:%.*]] = getelementptr inbounds i64, ptr [[OUT]], i64 1
+; CHECK-NEXT:    store i64 [[O1]], ptr [[PO1]], align 8
 ; CHECK-NEXT:    ret void
 ;
 entry:
diff --git a/llvm/test/Transforms/SLPVectorizer/AMDGPU/fdiv-afn-ctx-lanes.ll b/llvm/test/Transforms/SLPVectorizer/AMDGPU/fdiv-afn-ctx-lanes.ll
index 8b9554af55bae..f8953761552fc 100644
--- a/llvm/test/Transforms/SLPVectorizer/AMDGPU/fdiv-afn-ctx-lanes.ll
+++ b/llvm/test/Transforms/SLPVectorizer/AMDGPU/fdiv-afn-ctx-lanes.ll
@@ -9,17 +9,24 @@ define void @fdiv_mixed(ptr %a, ptr %b, ptr %out) {
 ; CHECK-LABEL: define void @fdiv_mixed(
 ; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[OUT:%.*]]) {
 ; CHECK-NEXT:  [[ENTRY:.*:]]
-; CHECK-NEXT:    [[AP1:%.*]] = getelementptr inbounds float, ptr [[A]], i64 2
-; CHECK-NEXT:    [[BP1:%.*]] = getelementptr inbounds float, ptr [[B]], i64 2
-; CHECK-NEXT:    [[TMP3:%.*]] = load <2 x float>, ptr [[A]], align 4
-; CHECK-NEXT:    [[TMP4:%.*]] = load <2 x float>, ptr [[B]], align 4
-; CHECK-NEXT:    [[TMP5:%.*]] = fdiv <2 x float> [[TMP3]], [[TMP4]]
-; CHECK-NEXT:    [[O1:%.*]] = getelementptr inbounds float, ptr [[OUT]], i64 2
+; CHECK-NEXT:    [[A0:%.*]] = load float, ptr [[A]], align 4
+; CHECK-NEXT:    [[AP1:%.*]] = getelementptr inbounds float, ptr [[A]], i64 1
+; CHECK-NEXT:    [[AP3:%.*]] = getelementptr inbounds float, ptr [[A]], i64 3
+; CHECK-NEXT:    [[A3:%.*]] = load float, ptr [[AP3]], align 4
+; CHECK-NEXT:    [[B0:%.*]] = load float, ptr [[B]], align 4
+; CHECK-NEXT:    [[BP1:%.*]] = getelementptr inbounds float, ptr [[B]], i64 1
+; CHECK-NEXT:    [[BP3:%.*]] = getelementptr inbounds float, ptr [[B]], i64 3
+; CHECK-NEXT:    [[B3:%.*]] = load float, ptr [[BP3]], align 4
+; CHECK-NEXT:    [[D0:%.*]] = fdiv afn float [[A0]], [[B0]]
+; CHECK-NEXT:    [[D3:%.*]] = fdiv float [[A3]], [[B3]]
+; CHECK-NEXT:    [[O1:%.*]] = getelementptr inbounds float, ptr [[OUT]], i64 1
 ; CHECK-NEXT:    [[TMP0:%.*]] = load <2 x float>, ptr [[AP1]], align 4
 ; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x float>, ptr [[BP1]], align 4
 ; CHECK-NEXT:    [[TMP2:%.*]] = fdiv <2 x float> [[TMP0]], [[TMP1]]
-; CHECK-NEXT:    store <2 x float> [[TMP5]], ptr [[OUT]], align 4
+; CHECK-NEXT:    store float [[D0]], ptr [[OUT]], align 4
 ; CHECK-NEXT:    store <2 x float> [[TMP2]], ptr [[O1]], align 4
+; CHECK-NEXT:    [[O3:%.*]] = getelementptr inbounds float, ptr [[OUT]], i64 3
+; CHECK-NEXT:    store float [[D3]], ptr [[O3]], align 4
 ; CHECK-NEXT:    ret void
 ;
 entry:
diff --git a/llvm/test/Transforms/SLPVectorizer/AMDGPU/fmul-fusion-ctx-mixed-lanes.ll b/llvm/test/Transforms/SLPVectorizer/AMDGPU/fmul-fusion-ctx-mixed-lanes.ll
index 95e84c99925bc..2ecff1f6b7688 100644
--- a/llvm/test/Transforms/SLPVectorizer/AMDGPU/fmul-fusion-ctx-mixed-lanes.ll
+++ b/llvm/test/Transforms/SLPVectorizer/AMDGPU/fmul-fusion-ctx-mixed-lanes.ll
@@ -9,18 +9,32 @@
 define double @mixed_lanes(ptr noalias %e, ptr %a, ptr %b) {
 ; CHECK-LABEL: define double @mixed_lanes(
 ; CHECK-SAME: ptr noalias [[E:%.*]], ptr [[A:%.*]], ptr [[B:%.*]]) {
-; CHECK-NEXT:    [[TMP1:%.*]] = load <4 x double>, ptr [[A]], align 8
-; CHECK-NEXT:    [[TMP2:%.*]] = load <4 x double>, ptr [[B]], align 8
-; CHECK-NEXT:    [[TMP3:%.*]] = fmul reassoc contract <4 x double> [[TMP1]], [[TMP2]]
-; CHECK-NEXT:    [[M1:%.*]] = extractelement <4 x double> [[TMP3]], i64 1
+; CHECK-NEXT:    [[A0:%.*]] = load double, ptr [[A]], align 8
+; CHECK-NEXT:    [[B0:%.*]] = load double, ptr [[B]], align 8
+; CHECK-NEXT:    [[AP1:%.*]] = getelementptr inbounds double, ptr [[A]], i64 1
+; CHECK-NEXT:    [[BP1:%.*]] = getelementptr inbounds double, ptr [[B]], i64 1
+; CHECK-NEXT:    [[A1:%.*]] = load double, ptr [[AP1]], align 8
+; CHECK-NEXT:    [[B1:%.*]] = load double, ptr [[BP1]], align 8
+; CHECK-NEXT:    [[AP2:%.*]] = getelementptr inbounds double, ptr [[A]], i64 2
+; CHECK-NEXT:    [[BP2:%.*]] = getelementptr inbounds double, ptr [[B]], i64 2
+; CHECK-NEXT:    [[A2:%.*]] = load double, ptr [[AP2]], align 8
+; CHECK-NEXT:    [[B2:%.*]] = load double, ptr [[BP2]], align 8
+; CHECK-NEXT:    [[AP3:%.*]] = getelementptr inbounds double, ptr [[A]], i64 3
+; CHECK-NEXT:    [[BP3:%.*]] = getelementptr inbounds double, ptr [[B]], i64 3
+; CHECK-NEXT:    [[A3:%.*]] = load double, ptr [[AP3]], align 8
+; CHECK-NEXT:    [[B3:%.*]] = load double, ptr [[BP3]], align 8
+; CHECK-NEXT:    [[M0:%.*]] = fmul reassoc contract double [[A0]], [[B0]]
+; CHECK-NEXT:    [[M1:%.*]] = fmul reassoc contract double [[A1]], [[B1]]
+; CHECK-NEXT:    [[M2:%.*]] = fmul reassoc contract double [[A2]], [[B2]]
+; CHECK-NEXT:    [[M3:%.*]] = fmul reassoc contract double [[A3]], [[B3]]
 ; CHECK-NEXT:    store double [[M1]], ptr [[E]], align 8
 ; CHECK-NEXT:    [[E2:%.*]] = getelementptr inbounds double, ptr [[E]], i64 1
-; CHECK-NEXT:    [[M2:%.*]] = extractelement <4 x double> [[TMP3]], i64 2
 ; CHECK-NEXT:    store double [[M2]], ptr [[E2]], align 8
 ; CHECK-NEXT:    [[E3:%.*]] = getelementptr inbounds double, ptr [[E]], i64 2
-; CHECK-NEXT:    [[M3:%.*]] = extractelement <4 x double> [[TMP3]], i64 3
 ; CHECK-NEXT:    store double [[M3]], ptr [[E3]], align 8
-; CHECK-NEXT:    [[S3:%.*]] = call reassoc contract double @llvm.vector.reduce.fadd.v4f64(double -0.000000e+00, <4 x double> [[TMP3]])
+; CHECK-NEXT:    [[S1:%.*]] = fadd reassoc contract double [[M0]], [[M1]]
+; CHECK-NEXT:    [[S2:%.*]] = fadd reassoc contract double [[S1]], [[M2]]
+; CHECK-NEXT:    [[S3:%.*]] = fadd reassoc contract double [[S2]], [[M3]]
 ; CHECK-NEXT:    ret double [[S3]]
 ;
   %a0 = load double, ptr %a
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/remark-alt-cmp-ctx-lanes.ll b/llvm/test/Transforms/SLPVectorizer/X86/remark-alt-cmp-ctx-lanes.ll
index 37def1ad04f60..7c04553ccc92b 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/remark-alt-cmp-ctx-lanes.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/remark-alt-cmp-ctx-lanes.ll
@@ -12,7 +12,7 @@
 ; YAML-NEXT:  Function:        alt_cmp_ne_lanes
 ; YAML-NEXT:  Args:
 ; YAML-NEXT:    - String:          'Stores SLP vectorized with cost '
-; YAML-NEXT:    - Cost:            '-6'
+; YAML-NEXT:    - Cost:            '-5'
 ; YAML-NEXT:    - String:          ' and with tree size '
 ; YAML-NEXT:    - TreeSize:        '6'
 



More information about the llvm-branch-commits mailing list