llvm/llvm/test/Transforms/SLPVectorizer/X86/jumbled-load-used-in-phi.ll

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -S -mtriple=x86_64-unknown -mattr=+avx -passes=slp-vectorizer | FileCheck %s

;void phiUsingLoads(int *restrict A, int *restrict B) {
;  int tmp0, tmp1, tmp2, tmp3;
;  for (int i = 0; i < 100; i++) {
;    if (A[0] == 0) {
;      tmp0 = A[i + 0];
;      tmp1 = A[i + 1];
;      tmp2 = A[i + 2];
;      tmp3 = A[i + 3];
;    } else if (A[25] == 0) {
;      tmp0 = A[i + 0];
;      tmp1 = A[i + 1];
;      tmp2 = A[i + 2];
;      tmp3 = A[i + 3];
;    } else if (A[50] == 0) {
;      tmp0 = A[i + 0];
;      tmp1 = A[i + 1];
;      tmp2 = A[i + 2];
;      tmp3 = A[i + 3];
;    } else if (A[75] == 0) {
;      tmp0 = A[i + 0];
;      tmp1 = A[i + 1];
;      tmp2 = A[i + 3];
;      tmp3 = A[i + 2];
;    }
;  }
;  B[0] = tmp0;
;  B[1] = tmp1;
;  B[2] = tmp2;
;  B[3] = tmp3;
;}


; Function Attrs: norecurse nounwind uwtable
define void @phiUsingLoads(ptr noalias nocapture readonly %A, ptr noalias nocapture %B) local_unnamed_addr #0 {
; CHECK-LABEL: @phiUsingLoads(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[A:%.*]], align 4
; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i32 [[TMP0]], 0
; CHECK-NEXT:    [[ARRAYIDX12:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 25
; CHECK-NEXT:    [[ARRAYIDX28:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 50
; CHECK-NEXT:    [[ARRAYIDX44:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 75
; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
; CHECK:       for.cond.cleanup:
; CHECK-NEXT:    store <4 x i32> [[TMP14:%.*]], ptr [[B:%.*]], align 4
; CHECK-NEXT:    ret void
; CHECK:       for.body:
; CHECK-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_INC:%.*]] ]
; CHECK-NEXT:    [[TMP2:%.*]] = phi <4 x i32> [ undef, [[ENTRY]] ], [ [[TMP14]], [[FOR_INC]] ]
; CHECK-NEXT:    br i1 [[CMP1]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
; CHECK:       if.then:
; CHECK-NEXT:    [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[INDVARS_IV]]
; CHECK-NEXT:    [[TMP4:%.*]] = load <4 x i32>, ptr [[ARRAYIDX2]], align 4
; CHECK-NEXT:    br label [[FOR_INC]]
; CHECK:       if.else:
; CHECK-NEXT:    [[TMP5:%.*]] = load i32, ptr [[ARRAYIDX12]], align 4
; CHECK-NEXT:    [[CMP13:%.*]] = icmp eq i32 [[TMP5]], 0
; CHECK-NEXT:    br i1 [[CMP13]], label [[IF_THEN14:%.*]], label [[IF_ELSE27:%.*]]
; CHECK:       if.then14:
; CHECK-NEXT:    [[ARRAYIDX17:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[INDVARS_IV]]
; CHECK-NEXT:    [[TMP7:%.*]] = load <4 x i32>, ptr [[ARRAYIDX17]], align 4
; CHECK-NEXT:    br label [[FOR_INC]]
; CHECK:       if.else27:
; CHECK-NEXT:    [[TMP8:%.*]] = load i32, ptr [[ARRAYIDX28]], align 4
; CHECK-NEXT:    [[CMP29:%.*]] = icmp eq i32 [[TMP8]], 0
; CHECK-NEXT:    br i1 [[CMP29]], label [[IF_THEN30:%.*]], label [[IF_ELSE43:%.*]]
; CHECK:       if.then30:
; CHECK-NEXT:    [[ARRAYIDX33:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[INDVARS_IV]]
; CHECK-NEXT:    [[TMP10:%.*]] = load <4 x i32>, ptr [[ARRAYIDX33]], align 4
; CHECK-NEXT:    br label [[FOR_INC]]
; CHECK:       if.else43:
; CHECK-NEXT:    [[TMP11:%.*]] = load i32, ptr [[ARRAYIDX44]], align 4
; CHECK-NEXT:    [[CMP45:%.*]] = icmp eq i32 [[TMP11]], 0
; CHECK-NEXT:    br i1 [[CMP45]], label [[IF_THEN46:%.*]], label [[FOR_INC]]
; CHECK:       if.then46:
; CHECK-NEXT:    [[ARRAYIDX49:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[INDVARS_IV]]
; CHECK-NEXT:    [[TMP13:%.*]] = load <4 x i32>, ptr [[ARRAYIDX49]], align 4
; CHECK-NEXT:    [[SHUFFLE:%.*]] = shufflevector <4 x i32> [[TMP13]], <4 x i32> poison, <4 x i32> <i32 0, i32 1, i32 3, i32 2>
; CHECK-NEXT:    br label [[FOR_INC]]
; CHECK:       for.inc:
; CHECK-NEXT:    [[TMP14]] = phi <4 x i32> [ [[TMP4]], [[IF_THEN]] ], [ [[TMP7]], [[IF_THEN14]] ], [ [[TMP10]], [[IF_THEN30]] ], [ [[SHUFFLE]], [[IF_THEN46]] ], [ [[TMP2]], [[IF_ELSE43]] ]
; CHECK-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 100
; CHECK-NEXT:    br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]]
;
entry:
  %0 = load i32, ptr %A, align 4
  %cmp1 = icmp eq i32 %0, 0
  %arrayidx12 = getelementptr inbounds i32, ptr %A, i64 25
  %arrayidx28 = getelementptr inbounds i32, ptr %A, i64 50
  %arrayidx44 = getelementptr inbounds i32, ptr %A, i64 75
  br label %for.body

for.cond.cleanup:                                 ; preds = %for.inc
  store i32 %tmp0.1, ptr %B, align 4
  %arrayidx64 = getelementptr inbounds i32, ptr %B, i64 1
  store i32 %tmp1.1, ptr %arrayidx64, align 4
  %arrayidx65 = getelementptr inbounds i32, ptr %B, i64 2
  store i32 %tmp2.1, ptr %arrayidx65, align 4
  %arrayidx66 = getelementptr inbounds i32, ptr %B, i64 3
  store i32 %tmp3.1, ptr %arrayidx66, align 4
  ret void

for.body:                                         ; preds = %for.inc, %entry
  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.inc ]
  %tmp3.0111 = phi i32 [ undef, %entry ], [ %tmp3.1, %for.inc ]
  %tmp2.0110 = phi i32 [ undef, %entry ], [ %tmp2.1, %for.inc ]
  %tmp1.0109 = phi i32 [ undef, %entry ], [ %tmp1.1, %for.inc ]
  %tmp0.0108 = phi i32 [ undef, %entry ], [ %tmp0.1, %for.inc ]
  br i1 %cmp1, label %if.then, label %if.else

if.then:                                          ; preds = %for.body
  %arrayidx2 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv
  %1 = load i32, ptr %arrayidx2, align 4
  %2 = add nuw nsw i64 %indvars.iv, 1
  %arrayidx5 = getelementptr inbounds i32, ptr %A, i64 %2
  %3 = load i32, ptr %arrayidx5, align 4
  %4 = add nuw nsw i64 %indvars.iv, 2
  %arrayidx8 = getelementptr inbounds i32, ptr %A, i64 %4
  %5 = load i32, ptr %arrayidx8, align 4
  %6 = add nuw nsw i64 %indvars.iv, 3
  %arrayidx11 = getelementptr inbounds i32, ptr %A, i64 %6
  %7 = load i32, ptr %arrayidx11, align 4
  br label %for.inc

if.else:                                          ; preds = %for.body
  %8 = load i32, ptr %arrayidx12, align 4
  %cmp13 = icmp eq i32 %8, 0
  br i1 %cmp13, label %if.then14, label %if.else27

if.then14:                                        ; preds = %if.else
  %arrayidx17 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv
  %9 = load i32, ptr %arrayidx17, align 4
  %10 = add nuw nsw i64 %indvars.iv, 1
  %arrayidx20 = getelementptr inbounds i32, ptr %A, i64 %10
  %11 = load i32, ptr %arrayidx20, align 4
  %12 = add nuw nsw i64 %indvars.iv, 2
  %arrayidx23 = getelementptr inbounds i32, ptr %A, i64 %12
  %13 = load i32, ptr %arrayidx23, align 4
  %14 = add nuw nsw i64 %indvars.iv, 3
  %arrayidx26 = getelementptr inbounds i32, ptr %A, i64 %14
  %15 = load i32, ptr %arrayidx26, align 4
  br label %for.inc

if.else27:                                        ; preds = %if.else
  %16 = load i32, ptr %arrayidx28, align 4
  %cmp29 = icmp eq i32 %16, 0
  br i1 %cmp29, label %if.then30, label %if.else43

if.then30:                                        ; preds = %if.else27
  %arrayidx33 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv
  %17 = load i32, ptr %arrayidx33, align 4
  %18 = add nuw nsw i64 %indvars.iv, 1
  %arrayidx36 = getelementptr inbounds i32, ptr %A, i64 %18
  %19 = load i32, ptr %arrayidx36, align 4
  %20 = add nuw nsw i64 %indvars.iv, 2
  %arrayidx39 = getelementptr inbounds i32, ptr %A, i64 %20
  %21 = load i32, ptr %arrayidx39, align 4
  %22 = add nuw nsw i64 %indvars.iv, 3
  %arrayidx42 = getelementptr inbounds i32, ptr %A, i64 %22
  %23 = load i32, ptr %arrayidx42, align 4
  br label %for.inc

if.else43:                                        ; preds = %if.else27
  %24 = load i32, ptr %arrayidx44, align 4
  %cmp45 = icmp eq i32 %24, 0
  br i1 %cmp45, label %if.then46, label %for.inc

if.then46:                                        ; preds = %if.else43
  %arrayidx49 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv
  %25 = load i32, ptr %arrayidx49, align 4
  %26 = add nuw nsw i64 %indvars.iv, 1
  %arrayidx52 = getelementptr inbounds i32, ptr %A, i64 %26
  %27 = load i32, ptr %arrayidx52, align 4
  %28 = add nuw nsw i64 %indvars.iv, 3
  %arrayidx55 = getelementptr inbounds i32, ptr %A, i64 %28
  %29 = load i32, ptr %arrayidx55, align 4
  %30 = add nuw nsw i64 %indvars.iv, 2
  %arrayidx58 = getelementptr inbounds i32, ptr %A, i64 %30
  %31 = load i32, ptr %arrayidx58, align 4
  br label %for.inc

for.inc:                                          ; preds = %if.then, %if.then30, %if.else43, %if.then46, %if.then14
  %tmp0.1 = phi i32 [ %1, %if.then ], [ %9, %if.then14 ], [ %17, %if.then30 ], [ %25, %if.then46 ], [ %tmp0.0108, %if.else43 ]
  %tmp1.1 = phi i32 [ %3, %if.then ], [ %11, %if.then14 ], [ %19, %if.then30 ], [ %27, %if.then46 ], [ %tmp1.0109, %if.else43 ]
  %tmp2.1 = phi i32 [ %5, %if.then ], [ %13, %if.then14 ], [ %21, %if.then30 ], [ %29, %if.then46 ], [ %tmp2.0110, %if.else43 ]
  %tmp3.1 = phi i32 [ %7, %if.then ], [ %15, %if.then14 ], [ %23, %if.then30 ], [ %31, %if.then46 ], [ %tmp3.0111, %if.else43 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond = icmp eq i64 %indvars.iv.next, 100
  br i1 %exitcond, label %for.cond.cleanup, label %for.body
}