1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s  -loop-vectorize -S | FileCheck %s
3
4; This is a bugpoint reduction of a test from PR43582:
5; https://bugs.llvm.org/show_bug.cgi?id=43582
6
7; ...but it's over-simplifying the underlying question:
8; TODO: Should this be vectorized rather than allowing the backend to load combine?
9;       The original code is a bswap pattern.
10
11target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
12target triple = "x86_64-w64-windows-gnu"
13
14define void @cff_index_load_offsets(i1 %cond, i8 %x, i8* %p) #0 {
15; CHECK-LABEL: @cff_index_load_offsets(
16; CHECK-NEXT:  entry:
17; CHECK-NEXT:    br i1 [[COND:%.*]], label [[IF_THEN:%.*]], label [[EXIT:%.*]]
18; CHECK:       if.then:
19; CHECK-NEXT:    br i1 true, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
20; CHECK:       vector.ph:
21; CHECK-NEXT:    [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i8> undef, i8 [[X:%.*]], i32 0
22; CHECK-NEXT:    [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i8> [[BROADCAST_SPLATINSERT]], <4 x i8> undef, <4 x i32> zeroinitializer
23; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
24; CHECK:       vector.body:
25; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
26; CHECK-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
27; CHECK-NEXT:    [[TMP1:%.*]] = mul i64 [[TMP0]], 4
28; CHECK-NEXT:    [[NEXT_GEP:%.*]] = getelementptr i8, i8* null, i64 [[TMP1]]
29; CHECK-NEXT:    [[TMP2:%.*]] = zext <4 x i8> [[BROADCAST_SPLAT]] to <4 x i32>
30; CHECK-NEXT:    [[TMP3:%.*]] = shl nuw <4 x i32> [[TMP2]], <i32 24, i32 24, i32 24, i32 24>
31; CHECK-NEXT:    [[TMP4:%.*]] = load i8, i8* [[P:%.*]], align 1, !tbaa !1
32; CHECK-NEXT:    [[TMP5:%.*]] = load i8, i8* [[P]], align 1, !tbaa !1
33; CHECK-NEXT:    [[TMP6:%.*]] = load i8, i8* [[P]], align 1, !tbaa !1
34; CHECK-NEXT:    [[TMP7:%.*]] = load i8, i8* [[P]], align 1, !tbaa !1
35; CHECK-NEXT:    [[TMP8:%.*]] = insertelement <4 x i8> undef, i8 [[TMP4]], i32 0
36; CHECK-NEXT:    [[TMP9:%.*]] = insertelement <4 x i8> [[TMP8]], i8 [[TMP5]], i32 1
37; CHECK-NEXT:    [[TMP10:%.*]] = insertelement <4 x i8> [[TMP9]], i8 [[TMP6]], i32 2
38; CHECK-NEXT:    [[TMP11:%.*]] = insertelement <4 x i8> [[TMP10]], i8 [[TMP7]], i32 3
39; CHECK-NEXT:    [[TMP12:%.*]] = zext <4 x i8> [[TMP11]] to <4 x i32>
40; CHECK-NEXT:    [[TMP13:%.*]] = shl nuw nsw <4 x i32> [[TMP12]], <i32 16, i32 16, i32 16, i32 16>
41; CHECK-NEXT:    [[TMP14:%.*]] = or <4 x i32> [[TMP13]], [[TMP3]]
42; CHECK-NEXT:    [[TMP15:%.*]] = load i8, i8* undef, align 1, !tbaa !1
43; CHECK-NEXT:    [[TMP16:%.*]] = load i8, i8* undef, align 1, !tbaa !1
44; CHECK-NEXT:    [[TMP17:%.*]] = load i8, i8* undef, align 1, !tbaa !1
45; CHECK-NEXT:    [[TMP18:%.*]] = load i8, i8* undef, align 1, !tbaa !1
46; CHECK-NEXT:    [[TMP19:%.*]] = or <4 x i32> [[TMP14]], zeroinitializer
47; CHECK-NEXT:    [[TMP20:%.*]] = or <4 x i32> [[TMP19]], zeroinitializer
48; CHECK-NEXT:    [[TMP21:%.*]] = extractelement <4 x i32> [[TMP20]], i32 0
49; CHECK-NEXT:    store i32 [[TMP21]], i32* undef, align 4, !tbaa !4
50; CHECK-NEXT:    [[TMP22:%.*]] = extractelement <4 x i32> [[TMP20]], i32 1
51; CHECK-NEXT:    store i32 [[TMP22]], i32* undef, align 4, !tbaa !4
52; CHECK-NEXT:    [[TMP23:%.*]] = extractelement <4 x i32> [[TMP20]], i32 2
53; CHECK-NEXT:    store i32 [[TMP23]], i32* undef, align 4, !tbaa !4
54; CHECK-NEXT:    [[TMP24:%.*]] = extractelement <4 x i32> [[TMP20]], i32 3
55; CHECK-NEXT:    store i32 [[TMP24]], i32* undef, align 4, !tbaa !4
56; CHECK-NEXT:    [[INDEX_NEXT]] = add i64 [[INDEX]], 4
57; CHECK-NEXT:    [[TMP25:%.*]] = icmp eq i64 [[INDEX_NEXT]], 0
58; CHECK-NEXT:    br i1 [[TMP25]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop !6
59; CHECK:       middle.block:
60; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i64 1, 0
61; CHECK-NEXT:    br i1 [[CMP_N]], label [[SW_EPILOG:%.*]], label [[SCALAR_PH]]
62; CHECK:       scalar.ph:
63; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i8* [ null, [[MIDDLE_BLOCK]] ], [ null, [[IF_THEN]] ]
64; CHECK-NEXT:    br label [[FOR_BODY68:%.*]]
65; CHECK:       for.body68:
66; CHECK-NEXT:    [[P_359:%.*]] = phi i8* [ [[ADD_PTR86:%.*]], [[FOR_BODY68]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
67; CHECK-NEXT:    [[CONV70:%.*]] = zext i8 [[X]] to i32
68; CHECK-NEXT:    [[SHL71:%.*]] = shl nuw i32 [[CONV70]], 24
69; CHECK-NEXT:    [[TMP26:%.*]] = load i8, i8* [[P]], align 1, !tbaa !1
70; CHECK-NEXT:    [[CONV73:%.*]] = zext i8 [[TMP26]] to i32
71; CHECK-NEXT:    [[SHL74:%.*]] = shl nuw nsw i32 [[CONV73]], 16
72; CHECK-NEXT:    [[OR75:%.*]] = or i32 [[SHL74]], [[SHL71]]
73; CHECK-NEXT:    [[TMP27:%.*]] = load i8, i8* undef, align 1, !tbaa !1
74; CHECK-NEXT:    [[SHL78:%.*]] = shl nuw nsw i32 undef, 8
75; CHECK-NEXT:    [[OR79:%.*]] = or i32 [[OR75]], [[SHL78]]
76; CHECK-NEXT:    [[CONV81:%.*]] = zext i8 undef to i32
77; CHECK-NEXT:    [[OR83:%.*]] = or i32 [[OR79]], [[CONV81]]
78; CHECK-NEXT:    store i32 [[OR83]], i32* undef, align 4, !tbaa !4
79; CHECK-NEXT:    [[ADD_PTR86]] = getelementptr inbounds i8, i8* [[P_359]], i64 4
80; CHECK-NEXT:    [[CMP66:%.*]] = icmp ult i8* [[ADD_PTR86]], undef
81; CHECK-NEXT:    br i1 [[CMP66]], label [[FOR_BODY68]], label [[SW_EPILOG]], !llvm.loop !8
82; CHECK:       sw.epilog:
83; CHECK-NEXT:    unreachable
84; CHECK:       Exit:
85; CHECK-NEXT:    ret void
86;
87entry:
88  br i1 %cond, label %if.then, label %Exit
89
90if.then:                                          ; preds = %entry
91  br label %for.body68
92
93for.body68:                                       ; preds = %for.body68, %if.then
94  %p.359 = phi i8* [ %add.ptr86, %for.body68 ], [ null, %if.then ]
95  %conv70 = zext i8 %x to i32
96  %shl71 = shl nuw i32 %conv70, 24
97  %0 = load i8, i8* %p, align 1, !tbaa !1
98  %conv73 = zext i8 %0 to i32
99  %shl74 = shl nuw nsw i32 %conv73, 16
100  %or75 = or i32 %shl74, %shl71
101  %1 = load i8, i8* undef, align 1, !tbaa !1
102  %shl78 = shl nuw nsw i32 undef, 8
103  %or79 = or i32 %or75, %shl78
104  %conv81 = zext i8 undef to i32
105  %or83 = or i32 %or79, %conv81
106  store i32 %or83, i32* undef, align 4, !tbaa !4
107  %add.ptr86 = getelementptr inbounds i8, i8* %p.359, i64 4
108  %cmp66 = icmp ult i8* %add.ptr86, undef
109  br i1 %cmp66, label %for.body68, label %sw.epilog
110
111sw.epilog:                                        ; preds = %for.body68
112  unreachable
113
114Exit:                                             ; preds = %entry
115  ret void
116}
117
118attributes #0 = { "use-soft-float"="false" }
119
120!llvm.ident = !{!0}
121
122!0 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git 0fedc26a0dc0066f3968b9fea6a4e1f746c8d5a4)"}
123!1 = !{!2, !2, i64 0}
124!2 = !{!"omnipotent char", !3, i64 0}
125!3 = !{!"Simple C/C++ TBAA"}
126!4 = !{!5, !5, i64 0}
127!5 = !{!"long", !2, i64 0}
128