[llvm] [InstCombinePHI] Enable gep arg fold transform with constant indices (PR #174981)

Jessica Del via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 30 08:16:38 PDT 2026


https://github.com/OutOfCache updated https://github.com/llvm/llvm-project/pull/174981

>From ed5cf8a1b377a29d5413ff6767636cae9c88f912 Mon Sep 17 00:00:00 2001
From: Jessica Del <Jessica.Del at amd.com>
Date: Thu, 8 Jan 2026 09:33:18 +0100
Subject: [PATCH 01/10] [InstCombinePHI][NFC] Prevent gep canonicalization in
 testcase

GEP canonicalization unintentionally prevents the faulty behavior which
was tested.

InstCombine prevents the transformation of a gep, which indexes a struct,
into a gep with a variable index, since that is not valid LLVM IR.
It does so by checking if the gep only has constant indices.

The original test checks this scenario, even for constant vector
indices. Without the constant check, the test is supposed to crash.

However, after the getelementptr is canonicalized into a `gep i8, ptr %ptr,
i64`, the test case can actually be transformed without an issue.

In a followup change, we want to allow the transformation of geps with
constant indices, if they do not index into a struct.
Therefore, the constant index check needs to be changed accordingly to
properly check the indexed type and whether it is a struct or not.

Since canonicalization loses the type information, we modified the test
so it would still trigger a crash, by avoiding the canonicalization.
This is done by introducing a variable index and visiting the phi before
the geps (so they would not be canonicalized or split).
---
 .../fold-phi-arg-gep-to-phi-negative.ll       | 36 +++++++++++--------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi-negative.ll b/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi-negative.ll
index c5f9dc1861704..4278e60bd2d44 100644
--- a/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi-negative.ll
+++ b/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi-negative.ll
@@ -3,37 +3,45 @@
 
 %foo = type { i16, i16, i16 }
 
-define <16 x ptr> @test(i1 %tobool) {
+define <16 x ptr> @test(i1 %tobool, i1 %end, <16 x i64> %varidx) {
 ; CHECK-LABEL: define <16 x ptr> @test(
-; CHECK-SAME: i1 [[TOBOOL:%.*]]) {
-; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-SAME: i1 [[TOBOOL:%.*]], i1 [[END:%.*]], <16 x i64> [[VARIDX:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*]]:
 ; CHECK-NEXT:    [[LANE_0:%.*]] = alloca [[FOO:%.*]], align 16
 ; CHECK-NEXT:    [[LANE_15:%.*]] = insertelement <16 x ptr> poison, ptr [[LANE_0]], i64 0
-; CHECK-NEXT:    br i1 [[TOBOOL]], label %[[F1:.*]], label %[[F0:.*]]
+; CHECK-NEXT:    br label %[[LOOP:.*]]
+; CHECK:       [[LOOP]]:
+; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <16 x ptr> [ [[MM_VECTORGEP11:%.*]], %[[F0:.*]] ], [ [[MM_VECTORGEP22:%.*]], %[[F1:.*]] ], [ zeroinitializer, %[[ENTRY]] ]
+; CHECK-NEXT:    br i1 [[TOBOOL]], label %[[F1]], label %[[F0]]
 ; CHECK:       [[F0]]:
-; CHECK-NEXT:    [[MM_VECTORGEP1:%.*]] = getelementptr inbounds i8, <16 x ptr> [[LANE_15]], i64 2
-; CHECK-NEXT:    br label %[[MERGE:.*]]
+; CHECK-NEXT:    [[MM_VECTORGEP11_SPLIT:%.*]] = getelementptr inbounds [[FOO]], <16 x ptr> [[LANE_15]], <16 x i64> [[VARIDX]]
+; CHECK-NEXT:    [[MM_VECTORGEP11]] = getelementptr inbounds i8, <16 x ptr> [[MM_VECTORGEP11_SPLIT]], i64 2
+; CHECK-NEXT:    br i1 [[END]], label %[[LOOP]], label %[[MERGE:.*]]
 ; CHECK:       [[F1]]:
-; CHECK-NEXT:    [[MM_VECTORGEP22:%.*]] = getelementptr inbounds i8, <16 x ptr> [[LANE_15]], i64 4
-; CHECK-NEXT:    br label %[[MERGE]]
+; CHECK-NEXT:    [[MM_VECTORGEP22_SPLIT:%.*]] = getelementptr inbounds [[FOO]], <16 x ptr> [[LANE_15]], <16 x i64> [[VARIDX]]
+; CHECK-NEXT:    [[MM_VECTORGEP22]] = getelementptr inbounds i8, <16 x ptr> [[MM_VECTORGEP22_SPLIT]], i64 4
+; CHECK-NEXT:    br i1 [[END]], label %[[LOOP]], label %[[MERGE]]
 ; CHECK:       [[MERGE]]:
-; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <16 x ptr> [ [[MM_VECTORGEP1]], %[[F0]] ], [ [[MM_VECTORGEP22]], %[[F1]] ]
 ; CHECK-NEXT:    ret <16 x ptr> [[VEC_PHI]]
 ;
 entry:
   %lane.0 = alloca %foo, align 16
   %lane.15 = insertelement <16 x ptr> poison, ptr %lane.0, i64 0
-  %mm_vectorGEP = getelementptr inbounds %foo, <16 x ptr> %lane.15, <16 x i64> zeroinitializer, <16 x i32> splat (i32 1)
-  %mm_vectorGEP2 = getelementptr inbounds %foo, <16 x ptr> %lane.15, <16 x i64> zeroinitializer, <16 x i32> splat (i32 2)
+  br label %loop
+
+loop:
+  %vec.phi = phi <16 x ptr> [ %mm_vectorGEP1, %f0], [ %mm_vectorGEP2, %f1 ], [ zeroinitializer, %entry]
+  %mm_vectorGEP1 = getelementptr inbounds %foo, <16 x ptr> %lane.15, <16 x i64> %varidx, <16 x i32> splat (i32 1)
+  %mm_vectorGEP2 = getelementptr inbounds %foo, <16 x ptr> %lane.15, <16 x i64> %varidx, <16 x i32> splat (i32 2)
   br i1 %tobool, label %f1, label %f0
 
 f0:
-  br label %merge
+  br i1 %end, label %loop, label %merge
 
 f1:
-  br label %merge
+  br i1 %end, label %loop, label %merge
 
 merge:
-  %vec.phi = phi <16 x ptr> [ %mm_vectorGEP, %f0], [ %mm_vectorGEP2, %f1 ]
   ret <16 x ptr> %vec.phi
 }
+

>From 4e0952f80fc4cfbe082f8fcb1cbaf94eaa2066ba Mon Sep 17 00:00:00 2001
From: Jessica Del <Jessica.Del at amd.com>
Date: Tue, 16 Dec 2025 22:38:39 +0100
Subject: [PATCH 02/10] [InstCombine] Add tests for gep arg folding

---
 .../fold-phi-arg-gep-to-phi-negative.ll       |  47 ----
 .../InstCombine/fold-phi-arg-gep-to-phi.ll    | 202 ++++++++++++++++++
 2 files changed, 202 insertions(+), 47 deletions(-)
 delete mode 100644 llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi-negative.ll
 create mode 100644 llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll

diff --git a/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi-negative.ll b/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi-negative.ll
deleted file mode 100644
index 4278e60bd2d44..0000000000000
--- a/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi-negative.ll
+++ /dev/null
@@ -1,47 +0,0 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
-; RUN: opt < %s -passes=instcombine -S | FileCheck %s
-
-%foo = type { i16, i16, i16 }
-
-define <16 x ptr> @test(i1 %tobool, i1 %end, <16 x i64> %varidx) {
-; CHECK-LABEL: define <16 x ptr> @test(
-; CHECK-SAME: i1 [[TOBOOL:%.*]], i1 [[END:%.*]], <16 x i64> [[VARIDX:%.*]]) {
-; CHECK-NEXT:  [[ENTRY:.*]]:
-; CHECK-NEXT:    [[LANE_0:%.*]] = alloca [[FOO:%.*]], align 16
-; CHECK-NEXT:    [[LANE_15:%.*]] = insertelement <16 x ptr> poison, ptr [[LANE_0]], i64 0
-; CHECK-NEXT:    br label %[[LOOP:.*]]
-; CHECK:       [[LOOP]]:
-; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <16 x ptr> [ [[MM_VECTORGEP11:%.*]], %[[F0:.*]] ], [ [[MM_VECTORGEP22:%.*]], %[[F1:.*]] ], [ zeroinitializer, %[[ENTRY]] ]
-; CHECK-NEXT:    br i1 [[TOBOOL]], label %[[F1]], label %[[F0]]
-; CHECK:       [[F0]]:
-; CHECK-NEXT:    [[MM_VECTORGEP11_SPLIT:%.*]] = getelementptr inbounds [[FOO]], <16 x ptr> [[LANE_15]], <16 x i64> [[VARIDX]]
-; CHECK-NEXT:    [[MM_VECTORGEP11]] = getelementptr inbounds i8, <16 x ptr> [[MM_VECTORGEP11_SPLIT]], i64 2
-; CHECK-NEXT:    br i1 [[END]], label %[[LOOP]], label %[[MERGE:.*]]
-; CHECK:       [[F1]]:
-; CHECK-NEXT:    [[MM_VECTORGEP22_SPLIT:%.*]] = getelementptr inbounds [[FOO]], <16 x ptr> [[LANE_15]], <16 x i64> [[VARIDX]]
-; CHECK-NEXT:    [[MM_VECTORGEP22]] = getelementptr inbounds i8, <16 x ptr> [[MM_VECTORGEP22_SPLIT]], i64 4
-; CHECK-NEXT:    br i1 [[END]], label %[[LOOP]], label %[[MERGE]]
-; CHECK:       [[MERGE]]:
-; CHECK-NEXT:    ret <16 x ptr> [[VEC_PHI]]
-;
-entry:
-  %lane.0 = alloca %foo, align 16
-  %lane.15 = insertelement <16 x ptr> poison, ptr %lane.0, i64 0
-  br label %loop
-
-loop:
-  %vec.phi = phi <16 x ptr> [ %mm_vectorGEP1, %f0], [ %mm_vectorGEP2, %f1 ], [ zeroinitializer, %entry]
-  %mm_vectorGEP1 = getelementptr inbounds %foo, <16 x ptr> %lane.15, <16 x i64> %varidx, <16 x i32> splat (i32 1)
-  %mm_vectorGEP2 = getelementptr inbounds %foo, <16 x ptr> %lane.15, <16 x i64> %varidx, <16 x i32> splat (i32 2)
-  br i1 %tobool, label %f1, label %f0
-
-f0:
-  br i1 %end, label %loop, label %merge
-
-f1:
-  br i1 %end, label %loop, label %merge
-
-merge:
-  ret <16 x ptr> %vec.phi
-}
-
diff --git a/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll b/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll
new file mode 100644
index 0000000000000..41f0bbac2e30b
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll
@@ -0,0 +1,202 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+%foo = type { i16, i16, i16 }
+
+define <16 x ptr> @test(i1 %tobool, i1 %end, <16 x i64> %varidx) {
+; CHECK-LABEL: define <16 x ptr> @test(
+; CHECK-SAME: i1 [[TOBOOL:%.*]], i1 [[END:%.*]], <16 x i64> [[VARIDX:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*]]:
+; CHECK-NEXT:    [[LANE_0:%.*]] = alloca [[FOO:%.*]], align 16
+; CHECK-NEXT:    [[LANE_15:%.*]] = insertelement <16 x ptr> poison, ptr [[LANE_0]], i64 0
+; CHECK-NEXT:    br label %[[LOOP:.*]]
+; CHECK:       [[LOOP]]:
+; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <16 x ptr> [ [[MM_VECTORGEP11:%.*]], %[[F0:.*]] ], [ [[MM_VECTORGEP22:%.*]], %[[F1:.*]] ], [ zeroinitializer, %[[ENTRY]] ]
+; CHECK-NEXT:    br i1 [[TOBOOL]], label %[[F1]], label %[[F0]]
+; CHECK:       [[F0]]:
+; CHECK-NEXT:    [[MM_VECTORGEP11_SPLIT:%.*]] = getelementptr inbounds [[FOO]], <16 x ptr> [[LANE_15]], <16 x i64> [[VARIDX]]
+; CHECK-NEXT:    [[MM_VECTORGEP11]] = getelementptr inbounds i8, <16 x ptr> [[MM_VECTORGEP11_SPLIT]], i64 2
+; CHECK-NEXT:    br i1 [[END]], label %[[LOOP]], label %[[MERGE:.*]]
+; CHECK:       [[F1]]:
+; CHECK-NEXT:    [[MM_VECTORGEP22_SPLIT:%.*]] = getelementptr inbounds [[FOO]], <16 x ptr> [[LANE_15]], <16 x i64> [[VARIDX]]
+; CHECK-NEXT:    [[MM_VECTORGEP22]] = getelementptr inbounds i8, <16 x ptr> [[MM_VECTORGEP22_SPLIT]], i64 4
+; CHECK-NEXT:    br i1 [[END]], label %[[LOOP]], label %[[MERGE]]
+; CHECK:       [[MERGE]]:
+; CHECK-NEXT:    ret <16 x ptr> [[VEC_PHI]]
+;
+entry:
+  %lane.0 = alloca %foo, align 16
+  %lane.15 = insertelement <16 x ptr> poison, ptr %lane.0, i64 0
+  br label %loop
+
+loop:
+  %vec.phi = phi <16 x ptr> [ %mm_vectorGEP1, %f0], [ %mm_vectorGEP2, %f1 ], [ zeroinitializer, %entry]
+  %mm_vectorGEP1 = getelementptr inbounds %foo, <16 x ptr> %lane.15, <16 x i64> %varidx, <16 x i32> splat (i32 1)
+  %mm_vectorGEP2 = getelementptr inbounds %foo, <16 x ptr> %lane.15, <16 x i64> %varidx, <16 x i32> splat (i32 2)
+  br i1 %tobool, label %f1, label %f0
+
+f0:
+  br i1 %end, label %loop, label %merge
+
+f1:
+  br i1 %end, label %loop, label %merge
+
+merge:
+  ret <16 x ptr> %vec.phi
+}
+
+define ptr @gep_constant_offset(i1 %cond, ptr %ptr) {
+; CHECK-LABEL: define ptr @gep_constant_offset(
+; CHECK-SAME: i1 [[COND:%.*]], ptr [[PTR:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    br i1 [[COND]], label %[[F1:.*]], label %[[F0:.*]]
+; CHECK:       [[F0]]:
+; CHECK-NEXT:    [[GEP0:%.*]] = getelementptr inbounds nuw i8, ptr [[PTR]], i64 16
+; CHECK-NEXT:    br label %[[MERGE:.*]]
+; CHECK:       [[F1]]:
+; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr inbounds nuw i8, ptr [[PTR]], i64 32
+; CHECK-NEXT:    br label %[[MERGE]]
+; CHECK:       [[MERGE]]:
+; CHECK-NEXT:    [[PHI:%.*]] = phi ptr [ [[GEP0]], %[[F0]] ], [ [[GEP1]], %[[F1]] ]
+; CHECK-NEXT:    ret ptr [[PHI]]
+;
+entry:
+  %gep0 = getelementptr inbounds i8, ptr %ptr, i64 16
+  %gep1 = getelementptr inbounds i8, ptr %ptr, i64 32
+  br i1 %cond, label %f1, label %f0
+
+f0:
+  br label %merge
+
+f1:
+  br label %merge
+
+merge:
+  %phi = phi ptr [ %gep0, %f0], [ %gep1, %f1 ]
+  ret ptr %phi
+}
+
+define ptr @gep_variable_offset(i1 %cond, ptr %ptr, i64 %off0, i64 %off1) {
+; CHECK-LABEL: define ptr @gep_variable_offset(
+; CHECK-SAME: i1 [[COND:%.*]], ptr [[PTR:%.*]], i64 [[OFF0:%.*]], i64 [[OFF1:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    br i1 [[COND]], label %[[F1:.*]], label %[[F0:.*]]
+; CHECK:       [[F0]]:
+; CHECK-NEXT:    br label %[[MERGE:.*]]
+; CHECK:       [[F1]]:
+; CHECK-NEXT:    br label %[[MERGE]]
+; CHECK:       [[MERGE]]:
+; CHECK-NEXT:    [[OFF0_PN:%.*]] = phi i64 [ [[OFF0]], %[[F0]] ], [ [[OFF1]], %[[F1]] ]
+; CHECK-NEXT:    [[PHI:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i64 [[OFF0_PN]]
+; CHECK-NEXT:    ret ptr [[PHI]]
+;
+entry:
+  %gep0 = getelementptr inbounds i8, ptr %ptr, i64 %off0
+  %gep1 = getelementptr inbounds i8, ptr %ptr, i64 %off1
+  br i1 %cond, label %f1, label %f0
+
+f0:
+  br label %merge
+
+f1:
+  br label %merge
+
+merge:
+  %phi = phi ptr [ %gep0, %f0], [ %gep1, %f1 ]
+  ret ptr %phi
+}
+
+define ptr @gep_mixed_offset_1(i1 %cond, ptr %ptr, i64 %off1) {
+; CHECK-LABEL: define ptr @gep_mixed_offset_1(
+; CHECK-SAME: i1 [[COND:%.*]], ptr [[PTR:%.*]], i64 [[OFF1:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    br i1 [[COND]], label %[[F1:.*]], label %[[F0:.*]]
+; CHECK:       [[F0]]:
+; CHECK-NEXT:    [[GEP0:%.*]] = getelementptr inbounds nuw i8, ptr [[PTR]], i64 16
+; CHECK-NEXT:    br label %[[MERGE:.*]]
+; CHECK:       [[F1]]:
+; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i64 [[OFF1]]
+; CHECK-NEXT:    br label %[[MERGE]]
+; CHECK:       [[MERGE]]:
+; CHECK-NEXT:    [[PHI:%.*]] = phi ptr [ [[GEP0]], %[[F0]] ], [ [[GEP1]], %[[F1]] ]
+; CHECK-NEXT:    ret ptr [[PHI]]
+;
+entry:
+  %gep0 = getelementptr inbounds i8, ptr %ptr, i64 16
+  %gep1 = getelementptr inbounds i8, ptr %ptr, i64 %off1
+  br i1 %cond, label %f1, label %f0
+
+f0:
+  br label %merge
+
+f1:
+  br label %merge
+
+merge:
+  %phi = phi ptr [ %gep0, %f0], [ %gep1, %f1 ]
+  ret ptr %phi
+}
+
+define ptr @gep_mixed_offset_2(i1 %cond, ptr %ptr, i64 %off0) {
+; CHECK-LABEL: define ptr @gep_mixed_offset_2(
+; CHECK-SAME: i1 [[COND:%.*]], ptr [[PTR:%.*]], i64 [[OFF0:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    br i1 [[COND]], label %[[F1:.*]], label %[[F0:.*]]
+; CHECK:       [[F0]]:
+; CHECK-NEXT:    [[GEP0:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i64 [[OFF0]]
+; CHECK-NEXT:    br label %[[MERGE:.*]]
+; CHECK:       [[F1]]:
+; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr inbounds nuw i8, ptr [[PTR]], i64 32
+; CHECK-NEXT:    br label %[[MERGE]]
+; CHECK:       [[MERGE]]:
+; CHECK-NEXT:    [[PHI:%.*]] = phi ptr [ [[GEP0]], %[[F0]] ], [ [[GEP1]], %[[F1]] ]
+; CHECK-NEXT:    ret ptr [[PHI]]
+;
+entry:
+  %gep0 = getelementptr inbounds i8, ptr %ptr, i64 %off0
+  %gep1 = getelementptr inbounds i8, ptr %ptr, i64 32
+  br i1 %cond, label %f1, label %f0
+
+f0:
+  br label %merge
+
+f1:
+  br label %merge
+
+merge:
+  %phi = phi ptr [ %gep0, %f0], [ %gep1, %f1 ]
+  ret ptr %phi
+}
+
+define ptr @struct_constant_offset(i1 %cond, %foo %ptr) {
+; CHECK-LABEL: define ptr @struct_constant_offset(
+; CHECK-SAME: i1 [[COND:%.*]], [[FOO:%.*]] [[PTR:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[LANE_0:%.*]] = alloca [[FOO]], align 16
+; CHECK-NEXT:    br i1 [[COND]], label %[[F1:.*]], label %[[F0:.*]]
+; CHECK:       [[F0]]:
+; CHECK-NEXT:    [[GEP0:%.*]] = getelementptr inbounds nuw i8, ptr [[LANE_0]], i64 6
+; CHECK-NEXT:    br label %[[MERGE:.*]]
+; CHECK:       [[F1]]:
+; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr inbounds nuw i8, ptr [[LANE_0]], i64 12
+; CHECK-NEXT:    br label %[[MERGE]]
+; CHECK:       [[MERGE]]:
+; CHECK-NEXT:    [[PHI:%.*]] = phi ptr [ [[GEP0]], %[[F0]] ], [ [[GEP1]], %[[F1]] ]
+; CHECK-NEXT:    ret ptr [[PHI]]
+;
+entry:
+  %lane.0 = alloca %foo, align 16
+  %gep0 = getelementptr inbounds %foo, ptr %lane.0, i64 1
+  %gep1 = getelementptr inbounds %foo, ptr %lane.0, i64 2
+  br i1 %cond, label %f1, label %f0
+
+f0:
+  br label %merge
+
+f1:
+  br label %merge
+
+merge:
+  %phi = phi ptr [ %gep0, %f0], [ %gep1, %f1 ]
+  ret ptr %phi
+}

>From e2ed8a7e9b9c79e20dce35231d98907bf93d75ee Mon Sep 17 00:00:00 2001
From: Jessica Del <Jessica.Del at amd.com>
Date: Wed, 17 Dec 2025 10:12:42 +0100
Subject: [PATCH 03/10] [InstCombine] Allow folding if only one operand is
 variable

Allow the transform if a phi is needed for the same operand.
---
 llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index ea386df78bcba..62d8e4319bee4 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -589,7 +589,7 @@ Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) {
       // also requires a PHI, we'd be introducing more PHIs than we're
       // eliminating, which increases register pressure on entry to the PHI's
       // block.
-      if (NeededPhi)
+      if (NeededPhi && FixedOperands[Op] != nullptr)
         return nullptr;
 
       FixedOperands[Op] = nullptr; // Needs a PHI.

>From 5a595be2393cc3a12ecf5264f3556dce0ed1ba5d Mon Sep 17 00:00:00 2001
From: Jessica Del <Jessica.Del at amd.com>
Date: Wed, 7 Jan 2026 17:55:50 +0100
Subject: [PATCH 04/10] [InstCombinePHI] Prevent GEP arg folding for mixed
 offsets

Prevent folding of gep args into a phi if some of the geps have a
constant offset, while others have a variable offset.
---
 llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index 62d8e4319bee4..2d30c1953259f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -581,6 +581,16 @@ Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) {
           isa<Constant>(GEP->getOperand(Op)))
         return nullptr;
 
+      // Don't merge if there is a mixture of constant and variable indeces for
+      // the same operand. If all the indeces are constant, the chance is higher
+      // that we can create a lookup table. Otherwise, we could pessimize the
+      // path.
+      if ((isa<Constant>(FirstInst->getOperand(Op)) &&
+           !isa<Constant>(GEP->getOperand(Op))) ||
+          (!isa<Constant>(FirstInst->getOperand(Op)) &&
+           isa<Constant>(GEP->getOperand(Op))))
+        return nullptr;
+
       if (FirstInst->getOperand(Op)->getType() !=
           GEP->getOperand(Op)->getType())
         return nullptr;

>From db515faa53eb54d3bb1ce72db0ca5cbe8f942b88 Mon Sep 17 00:00:00 2001
From: Jessica Del <Jessica.Del at amd.com>
Date: Wed, 7 Jan 2026 18:41:39 +0100
Subject: [PATCH 05/10] [InstCombinePHI] Allow gep arg folding for constant
 non-struct indices

Allow folding of a gep with constant indices, as long as it does not
index a struct.

Change the check from one based on constant indices to one based on the
indexed type.
---
 .../Transforms/InstCombine/InstCombinePHI.cpp    | 16 +++++++++-------
 .../InstCombine/InstructionCombining.cpp         |  2 +-
 .../InstCombine/fold-phi-arg-gep-to-phi.ll       |  5 ++---
 llvm/test/Transforms/InstCombine/opaque-ptr.ll   |  5 ++---
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index 2d30c1953259f..49d20e23740d0 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -554,6 +554,7 @@ Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) {
   // Scan to see if all operands are the same opcode, and all have one user.
   for (Value *V : drop_begin(PN.incoming_values())) {
     GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(V);
+    SmallVector<Value *, 16> GEPIndices;
     if (!GEP || !GEP->hasOneUser() ||
         GEP->getSourceElementType() != FirstInst->getSourceElementType() ||
         GEP->getNumOperands() != FirstInst->getNumOperands())
@@ -572,13 +573,14 @@ Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) {
       if (FirstInst->getOperand(Op) == GEP->getOperand(Op))
         continue;
 
-      // Don't merge two GEPs when two operands differ (introducing phi nodes)
-      // if one of the PHIs has a constant for the index.  The index may be
-      // substantially cheaper to compute for the constants, so making it a
-      // variable index could pessimize the path.  This also handles the case
-      // for struct indices, which must always be constant.
-      if (isa<Constant>(FirstInst->getOperand(Op)) ||
-          isa<Constant>(GEP->getOperand(Op)))
+      // Don't merge two GEPs if the GEP indices a struct, because struct
+      // indices must be constant.
+
+      if (Op > 0) // skip base pointer for indeces
+        GEPIndices.push_back(GEP->getOperand(Op));
+
+      if (GEP->getIndexedType(GEP->getSourceElementType(), GEPIndices)
+              ->isStructTy())
         return nullptr;
 
       // Don't merge if there is a mixture of constant and variable indeces for
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 6798493de1aa3..812d415735f7a 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3194,7 +3194,7 @@ static bool shouldCanonicalizeGEPToPtrAdd(GetElementPtrInst &GEP) {
 
   // gep (gep %p, C1), %x, C2 is expanded so the two constants can
   // possibly be merged together.
-  auto PtrOpGep = dyn_cast<GEPOperator>(PtrOp);
+  auto *PtrOpGep = dyn_cast<GEPOperator>(PtrOp);
   return PtrOpGep && PtrOpGep->hasAllConstantIndices() &&
          any_of(GEP.indices(), [](Value *V) {
            const APInt *C;
diff --git a/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll b/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll
index 41f0bbac2e30b..a1b989c3ec476 100644
--- a/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll
+++ b/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll
@@ -51,13 +51,12 @@ define ptr @gep_constant_offset(i1 %cond, ptr %ptr) {
 ; CHECK-NEXT:  [[ENTRY:.*:]]
 ; CHECK-NEXT:    br i1 [[COND]], label %[[F1:.*]], label %[[F0:.*]]
 ; CHECK:       [[F0]]:
-; CHECK-NEXT:    [[GEP0:%.*]] = getelementptr inbounds nuw i8, ptr [[PTR]], i64 16
 ; CHECK-NEXT:    br label %[[MERGE:.*]]
 ; CHECK:       [[F1]]:
-; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr inbounds nuw i8, ptr [[PTR]], i64 32
 ; CHECK-NEXT:    br label %[[MERGE]]
 ; CHECK:       [[MERGE]]:
-; CHECK-NEXT:    [[PHI:%.*]] = phi ptr [ [[GEP0]], %[[F0]] ], [ [[GEP1]], %[[F1]] ]
+; CHECK-NEXT:    [[DOTPN:%.*]] = phi i64 [ 16, %[[F0]] ], [ 32, %[[F1]] ]
+; CHECK-NEXT:    [[PHI:%.*]] = getelementptr inbounds nuw i8, ptr [[PTR]], i64 [[DOTPN]]
 ; CHECK-NEXT:    ret ptr [[PHI]]
 ;
 entry:
diff --git a/llvm/test/Transforms/InstCombine/opaque-ptr.ll b/llvm/test/Transforms/InstCombine/opaque-ptr.ll
index 9f3cd87924774..9912603557638 100644
--- a/llvm/test/Transforms/InstCombine/opaque-ptr.ll
+++ b/llvm/test/Transforms/InstCombine/opaque-ptr.ll
@@ -634,13 +634,12 @@ define ptr @phi_of_gep_different_type(i1 %c, ptr %p) {
 ; CHECK-LABEL: @phi_of_gep_different_type(
 ; CHECK-NEXT:    br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
 ; CHECK:       if:
-; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 4
 ; CHECK-NEXT:    br label [[JOIN:%.*]]
 ; CHECK:       else:
-; CHECK-NEXT:    [[GEP2:%.*]] = getelementptr i8, ptr [[P]], i64 8
 ; CHECK-NEXT:    br label [[JOIN]]
 ; CHECK:       join:
-; CHECK-NEXT:    [[PHI:%.*]] = phi ptr [ [[GEP1]], [[IF]] ], [ [[GEP2]], [[ELSE]] ]
+; CHECK-NEXT:    [[DOTPN:%.*]] = phi i64 [ 4, [[IF]] ], [ 8, [[ELSE]] ]
+; CHECK-NEXT:    [[PHI:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 [[DOTPN]]
 ; CHECK-NEXT:    ret ptr [[PHI]]
 ;
   br i1 %c, label %if, label %else

>From dc460f64c8dbd588d629bb448c10941422a7f0dd Mon Sep 17 00:00:00 2001
From: Jessica Del <Jessica.Del at amd.com>
Date: Tue, 13 Jan 2026 14:19:32 +0100
Subject: [PATCH 06/10] fixup! [InstCombinePHI] Prevent GEP arg folding for
 mixed offsets

---
 llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index 49d20e23740d0..783fa855a9a83 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -587,10 +587,8 @@ Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) {
       // the same operand. If all the indeces are constant, the chance is higher
       // that we can create a lookup table. Otherwise, we could pessimize the
       // path.
-      if ((isa<Constant>(FirstInst->getOperand(Op)) &&
-           !isa<Constant>(GEP->getOperand(Op))) ||
-          (!isa<Constant>(FirstInst->getOperand(Op)) &&
-           isa<Constant>(GEP->getOperand(Op))))
+      if (isa<Constant>(FirstInst->getOperand(Op)) !=
+          isa<Constant>(GEP->getOperand(Op)))
         return nullptr;
 
       if (FirstInst->getOperand(Op)->getType() !=

>From 04e7f5c7f4772f38de0943885a7b6999a803837a Mon Sep 17 00:00:00 2001
From: Jessica Del <Jessica.Del at amd.com>
Date: Tue, 13 Jan 2026 14:27:20 +0100
Subject: [PATCH 07/10] fixup! [InstCombinePHI] Prevent GEP arg folding for
 mixed offsets

---
 llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index 783fa855a9a83..f8d5e92712ec7 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -583,8 +583,8 @@ Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) {
               ->isStructTy())
         return nullptr;
 
-      // Don't merge if there is a mixture of constant and variable indeces for
-      // the same operand. If all the indeces are constant, the chance is higher
+      // Don't merge if there is a mixture of constant and variable indices for
+      // the same operand. If all the indices are constant, the chance is higher
       // that we can create a lookup table. Otherwise, we could pessimize the
       // path.
       if (isa<Constant>(FirstInst->getOperand(Op)) !=

>From 8a41d40df8e2bb4eec907e603e574c440d089975 Mon Sep 17 00:00:00 2001
From: Jessica Del <Jessica.Del at amd.com>
Date: Tue, 13 Jan 2026 15:08:56 +0100
Subject: [PATCH 08/10] fixup! [InstCombinePHI] Allow gep arg folding for
 constant non-struct indices

---
 .../lib/Transforms/InstCombine/InstCombinePHI.cpp | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index f8d5e92712ec7..7269c0a267d7d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -16,6 +16,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/InstructionSimplify.h"
 #include "llvm/Analysis/ValueTracking.h"
+#include "llvm/IR/GetElementPtrTypeIterator.h"
 #include "llvm/IR/PatternMatch.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Transforms/InstCombine/InstCombiner.h"
@@ -554,7 +555,6 @@ Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) {
   // Scan to see if all operands are the same opcode, and all have one user.
   for (Value *V : drop_begin(PN.incoming_values())) {
     GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(V);
-    SmallVector<Value *, 16> GEPIndices;
     if (!GEP || !GEP->hasOneUser() ||
         GEP->getSourceElementType() != FirstInst->getSourceElementType() ||
         GEP->getNumOperands() != FirstInst->getNumOperands())
@@ -569,19 +569,18 @@ Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) {
       AllBasePointersAreAllocas = false;
 
     // Compare the operand lists.
+    gep_type_iterator TypeIter = gep_type_begin(GEP);
     for (unsigned Op = 0, E = FirstInst->getNumOperands(); Op != E; ++Op) {
       if (FirstInst->getOperand(Op) == GEP->getOperand(Op))
         continue;
 
       // Don't merge two GEPs if the GEP indices a struct, because struct
       // indices must be constant.
-
-      if (Op > 0) // skip base pointer for indeces
-        GEPIndices.push_back(GEP->getOperand(Op));
-
-      if (GEP->getIndexedType(GEP->getSourceElementType(), GEPIndices)
-              ->isStructTy())
-        return nullptr;
+      if (Op > 0) { // skip pointer operand
+        if (TypeIter.isStruct())
+          return nullptr;
+        ++TypeIter;
+      }
 
       // Don't merge if there is a mixture of constant and variable indices for
       // the same operand. If all the indices are constant, the chance is higher

>From 9d4d3dcea57e51924904c26673d402a59e69a57a Mon Sep 17 00:00:00 2001
From: Jessica Del <Jessica.Del at amd.com>
Date: Tue, 13 Jan 2026 15:37:43 +0100
Subject: [PATCH 09/10] fixup! [InstCombine] Add tests for gep arg folding

---
 .../InstCombine/fold-phi-arg-gep-to-phi.ll    | 73 +++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll b/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll
index a1b989c3ec476..d0e06693fbe9b 100644
--- a/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll
+++ b/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll
@@ -199,3 +199,76 @@ merge:
   %phi = phi ptr [ %gep0, %f0], [ %gep1, %f1 ]
   ret ptr %phi
 }
+
+define ptr @gep_different_offset_types_canonicalized(i1 %cond, i1 %end, ptr %ptr, i64 %off0, i32 %off1) {
+; CHECK-LABEL: define ptr @gep_different_offset_types_canonicalized(
+; CHECK-SAME: i1 [[COND:%.*]], i1 [[END:%.*]], ptr [[PTR:%.*]], i64 [[OFF0:%.*]], i32 [[OFF1:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*]]:
+; CHECK-NEXT:    [[TMP0:%.*]] = sext i32 [[OFF1]] to i64
+; CHECK-NEXT:    br label %[[LOOP:.*]]
+; CHECK:       [[LOOP]]:
+; CHECK-NEXT:    [[OFF0_PN:%.*]] = phi i64 [ [[OFF0]], %[[F0:.*]] ], [ [[TMP0]], %[[F1:.*]] ], [ [[OFF0]], %[[ENTRY]] ]
+; CHECK-NEXT:    br i1 [[COND]], label %[[F1]], label %[[F0]]
+; CHECK:       [[F0]]:
+; CHECK-NEXT:    br i1 [[END]], label %[[MERGE:.*]], label %[[LOOP]]
+; CHECK:       [[F1]]:
+; CHECK-NEXT:    br i1 [[END]], label %[[MERGE]], label %[[LOOP]]
+; CHECK:       [[MERGE]]:
+; CHECK-NEXT:    [[PHI:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i64 [[OFF0_PN]]
+; CHECK-NEXT:    ret ptr [[PHI]]
+;
+entry:
+  %gep0 = getelementptr inbounds <3 x i8>, ptr %ptr, i64 0, i64 %off0
+  %gep1 = getelementptr inbounds <3 x i8>, ptr %ptr, i64 0, i32 %off1
+  br label %loop
+
+loop:
+  %phi = phi ptr [ %gep0, %f0 ], [ %gep1, %f1 ], [ %gep0, %entry ]
+  br i1 %cond, label %f1, label %f0
+
+f0:
+  br i1 %end, label %merge, label %loop
+
+f1:
+  br i1 %end, label %merge, label %loop
+
+merge:
+  ret ptr %phi
+}
+
+define ptr @gep_different_offset_types_negative(i1 %cond, i1 %end, ptr %ptr, i64 %off0, i32 %off1) {
+; CHECK-LABEL: define ptr @gep_different_offset_types_negative(
+; CHECK-SAME: i1 [[COND:%.*]], i1 [[END:%.*]], ptr [[PTR:%.*]], i64 [[OFF0:%.*]], i32 [[OFF1:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*]]:
+; CHECK-NEXT:    br label %[[LOOP:.*]]
+; CHECK:       [[LOOP]]:
+; CHECK-NEXT:    [[PHI:%.*]] = phi ptr [ [[GEP0:%.*]], %[[F0:.*]] ], [ [[GEP1:%.*]], %[[F1:.*]] ], [ null, %[[ENTRY]] ]
+; CHECK-NEXT:    br i1 [[COND]], label %[[F1]], label %[[F0]]
+; CHECK:       [[F0]]:
+; CHECK-NEXT:    [[GEP0]] = getelementptr inbounds i8, ptr [[PTR]], i64 [[OFF0]]
+; CHECK-NEXT:    br i1 [[END]], label %[[MERGE:.*]], label %[[LOOP]]
+; CHECK:       [[F1]]:
+; CHECK-NEXT:    [[TMP0:%.*]] = sext i32 [[OFF1]] to i64
+; CHECK-NEXT:    [[GEP1]] = getelementptr inbounds i8, ptr [[PTR]], i64 [[TMP0]]
+; CHECK-NEXT:    br i1 [[END]], label %[[MERGE]], label %[[LOOP]]
+; CHECK:       [[MERGE]]:
+; CHECK-NEXT:    ret ptr [[PHI]]
+;
+entry:
+  br label %loop
+
+loop:
+  %phi = phi ptr [ %gep0, %f0 ], [ %gep1, %f1 ], [ zeroinitializer, %entry ]
+  %gep0 = getelementptr inbounds <3 x i8>, ptr %ptr, i64 0, i64 %off0
+  %gep1 = getelementptr inbounds <3 x i8>, ptr %ptr, i64 0, i32 %off1
+  br i1 %cond, label %f1, label %f0
+
+f0:
+  br i1 %end, label %merge, label %loop
+
+f1:
+  br i1 %end, label %merge, label %loop
+
+merge:
+  ret ptr %phi
+}

>From 4ba9296790d4147a3b3bd46cc6bed2f5cfd55da1 Mon Sep 17 00:00:00 2001
From: Jessica Del <Jessica.Del at amd.com>
Date: Mon, 30 Mar 2026 11:38:04 +0200
Subject: [PATCH 10/10] fixup! [InstCombinePHI] Allow gep arg folding for
 constant non-struct indices

---
 .../lib/Transforms/InstCombine/InstCombinePHI.cpp | 15 ++++++---------
 .../InstCombine/fold-phi-arg-gep-to-phi.ll        |  4 ++--
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index 7269c0a267d7d..c3a50416e0d92 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -568,20 +568,17 @@ Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) {
          !GEP->hasAllConstantIndices()))
       AllBasePointersAreAllocas = false;
 
-    // Compare the operand lists.
+    // Don't merge two GEPs if the GEP indices a struct, because struct
+    // indices must be constant.
     gep_type_iterator TypeIter = gep_type_begin(GEP);
+    if (GEP->getNumIndices() == 1 && TypeIter.isStruct())
+      return nullptr;
+
+    // Compare the operand lists.
     for (unsigned Op = 0, E = FirstInst->getNumOperands(); Op != E; ++Op) {
       if (FirstInst->getOperand(Op) == GEP->getOperand(Op))
         continue;
 
-      // Don't merge two GEPs if the GEP indices a struct, because struct
-      // indices must be constant.
-      if (Op > 0) { // skip pointer operand
-        if (TypeIter.isStruct())
-          return nullptr;
-        ++TypeIter;
-      }
-
       // Don't merge if there is a mixture of constant and variable indices for
       // the same operand. If all the indices are constant, the chance is higher
       // that we can create a lookup table. Otherwise, we could pessimize the
diff --git a/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll b/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll
index d0e06693fbe9b..afa6483358059 100644
--- a/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll
+++ b/llvm/test/Transforms/InstCombine/fold-phi-arg-gep-to-phi.ll
@@ -14,11 +14,11 @@ define <16 x ptr> @test(i1 %tobool, i1 %end, <16 x i64> %varidx) {
 ; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <16 x ptr> [ [[MM_VECTORGEP11:%.*]], %[[F0:.*]] ], [ [[MM_VECTORGEP22:%.*]], %[[F1:.*]] ], [ zeroinitializer, %[[ENTRY]] ]
 ; CHECK-NEXT:    br i1 [[TOBOOL]], label %[[F1]], label %[[F0]]
 ; CHECK:       [[F0]]:
-; CHECK-NEXT:    [[MM_VECTORGEP11_SPLIT:%.*]] = getelementptr inbounds [[FOO]], <16 x ptr> [[LANE_15]], <16 x i64> [[VARIDX]]
+; CHECK-NEXT:    [[MM_VECTORGEP11_SPLIT:%.*]] = getelementptr inbounds [6 x i8], <16 x ptr> [[LANE_15]], <16 x i64> [[VARIDX]]
 ; CHECK-NEXT:    [[MM_VECTORGEP11]] = getelementptr inbounds i8, <16 x ptr> [[MM_VECTORGEP11_SPLIT]], i64 2
 ; CHECK-NEXT:    br i1 [[END]], label %[[LOOP]], label %[[MERGE:.*]]
 ; CHECK:       [[F1]]:
-; CHECK-NEXT:    [[MM_VECTORGEP22_SPLIT:%.*]] = getelementptr inbounds [[FOO]], <16 x ptr> [[LANE_15]], <16 x i64> [[VARIDX]]
+; CHECK-NEXT:    [[MM_VECTORGEP22_SPLIT:%.*]] = getelementptr inbounds [6 x i8], <16 x ptr> [[LANE_15]], <16 x i64> [[VARIDX]]
 ; CHECK-NEXT:    [[MM_VECTORGEP22]] = getelementptr inbounds i8, <16 x ptr> [[MM_VECTORGEP22_SPLIT]], i64 4
 ; CHECK-NEXT:    br i1 [[END]], label %[[LOOP]], label %[[MERGE]]
 ; CHECK:       [[MERGE]]:



More information about the llvm-commits mailing list