[SLP] Add cost model for `llvm.powi.*` intrinsics
[llvm-project.git] / llvm / test / Transforms / PhaseOrdering / X86 / pixel-splat.ll
blob93e219655ccd2d47087093845873470418a6db32
1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -O2                   -S < %s  | FileCheck %s
3 ; RUN: opt -passes="default<O2>" -S < %s  | FileCheck %s
6 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-apple-macosx10.15.0"
9 ; https://llvm.org/PR49055
11 ; void loop_or(const unsigned char* __restrict pIn, unsigned int* __restrict pOut, int s) {
12 ;   for (int i = 0; i < s; i++) {
13 ;     unsigned int pixelChar = pIn[i];
14 ;     unsigned int pixel = pixelChar | (pixelChar << 8) | (pixelChar << 16) | (255 << 24);
15 ;     pOut[i] = pixel;
16 ;   }
17 ; }
19 ; We are looking for the shifts to get combined into mul along with vectorization.
21 define void @loop_or(i8* noalias %pIn, i32* noalias %pOut, i32 %s) {
22 ; CHECK-LABEL: @loop_or(
23 ; CHECK-NEXT:  entry:
24 ; CHECK-NEXT:    [[CMP1:%.*]] = icmp sgt i32 [[S:%.*]], 0
25 ; CHECK-NEXT:    br i1 [[CMP1]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END:%.*]]
26 ; CHECK:       for.body.preheader:
27 ; CHECK-NEXT:    [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[S]] to i64
28 ; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[S]], 8
29 ; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[FOR_BODY_PREHEADER5:%.*]], label [[VECTOR_PH:%.*]]
30 ; CHECK:       vector.ph:
31 ; CHECK-NEXT:    [[N_VEC:%.*]] = and i64 [[WIDE_TRIP_COUNT]], 4294967288
32 ; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
33 ; CHECK:       vector.body:
34 ; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
35 ; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr inbounds i8, i8* [[PIN:%.*]], i64 [[INDEX]]
36 ; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i8* [[TMP0]] to <4 x i8>*
37 ; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <4 x i8>, <4 x i8>* [[TMP1]], align 1
38 ; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i8, i8* [[TMP0]], i64 4
39 ; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i8* [[TMP2]] to <4 x i8>*
40 ; CHECK-NEXT:    [[WIDE_LOAD4:%.*]] = load <4 x i8>, <4 x i8>* [[TMP3]], align 1
41 ; CHECK-NEXT:    [[TMP4:%.*]] = zext <4 x i8> [[WIDE_LOAD]] to <4 x i32>
42 ; CHECK-NEXT:    [[TMP5:%.*]] = zext <4 x i8> [[WIDE_LOAD4]] to <4 x i32>
43 ; CHECK-NEXT:    [[TMP6:%.*]] = mul nuw nsw <4 x i32> [[TMP4]], <i32 65793, i32 65793, i32 65793, i32 65793>
44 ; CHECK-NEXT:    [[TMP7:%.*]] = mul nuw nsw <4 x i32> [[TMP5]], <i32 65793, i32 65793, i32 65793, i32 65793>
45 ; CHECK-NEXT:    [[TMP8:%.*]] = or <4 x i32> [[TMP6]], <i32 -16777216, i32 -16777216, i32 -16777216, i32 -16777216>
46 ; CHECK-NEXT:    [[TMP9:%.*]] = or <4 x i32> [[TMP7]], <i32 -16777216, i32 -16777216, i32 -16777216, i32 -16777216>
47 ; CHECK-NEXT:    [[TMP10:%.*]] = getelementptr inbounds i32, i32* [[POUT:%.*]], i64 [[INDEX]]
48 ; CHECK-NEXT:    [[TMP11:%.*]] = bitcast i32* [[TMP10]] to <4 x i32>*
49 ; CHECK-NEXT:    store <4 x i32> [[TMP8]], <4 x i32>* [[TMP11]], align 4
50 ; CHECK-NEXT:    [[TMP12:%.*]] = getelementptr inbounds i32, i32* [[TMP10]], i64 4
51 ; CHECK-NEXT:    [[TMP13:%.*]] = bitcast i32* [[TMP12]] to <4 x i32>*
52 ; CHECK-NEXT:    store <4 x i32> [[TMP9]], <4 x i32>* [[TMP13]], align 4
53 ; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
54 ; CHECK-NEXT:    [[TMP14:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
55 ; CHECK-NEXT:    br i1 [[TMP14]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
56 ; CHECK:       middle.block:
57 ; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 [[N_VEC]], [[WIDE_TRIP_COUNT]]
58 ; CHECK-NEXT:    br i1 [[CMP_N]], label [[FOR_END]], label [[FOR_BODY_PREHEADER5]]
59 ; CHECK:       for.body.preheader5:
60 ; CHECK-NEXT:    [[INDVARS_IV_PH:%.*]] = phi i64 [ 0, [[FOR_BODY_PREHEADER]] ], [ [[N_VEC]], [[MIDDLE_BLOCK]] ]
61 ; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
62 ; CHECK:       for.body:
63 ; CHECK-NEXT:    [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[INDVARS_IV_PH]], [[FOR_BODY_PREHEADER5]] ]
64 ; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i8, i8* [[PIN]], i64 [[INDVARS_IV]]
65 ; CHECK-NEXT:    [[TMP15:%.*]] = load i8, i8* [[ARRAYIDX]], align 1
66 ; CHECK-NEXT:    [[CONV:%.*]] = zext i8 [[TMP15]] to i32
67 ; CHECK-NEXT:    [[OR2:%.*]] = mul nuw nsw i32 [[CONV]], 65793
68 ; CHECK-NEXT:    [[OR3:%.*]] = or i32 [[OR2]], -16777216
69 ; CHECK-NEXT:    [[ARRAYIDX5:%.*]] = getelementptr inbounds i32, i32* [[POUT]], i64 [[INDVARS_IV]]
70 ; CHECK-NEXT:    store i32 [[OR3]], i32* [[ARRAYIDX5]], align 4
71 ; CHECK-NEXT:    [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
72 ; CHECK-NEXT:    [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
73 ; CHECK-NEXT:    br i1 [[EXITCOND_NOT]], label [[FOR_END]], label [[FOR_BODY]], !llvm.loop [[LOOP2:![0-9]+]]
74 ; CHECK:       for.end:
75 ; CHECK-NEXT:    ret void
77 entry:
78   br label %for.cond
80 for.cond:
81   %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
82   %cmp = icmp slt i32 %i.0, %s
83   br i1 %cmp, label %for.body, label %for.cond.cleanup
85 for.cond.cleanup:
86   br label %for.end
88 for.body:
89   %idxprom = sext i32 %i.0 to i64
90   %arrayidx = getelementptr inbounds i8, i8* %pIn, i64 %idxprom
91   %0 = load i8, i8* %arrayidx, align 1
92   %conv = zext i8 %0 to i32
93   %shl = shl i32 %conv, 8
94   %or = or i32 %conv, %shl
95   %shl1 = shl i32 %conv, 16
96   %or2 = or i32 %or, %shl1
97   %or3 = or i32 %or2, -16777216
98   %idxprom4 = sext i32 %i.0 to i64
99   %arrayidx5 = getelementptr inbounds i32, i32* %pOut, i64 %idxprom4
100   store i32 %or3, i32* %arrayidx5, align 4
101   br label %for.inc
103 for.inc:
104   %inc = add nsw i32 %i.0, 1
105   br label %for.cond
107 for.end:
108   ret void