[llvm] SROA: Fix tree merge IRBuilder insert point (PR #189680)

Lewis Crawford via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 04:54:04 PDT 2026


================
@@ -296,6 +296,67 @@ FalseBranch:
   ret <8 x float> %result
 }
 
+define <6 x float> @merge_unordered_indices_same_bb(<2 x float> %a, <2 x float> %c) {
+; CHECK-LABEL: define <6 x float> @merge_unordered_indices_same_bb(
+; CHECK-SAME: <2 x float> [[A:%.*]], <2 x float> [[C:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALC:%.*]] = fadd <2 x float> [[A]], [[C]]
+; CHECK-NEXT:    [[TMP0:%.*]] = shufflevector <2 x float> [[A]], <2 x float> [[CALC]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <2 x float> [[C]], <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
+; CHECK-NEXT:    [[TMP2:%.*]] = shufflevector <4 x float> [[TMP0]], <4 x float> [[TMP1]], <6 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5>
+; CHECK-NEXT:    ret <6 x float> [[TMP2]]
+;
+entry:
+  %alloca = alloca [6 x float]
+
+  %ptr4 = getelementptr inbounds [6 x float], ptr %alloca, i32 0, i32 4
+  store <2 x float> %c, ptr %ptr4
+
+  %ptr0 = getelementptr inbounds [6 x float], ptr %alloca, i32 0, i32 0
+  store <2 x float> %a, ptr %ptr0
+
+  %calc = fadd <2 x float> %a, %c
+
+  %ptr2 = getelementptr inbounds [6 x float], ptr %alloca, i32 0, i32 2
+  store <2 x float> %calc, ptr %ptr2
+
+  %result = load <6 x float>, ptr %alloca
+  ret <6 x float> %result
+}
+
+define <6 x float> @merge_unordered_indices_different_bb(<2 x float> %a, <2 x float> %c) {
+; CHECK-LABEL: define <6 x float> @merge_unordered_indices_different_bb(
+; CHECK-SAME: <2 x float> [[A:%.*]], <2 x float> [[C:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[CALC:%.*]] = fadd <2 x float> [[A]], [[C]]
+; CHECK-NEXT:    [[TMP0:%.*]] = shufflevector <2 x float> [[A]], <2 x float> [[CALC]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <2 x float> [[C]], <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
+; CHECK-NEXT:    [[TMP2:%.*]] = shufflevector <4 x float> [[TMP0]], <4 x float> [[TMP1]], <6 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5>
+; CHECK-NEXT:    br label %[[LOAD_BB:.*]]
+; CHECK:       [[LOAD_BB]]:
+; CHECK-NEXT:    ret <6 x float> [[TMP2]]
+;
+entry:
+  %alloca = alloca [6 x float]
+
+  %ptr4 = getelementptr inbounds [6 x float], ptr %alloca, i32 0, i32 4
+  store <2 x float> %c, ptr %ptr4
+
+  %ptr0 = getelementptr inbounds [6 x float], ptr %alloca, i32 0, i32 0
+  store <2 x float> %a, ptr %ptr0
+
+  %calc = fadd <2 x float> %a, %c
+
+  %ptr2 = getelementptr inbounds [6 x float], ptr %alloca, i32 0, i32 2
+  store <2 x float> %calc, ptr %ptr2
+
+  br label %load_bb
+
+load_bb:
+  %result = load <6 x float>, ptr %alloca
+  ret <6 x float> %result
+}
+
 ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
 ; CHECK-MODIFY-CFG: {{.*}}
 ; CHECK-PRESERVE-CFG: {{.*}}
----------------
LewisCrawford wrote:

I've removed those unused CHECK prefixes now.

https://github.com/llvm/llvm-project/pull/189680


More information about the llvm-commits mailing list