1; RUN: llc < %s -march=bpf -verify-machineinstrs | FileCheck %s
2
3; Source code:
4; struct xdp_md {
5;   unsigned data;
6;   unsigned data_end;
7; };
8;
9; int gbl;
10; int xdp_dummy(struct xdp_md *xdp)
11; {
12;   char tmp;
13;   long addr;
14;
15;   if (gbl) {
16;     long addr1 = (long)xdp->data;
17;     tmp = *(char *)addr1;
18;     if (tmp == 1)
19;       return 3;
20;   } else {
21;     tmp = *(volatile char *)(long)xdp->data_end;
22;     if (tmp == 1)
23;       return 2;
24;   }
25;   addr = (long)xdp->data;
26;   tmp = *(volatile char *)addr;
27;   if (tmp == 0)
28;     return 1;
29;   return 0;
30; }
31;
32; unsigned int rol32(unsigned int word, unsigned int shift)
33; {
34;   return (word << shift) | (word >> ((-shift) & 31));
35; }
36%struct.xdp_md = type { i32, i32 }
37
38@gbl = common local_unnamed_addr global i32 0, align 4
39
40; Function Attrs: norecurse nounwind
41define i32 @xdp_dummy(%struct.xdp_md* nocapture readonly) local_unnamed_addr #0 {
42  %2 = load i32, i32* @gbl, align 4
43  %3 = icmp eq i32 %2, 0
44  br i1 %3, label %11, label %4
45
46; <label>:4:                                      ; preds = %1
47  %5 = getelementptr inbounds %struct.xdp_md, %struct.xdp_md* %0, i64 0, i32 0
48  %6 = load i32, i32* %5, align 4
49  %7 = zext i32 %6 to i64
50  %8 = inttoptr i64 %7 to i8*
51  %9 = load i8, i8* %8, align 1
52  %10 = icmp eq i8 %9, 1
53  br i1 %10, label %28, label %23
54; CHECK:  r1 = *(u32 *)(r1 + 0)
55; CHECK:  r2 = *(u8 *)(r1 + 0)
56
57; <label>:11:                                     ; preds = %1
58  %12 = getelementptr inbounds %struct.xdp_md, %struct.xdp_md* %0, i64 0, i32 1
59  %13 = load i32, i32* %12, align 4
60  %14 = zext i32 %13 to i64
61; CHECK:  r2 = *(u32 *)(r1 + 4)
62  %15 = inttoptr i64 %14 to i8*
63  %16 = load volatile i8, i8* %15, align 1
64; CHECK:  r2 = *(u8 *)(r2 + 0)
65  %17 = icmp eq i8 %16, 1
66  br i1 %17, label %28, label %18
67
68; <label>:18:                                     ; preds = %11
69  %19 = getelementptr inbounds %struct.xdp_md, %struct.xdp_md* %0, i64 0, i32 0
70  %20 = load i32, i32* %19, align 4
71  %21 = zext i32 %20 to i64
72  %22 = inttoptr i64 %21 to i8*
73  br label %23
74; CHECK: r1 = *(u32 *)(r1 + 0)
75
76; <label>:23:                                     ; preds = %18, %4
77  %24 = phi i8* [ %22, %18 ], [ %8, %4 ]
78; CHECK-NOT: r1 <<= 32
79; CHECK-NOT: r1 >>= 32
80  %25 = load volatile i8, i8* %24, align 1
81; CHECK:  r1 = *(u8 *)(r1 + 0)
82  %26 = icmp eq i8 %25, 0
83  %27 = zext i1 %26 to i32
84  br label %28
85
86; <label>:28:                                     ; preds = %4, %23, %11
87  %29 = phi i32 [ 3, %4 ], [ 2, %11 ], [ %27, %23 ]
88  ret i32 %29
89}
90
91; Function Attrs: norecurse nounwind readnone
92define i32 @rol32(i32, i32) local_unnamed_addr #1 {
93  %3 = shl i32 %0, %1
94; CHECK: r1 <<= 32
95; CHECK: r1 >>= 32
96  %4 = sub i32 0, %1
97  %5 = and i32 %4, 31
98  %6 = lshr i32 %0, %5
99; CHECK: r0 <<= 32
100; CHECK: r0 >>= 32
101  %7 = or i32 %6, %3
102  ret i32 %7
103}
104
105attributes #0 = { norecurse nounwind }
106attributes #1 = { norecurse nounwind readnone }
107