xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/fixup-bw-inst.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc -fixup-byte-word-insts=1 -march=x86-64 < %s | \
2*9880d681SAndroid Build Coastguard Worker; RUN: FileCheck -check-prefix CHECK -check-prefix BWON %s
3*9880d681SAndroid Build Coastguard Worker; RUN: llc -fixup-byte-word-insts=0 -march=x86-64 < %s | \
4*9880d681SAndroid Build Coastguard Worker; RUN: FileCheck -check-prefix CHECK -check-prefix BWOFF %s
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
7*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-apple-macosx10.8.0"
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Worker%struct.A = type { i8, i8, i8, i8, i8, i8, i8, i8 }
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker; This has byte loads interspersed with byte stores, in a single
12*9880d681SAndroid Build Coastguard Worker; basic-block loop.  The upper portion should be dead, so the movb loads
13*9880d681SAndroid Build Coastguard Worker; should have been changed into movzbl instead.
14*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: foo1
15*9880d681SAndroid Build Coastguard Worker; load:
16*9880d681SAndroid Build Coastguard Worker; BWON:  movzbl
17*9880d681SAndroid Build Coastguard Worker; BWOFF: movb
18*9880d681SAndroid Build Coastguard Worker; store:
19*9880d681SAndroid Build Coastguard Worker; CHECK: movb
20*9880d681SAndroid Build Coastguard Worker; load:
21*9880d681SAndroid Build Coastguard Worker; BWON: movzbl
22*9880d681SAndroid Build Coastguard Worker; BWOFF: movb
23*9880d681SAndroid Build Coastguard Worker; store:
24*9880d681SAndroid Build Coastguard Worker; CHECK: movb
25*9880d681SAndroid Build Coastguard Worker; CHECK: ret
26*9880d681SAndroid Build Coastguard Workerdefine void @foo1(i32 %count,
27*9880d681SAndroid Build Coastguard Worker                  %struct.A* noalias nocapture %q,
28*9880d681SAndroid Build Coastguard Worker                  %struct.A* noalias nocapture %p)
29*9880d681SAndroid Build Coastguard Worker                    nounwind uwtable noinline ssp {
30*9880d681SAndroid Build Coastguard Worker  %1 = icmp sgt i32 %count, 0
31*9880d681SAndroid Build Coastguard Worker  br i1 %1, label %.lr.ph, label %._crit_edge
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard Worker.lr.ph:                                           ; preds = %0
34*9880d681SAndroid Build Coastguard Worker  %2 = getelementptr inbounds %struct.A, %struct.A* %q, i64 0, i32 0
35*9880d681SAndroid Build Coastguard Worker  %3 = getelementptr inbounds %struct.A, %struct.A* %q, i64 0, i32 1
36*9880d681SAndroid Build Coastguard Worker  br label %a4
37*9880d681SAndroid Build Coastguard Worker
38*9880d681SAndroid Build Coastguard Workera4:                                       ; preds = %4, %.lr.ph
39*9880d681SAndroid Build Coastguard Worker  %i.02 = phi i32 [ 0, %.lr.ph ], [ %a9, %a4 ]
40*9880d681SAndroid Build Coastguard Worker  %.01 = phi %struct.A* [ %p, %.lr.ph ], [ %a10, %a4 ]
41*9880d681SAndroid Build Coastguard Worker  %a5 = load i8, i8* %2, align 1
42*9880d681SAndroid Build Coastguard Worker  %a7 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 0
43*9880d681SAndroid Build Coastguard Worker  store i8 %a5, i8* %a7, align 1
44*9880d681SAndroid Build Coastguard Worker  %a8 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 0, i32 1
45*9880d681SAndroid Build Coastguard Worker  %a6 = load i8, i8* %3, align 1
46*9880d681SAndroid Build Coastguard Worker  store i8 %a6, i8* %a8, align 1
47*9880d681SAndroid Build Coastguard Worker  %a9 = add nsw i32 %i.02, 1
48*9880d681SAndroid Build Coastguard Worker  %a10 = getelementptr inbounds %struct.A, %struct.A* %.01, i64 1
49*9880d681SAndroid Build Coastguard Worker  %exitcond = icmp eq i32 %a9, %count
50*9880d681SAndroid Build Coastguard Worker  br i1 %exitcond, label %._crit_edge, label %a4
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard Worker._crit_edge:                                      ; preds = %4, %0
53*9880d681SAndroid Build Coastguard Worker  ret void
54*9880d681SAndroid Build Coastguard Worker}
55*9880d681SAndroid Build Coastguard Worker
56*9880d681SAndroid Build Coastguard Worker%struct.B = type { i16, i16, i16, i16, i16, i16, i16, i16 }
57*9880d681SAndroid Build Coastguard Worker
58*9880d681SAndroid Build Coastguard Worker; This has word loads interspersed with word stores.
59*9880d681SAndroid Build Coastguard Worker; The upper portion should be dead, so the movw loads should have
60*9880d681SAndroid Build Coastguard Worker; been changed into movzwl instead.
61*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: foo2
62*9880d681SAndroid Build Coastguard Worker; load:
63*9880d681SAndroid Build Coastguard Worker; BWON:  movzwl
64*9880d681SAndroid Build Coastguard Worker; BWOFF: movw
65*9880d681SAndroid Build Coastguard Worker; store:
66*9880d681SAndroid Build Coastguard Worker; CHECK: movw
67*9880d681SAndroid Build Coastguard Worker; load:
68*9880d681SAndroid Build Coastguard Worker; BWON:  movzwl
69*9880d681SAndroid Build Coastguard Worker; BWOFF: movw
70*9880d681SAndroid Build Coastguard Worker; store:
71*9880d681SAndroid Build Coastguard Worker; CHECK: movw
72*9880d681SAndroid Build Coastguard Worker; CHECK: ret
73*9880d681SAndroid Build Coastguard Workerdefine void @foo2(i32 %count,
74*9880d681SAndroid Build Coastguard Worker                  %struct.B* noalias nocapture %q,
75*9880d681SAndroid Build Coastguard Worker                  %struct.B* noalias nocapture %p)
76*9880d681SAndroid Build Coastguard Worker                    nounwind uwtable noinline ssp {
77*9880d681SAndroid Build Coastguard Worker  %1 = icmp sgt i32 %count, 0
78*9880d681SAndroid Build Coastguard Worker  br i1 %1, label %.lr.ph, label %._crit_edge
79*9880d681SAndroid Build Coastguard Worker
80*9880d681SAndroid Build Coastguard Worker.lr.ph:                                           ; preds = %0
81*9880d681SAndroid Build Coastguard Worker  %2 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 0
82*9880d681SAndroid Build Coastguard Worker  %3 = getelementptr inbounds %struct.B, %struct.B* %q, i64 0, i32 1
83*9880d681SAndroid Build Coastguard Worker  br label %a4
84*9880d681SAndroid Build Coastguard Worker
85*9880d681SAndroid Build Coastguard Workera4:                                       ; preds = %4, %.lr.ph
86*9880d681SAndroid Build Coastguard Worker  %i.02 = phi i32 [ 0, %.lr.ph ], [ %a9, %a4 ]
87*9880d681SAndroid Build Coastguard Worker  %.01 = phi %struct.B* [ %p, %.lr.ph ], [ %a10, %a4 ]
88*9880d681SAndroid Build Coastguard Worker  %a5 = load i16, i16* %2, align 2
89*9880d681SAndroid Build Coastguard Worker  %a7 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 0
90*9880d681SAndroid Build Coastguard Worker  store i16 %a5, i16* %a7, align 2
91*9880d681SAndroid Build Coastguard Worker  %a8 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 0, i32 1
92*9880d681SAndroid Build Coastguard Worker  %a6 = load i16, i16* %3, align 2
93*9880d681SAndroid Build Coastguard Worker  store i16 %a6, i16* %a8, align 2
94*9880d681SAndroid Build Coastguard Worker  %a9 = add nsw i32 %i.02, 1
95*9880d681SAndroid Build Coastguard Worker  %a10 = getelementptr inbounds %struct.B, %struct.B* %.01, i64 1
96*9880d681SAndroid Build Coastguard Worker  %exitcond = icmp eq i32 %a9, %count
97*9880d681SAndroid Build Coastguard Worker  br i1 %exitcond, label %._crit_edge, label %a4
98*9880d681SAndroid Build Coastguard Worker
99*9880d681SAndroid Build Coastguard Worker._crit_edge:                                      ; preds = %4, %0
100*9880d681SAndroid Build Coastguard Worker  ret void
101*9880d681SAndroid Build Coastguard Worker}
102*9880d681SAndroid Build Coastguard Worker
103*9880d681SAndroid Build Coastguard Worker; This test contains nothing but a simple byte load and store.  Since
104*9880d681SAndroid Build Coastguard Worker; movb encodes smaller, we do not want to use movzbl unless in a tight loop.
105*9880d681SAndroid Build Coastguard Worker; So this test checks that movb is used.
106*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: foo3:
107*9880d681SAndroid Build Coastguard Worker; CHECK: movb
108*9880d681SAndroid Build Coastguard Worker; CHECK: movb
109*9880d681SAndroid Build Coastguard Workerdefine void @foo3(i8 *%dst, i8 *%src) {
110*9880d681SAndroid Build Coastguard Worker  %t0 = load i8, i8 *%src, align 1
111*9880d681SAndroid Build Coastguard Worker  store i8 %t0, i8 *%dst, align 1
112*9880d681SAndroid Build Coastguard Worker  ret void
113*9880d681SAndroid Build Coastguard Worker}
114*9880d681SAndroid Build Coastguard Worker
115*9880d681SAndroid Build Coastguard Worker; This test contains nothing but a simple word load and store.  Since
116*9880d681SAndroid Build Coastguard Worker; movw and movzwl are the same size, we should always choose to use
117*9880d681SAndroid Build Coastguard Worker; movzwl instead.
118*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: foo4:
119*9880d681SAndroid Build Coastguard Worker; BWON:  movzwl
120*9880d681SAndroid Build Coastguard Worker; BWOFF: movw
121*9880d681SAndroid Build Coastguard Worker; CHECK: movw
122*9880d681SAndroid Build Coastguard Workerdefine void @foo4(i16 *%dst, i16 *%src) {
123*9880d681SAndroid Build Coastguard Worker  %t0 = load i16, i16 *%src, align 2
124*9880d681SAndroid Build Coastguard Worker  store i16 %t0, i16 *%dst, align 2
125*9880d681SAndroid Build Coastguard Worker  ret void
126*9880d681SAndroid Build Coastguard Worker}
127