• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt %s -loop-vectorize -instcombine -simplifycfg -mtriple=x86_64-unknown-linux-gnu -mattr=avx512vl,avx512dq,avx512bw -S | FileCheck %s
3
4@bytes = global [128 x i8] zeroinitializer, align 16
5
6; Make sure we end up with vector code for this loop. We used to try to create
7; a VF=64,UF=4 loop, but the scalar trip count is only 128 so
8; the vector loop was dead code leaving only a scalar remainder.
9define zeroext i8 @sum() {
10; CHECK-LABEL: @sum(
11; CHECK-NEXT:  entry:
12; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
13; CHECK:       vector.body:
14; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
15; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <64 x i8> [ zeroinitializer, [[ENTRY]] ], [ [[TMP4:%.*]], [[VECTOR_BODY]] ]
16; CHECK-NEXT:    [[VEC_PHI1:%.*]] = phi <64 x i8> [ zeroinitializer, [[ENTRY]] ], [ [[TMP5:%.*]], [[VECTOR_BODY]] ]
17; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr inbounds [128 x i8], [128 x i8]* @bytes, i64 0, i64 [[INDEX]]
18; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <64 x i8>*
19; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <64 x i8>, <64 x i8>* [[TMP1]], align 16
20; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i8, i8* [[TMP0]], i64 64
21; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i8* [[TMP2]] to <64 x i8>*
22; CHECK-NEXT:    [[WIDE_LOAD2:%.*]] = load <64 x i8>, <64 x i8>* [[TMP3]], align 16
23; CHECK-NEXT:    [[TMP4]] = add <64 x i8> [[WIDE_LOAD]], [[VEC_PHI]]
24; CHECK-NEXT:    [[TMP5]] = add <64 x i8> [[WIDE_LOAD2]], [[VEC_PHI1]]
25; CHECK-NEXT:    [[INDEX_NEXT]] = add i64 [[INDEX]], 128
26; CHECK-NEXT:    [[TMP6:%.*]] = icmp eq i64 [[INDEX]], 0
27; CHECK-NEXT:    br i1 [[TMP6]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop !0
28; CHECK:       middle.block:
29; CHECK-NEXT:    [[BIN_RDX:%.*]] = add <64 x i8> [[TMP5]], [[TMP4]]
30; CHECK-NEXT:    [[TMP7:%.*]] = call i8 @llvm.vector.reduce.add.v64i8(<64 x i8> [[BIN_RDX]])
31; CHECK-NEXT:    ret i8 [[TMP7]]
32;
33entry:
34  br label %for.body
35
36for.body:                                         ; preds = %for.body, %entry
37  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
38  %r.010 = phi i8 [ 0, %entry ], [ %add, %for.body ]
39  %arrayidx = getelementptr inbounds [128 x i8], [128 x i8]* @bytes, i64 0, i64 %indvars.iv
40  %0 = load i8, i8* %arrayidx, align 1
41  %add = add i8 %0, %r.010
42  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
43  %exitcond = icmp eq i64 %indvars.iv.next, 128
44  br i1 %exitcond, label %for.end, label %for.body
45
46for.end:                                          ; preds = %for.body
47  %add.lcssa = phi i8 [ %add, %for.body ]
48  ret i8 %add.lcssa
49}
50