11a18de3dSPhilip Reames; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2cee313d2SEric Christopher; RUN: opt -S  -mtriple=s390x-unknown-linux -mcpu=z13 -loop-vectorize -dce \
3cee313d2SEric Christopher; RUN:   -instcombine -force-vector-width=2  < %s | FileCheck %s
4cee313d2SEric Christopher;
5cee313d2SEric Christopher; Test that loop vectorizer does not generate vector addresses that must then
6cee313d2SEric Christopher; always be extracted.
7cee313d2SEric Christopher
8cee313d2SEric Christopher; Check that the addresses for a scalarized memory access is not extracted
9cee313d2SEric Christopher; from a vector register.
10cee313d2SEric Christopherdefine i32 @foo(i32* nocapture %A) {
11cee313d2SEric Christopher; CHECK-LABEL: @foo(
121a18de3dSPhilip Reames; CHECK-NEXT:  entry:
131a18de3dSPhilip Reames; CHECK-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
141a18de3dSPhilip Reames; CHECK:       vector.ph:
151a18de3dSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
161a18de3dSPhilip Reames; CHECK:       vector.body:
171a18de3dSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
181a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = shl nsw i64 [[INDEX]], 2
191a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = shl i64 [[INDEX]], 2
201a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = or i64 [[TMP1]], 4
211a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[TMP0]]
221a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i32, i32* [[A]], i64 [[TMP2]]
231a18de3dSPhilip Reames; CHECK-NEXT:    store i32 4, i32* [[TMP3]], align 4
241a18de3dSPhilip Reames; CHECK-NEXT:    store i32 4, i32* [[TMP4]], align 4
251a18de3dSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
261a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i64 [[INDEX_NEXT]], 10000
271a18de3dSPhilip Reames; CHECK-NEXT:    br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
281a18de3dSPhilip Reames; CHECK:       middle.block:
291a18de3dSPhilip Reames; CHECK-NEXT:    br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
301a18de3dSPhilip Reames; CHECK:       scalar.ph:
311a18de3dSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
321a18de3dSPhilip Reames; CHECK:       for.body:
33*a30e77b6SNuno Lopes; CHECK-NEXT:    br i1 poison, label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP2:![0-9]+]]
341a18de3dSPhilip Reames; CHECK:       for.end:
35*a30e77b6SNuno Lopes; CHECK-NEXT:    ret i32 poison
361a18de3dSPhilip Reames;
37cee313d2SEric Christopher
38cee313d2SEric Christopherentry:
39cee313d2SEric Christopher  br label %for.body
40cee313d2SEric Christopher
41cee313d2SEric Christopherfor.body:
42cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
43cee313d2SEric Christopher  %0 = shl nsw i64 %indvars.iv, 2
44cee313d2SEric Christopher  %arrayidx = getelementptr inbounds i32, i32* %A, i64 %0
45cee313d2SEric Christopher  store i32 4, i32* %arrayidx, align 4
46cee313d2SEric Christopher  %indvars.iv.next = add i64 %indvars.iv, 1
47cee313d2SEric Christopher  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
48cee313d2SEric Christopher  %exitcond = icmp eq i32 %lftr.wideiv, 10000
49cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
50cee313d2SEric Christopher
51cee313d2SEric Christopherfor.end:
52*a30e77b6SNuno Lopes  ret i32 poison
53cee313d2SEric Christopher}
54cee313d2SEric Christopher
55cee313d2SEric Christopher
56cee313d2SEric Christopher; Check that a load of address is scalarized.
57cee313d2SEric Christopherdefine i32 @foo1(i32* nocapture noalias %A, i32** nocapture %PtrPtr) {
58cee313d2SEric Christopher; CHECK-LABEL: @foo1(
591a18de3dSPhilip Reames; CHECK-NEXT:  entry:
601a18de3dSPhilip Reames; CHECK-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
611a18de3dSPhilip Reames; CHECK:       vector.ph:
621a18de3dSPhilip Reames; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
631a18de3dSPhilip Reames; CHECK:       vector.body:
641a18de3dSPhilip Reames; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
651a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP0:%.*]] = or i64 [[INDEX]], 1
661a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i32*, i32** [[PTRPTR:%.*]], i64 [[INDEX]]
671a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i32*, i32** [[PTRPTR]], i64 [[TMP0]]
681a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP3:%.*]] = load i32*, i32** [[TMP1]], align 8
691a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP4:%.*]] = load i32*, i32** [[TMP2]], align 8
701a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP5:%.*]] = load i32, i32* [[TMP3]], align 4
711a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP6:%.*]] = load i32, i32* [[TMP4]], align 4
72e6ad9ef4SPhilip Reames; CHECK-NEXT:    [[TMP7:%.*]] = insertelement <2 x i32> poison, i32 [[TMP5]], i64 0
73e6ad9ef4SPhilip Reames; CHECK-NEXT:    [[TMP8:%.*]] = insertelement <2 x i32> [[TMP7]], i32 [[TMP6]], i64 1
741a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP9:%.*]] = getelementptr inbounds i32, i32* [[A:%.*]], i64 [[INDEX]]
751a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP10:%.*]] = bitcast i32* [[TMP9]] to <2 x i32>*
761a18de3dSPhilip Reames; CHECK-NEXT:    store <2 x i32> [[TMP8]], <2 x i32>* [[TMP10]], align 4
771a18de3dSPhilip Reames; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
781a18de3dSPhilip Reames; CHECK-NEXT:    [[TMP11:%.*]] = icmp eq i64 [[INDEX_NEXT]], 10000
791a18de3dSPhilip Reames; CHECK-NEXT:    br i1 [[TMP11]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
801a18de3dSPhilip Reames; CHECK:       middle.block:
811a18de3dSPhilip Reames; CHECK-NEXT:    br i1 true, label [[FOR_END:%.*]], label [[SCALAR_PH]]
821a18de3dSPhilip Reames; CHECK:       scalar.ph:
831a18de3dSPhilip Reames; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
841a18de3dSPhilip Reames; CHECK:       for.body:
85*a30e77b6SNuno Lopes; CHECK-NEXT:    br i1 poison, label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
861a18de3dSPhilip Reames; CHECK:       for.end:
87*a30e77b6SNuno Lopes; CHECK-NEXT:    ret i32 poison
881a18de3dSPhilip Reames;
89cee313d2SEric Christopher
90cee313d2SEric Christopherentry:
91cee313d2SEric Christopher  br label %for.body
92cee313d2SEric Christopher
93cee313d2SEric Christopherfor.body:
94cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
95cee313d2SEric Christopher  %ptr = getelementptr inbounds i32*, i32** %PtrPtr, i64 %indvars.iv
96cee313d2SEric Christopher  %el = load i32*, i32** %ptr
97cee313d2SEric Christopher  %v = load i32, i32* %el
98cee313d2SEric Christopher  %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
99cee313d2SEric Christopher  store i32 %v, i32* %arrayidx, align 4
100cee313d2SEric Christopher  %indvars.iv.next = add i64 %indvars.iv, 1
101cee313d2SEric Christopher  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
102cee313d2SEric Christopher  %exitcond = icmp eq i32 %lftr.wideiv, 10000
103cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
104cee313d2SEric Christopher
105cee313d2SEric Christopherfor.end:
106*a30e77b6SNuno Lopes  ret i32 poison
107cee313d2SEric Christopher}
108