llvm/llvm/test/Transforms/SLPVectorizer/AMDGPU/phi-result-use-order.ll

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=slp-vectorizer -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx906 < %s | FileCheck %s

define <4 x half> @phis(i1 %cmp1, <4 x half> %in1, <4 x half> %in2)  {
; CHECK-LABEL: @phis(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TMP0:%.*]] = shufflevector <4 x half> [[IN1:%.*]], <4 x half> poison, <2 x i32> <i32 0, i32 1>
; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <4 x half> [[IN1]], <4 x half> poison, <2 x i32> <i32 2, i32 3>
; CHECK-NEXT:    br i1 [[CMP1:%.*]], label [[BB1:%.*]], label [[BB0:%.*]]
; CHECK:       bb0:
; CHECK-NEXT:    [[TMP2:%.*]] = shufflevector <4 x half> [[IN2:%.*]], <4 x half> poison, <2 x i32> <i32 0, i32 1>
; CHECK-NEXT:    [[TMP3:%.*]] = shufflevector <4 x half> [[IN2]], <4 x half> poison, <2 x i32> <i32 2, i32 3>
; CHECK-NEXT:    br label [[BB1]]
; CHECK:       bb1:
; CHECK-NEXT:    [[TMP4:%.*]] = phi <2 x half> [ [[TMP0]], [[ENTRY:%.*]] ], [ [[TMP2]], [[BB0]] ]
; CHECK-NEXT:    [[TMP5:%.*]] = phi <2 x half> [ [[TMP1]], [[ENTRY]] ], [ [[TMP3]], [[BB0]] ]
; CHECK-NEXT:    [[TMP6:%.*]] = shufflevector <2 x half> [[TMP4]], <2 x half> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
; CHECK-NEXT:    [[TMP7:%.*]] = shufflevector <2 x half> [[TMP5]], <2 x half> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
; CHECK-NEXT:    [[TMP8:%.*]] = shufflevector <2 x half> [[TMP4]], <2 x half> [[TMP5]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>
; CHECK-NEXT:    ret <4 x half> [[TMP8]]
;
entry:
  %a0 = extractelement <4 x half> %in1, i64 0
  %a1 = extractelement <4 x half> %in1, i64 1
  %a2 = extractelement <4 x half> %in1, i64 2
  %a3 = extractelement <4 x half> %in1, i64 3
  br i1 %cmp1, label %bb1, label %bb0

bb0:
  %b0 = extractelement <4 x half> %in2, i64 0
  %b1 = extractelement <4 x half> %in2, i64 1
  %b2 = extractelement <4 x half> %in2, i64 2
  %b3 = extractelement <4 x half> %in2, i64 3
  br label %bb1

bb1:
  %c0 = phi half [ %a0, %entry ], [ %b0, %bb0 ]
  %c1 = phi half [ %a1, %entry ], [ %b1, %bb0 ]
  %c2 = phi half [ %a2, %entry ], [ %b2, %bb0 ]
  %c3 = phi half [ %a3, %entry ], [ %b3, %bb0 ]

  %o0 = insertelement <4 x half> undef, half %c0, i64 0
  %o1 = insertelement <4 x half> %o0, half %c1, i64 1
  %o2 = insertelement <4 x half> %o1, half %c2, i64 2
  %o3 = insertelement <4 x half> %o2, half %c3, i64 3
  ret <4 x half> %o3
}

define <4 x half> @phis_reverse(i1 %cmp1, <4 x half> %in1, <4 x half> %in2)  {
; CHECK-LABEL: @phis_reverse(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TMP0:%.*]] = shufflevector <4 x half> [[IN1:%.*]], <4 x half> poison, <2 x i32> <i32 2, i32 3>
; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <4 x half> [[IN1]], <4 x half> poison, <2 x i32> <i32 0, i32 1>
; CHECK-NEXT:    br i1 [[CMP1:%.*]], label [[BB1:%.*]], label [[BB0:%.*]]
; CHECK:       bb0:
; CHECK-NEXT:    [[TMP2:%.*]] = shufflevector <4 x half> [[IN2:%.*]], <4 x half> poison, <2 x i32> <i32 2, i32 3>
; CHECK-NEXT:    [[TMP3:%.*]] = shufflevector <4 x half> [[IN2]], <4 x half> poison, <2 x i32> <i32 0, i32 1>
; CHECK-NEXT:    br label [[BB1]]
; CHECK:       bb1:
; CHECK-NEXT:    [[TMP4:%.*]] = phi <2 x half> [ [[TMP0]], [[ENTRY:%.*]] ], [ [[TMP2]], [[BB0]] ]
; CHECK-NEXT:    [[TMP5:%.*]] = phi <2 x half> [ [[TMP1]], [[ENTRY]] ], [ [[TMP3]], [[BB0]] ]
; CHECK-NEXT:    [[TMP6:%.*]] = shufflevector <2 x half> [[TMP5]], <2 x half> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
; CHECK-NEXT:    [[TMP7:%.*]] = shufflevector <2 x half> [[TMP4]], <2 x half> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
; CHECK-NEXT:    [[TMP8:%.*]] = shufflevector <4 x half> [[TMP6]], <4 x half> [[TMP7]], <4 x i32> <i32 0, i32 1, i32 4, i32 5>
; CHECK-NEXT:    ret <4 x half> [[TMP8]]
;
entry:
  %a0 = extractelement <4 x half> %in1, i64 0
  %a1 = extractelement <4 x half> %in1, i64 1
  %a2 = extractelement <4 x half> %in1, i64 2
  %a3 = extractelement <4 x half> %in1, i64 3
  br i1 %cmp1, label %bb1, label %bb0

bb0:
  %b0 = extractelement <4 x half> %in2, i64 0
  %b1 = extractelement <4 x half> %in2, i64 1
  %b2 = extractelement <4 x half> %in2, i64 2
  %b3 = extractelement <4 x half> %in2, i64 3
  br label %bb1

bb1:
  %c3 = phi half [ %a3, %entry ], [ %b3, %bb0 ]
  %c2 = phi half [ %a2, %entry ], [ %b2, %bb0 ]
  %c1 = phi half [ %a1, %entry ], [ %b1, %bb0 ]
  %c0 = phi half [ %a0, %entry ], [ %b0, %bb0 ]

  %o0 = insertelement <4 x half> undef, half %c0, i64 0
  %o1 = insertelement <4 x half> %o0, half %c1, i64 1
  %o2 = insertelement <4 x half> %o1, half %c2, i64 2
  %o3 = insertelement <4 x half> %o2, half %c3, i64 3
  ret <4 x half> %o3
}