• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc < %s -march=bpfel -show-mc-encoding | FileCheck %s
2
3; Function Attrs: nounwind uwtable
4define i32 @ld_b(i64 %foo, i64* nocapture %bar, i8* %ctx, i8* %ctx2) #0 {
5  %1 = tail call i64 @llvm.bpf.load.byte(i8* %ctx, i64 123) #2
6  %2 = add i64 %1, %foo
7  %3 = load volatile i64, i64* %bar, align 8
8  %4 = add i64 %2, %3
9  %5 = tail call i64 @llvm.bpf.load.byte(i8* %ctx2, i64 %foo) #2
10  %6 = add i64 %4, %5
11  %7 = load volatile i64, i64* %bar, align 8
12  %8 = add i64 %6, %7
13  %9 = trunc i64 %8 to i32
14  ret i32 %9
15; CHECK-LABEL: ld_b:
16; CHECK: ldabs_b r0, r6.data + 123
17; CHECK: ldind_b r0, r6.data
18}
19
20declare i64 @llvm.bpf.load.byte(i8*, i64) #1
21
22; Function Attrs: nounwind uwtable
23define i32 @ld_h(i8* %ctx, i8* %ctx2, i32 %foo) #0 {
24  %1 = tail call i64 @llvm.bpf.load.half(i8* %ctx, i64 123) #2
25  %2 = sext i32 %foo to i64
26  %3 = tail call i64 @llvm.bpf.load.half(i8* %ctx2, i64 %2) #2
27  %4 = add i64 %3, %1
28  %5 = trunc i64 %4 to i32
29  ret i32 %5
30; CHECK-LABEL: ld_h:
31; CHECK: ldind_h r0, r6.data
32; CHECK: ldabs_h r0, r6.data + 123
33}
34
35declare i64 @llvm.bpf.load.half(i8*, i64) #1
36
37; Function Attrs: nounwind uwtable
38define i32 @ld_w(i8* %ctx, i8* %ctx2, i32 %foo) #0 {
39  %1 = tail call i64 @llvm.bpf.load.word(i8* %ctx, i64 123) #2
40  %2 = sext i32 %foo to i64
41  %3 = tail call i64 @llvm.bpf.load.word(i8* %ctx2, i64 %2) #2
42  %4 = add i64 %3, %1
43  %5 = trunc i64 %4 to i32
44  ret i32 %5
45; CHECK-LABEL: ld_w:
46; CHECK: ldind_w r0, r6.data
47; CHECK: ldabs_w r0, r6.data + 123
48}
49
50declare i64 @llvm.bpf.load.word(i8*, i64) #1
51
52define i32 @ld_pseudo() #0 {
53entry:
54  %call = tail call i64 @llvm.bpf.pseudo(i64 2, i64 3)
55  tail call void @bar(i64 %call, i32 4) #2
56  ret i32 0
57; CHECK-LABEL: ld_pseudo:
58; CHECK: ld_pseudo r1, 2, 3 # encoding: [0x18,0x21,0x00,0x00,0x03,0x00
59}
60
61declare void @bar(i64, i32) #1
62
63declare i64 @llvm.bpf.pseudo(i64, i64) #2
64
65define i32 @bswap(i64 %a, i64 %b, i64 %c) #0 {
66entry:
67  %0 = tail call i64 @llvm.bswap.i64(i64 %a)
68  %conv = trunc i64 %b to i32
69  %1 = tail call i32 @llvm.bswap.i32(i32 %conv)
70  %conv1 = zext i32 %1 to i64
71  %add = add i64 %conv1, %0
72  %conv2 = trunc i64 %c to i16
73  %2 = tail call i16 @llvm.bswap.i16(i16 %conv2)
74  %conv3 = zext i16 %2 to i64
75  %add4 = add i64 %add, %conv3
76  %conv5 = trunc i64 %add4 to i32
77  ret i32 %conv5
78; CHECK-LABEL: bswap:
79; CHECK: bswap64 r1     # encoding: [0xdc,0x01,0x00,0x00,0x40,0x00,0x00,0x00]
80; CHECK: bswap32 r2     # encoding: [0xdc,0x02,0x00,0x00,0x20,0x00,0x00,0x00]
81; CHECK: add     r2, r1 # encoding: [0x0f,0x12,0x00,0x00,0x00,0x00,0x00,0x00]
82; CHECK: bswap16 r3     # encoding: [0xdc,0x03,0x00,0x00,0x10,0x00,0x00,0x00]
83; CHECK: add     r2, r3 # encoding: [0x0f,0x32,0x00,0x00,0x00,0x00,0x00,0x00]
84}
85
86declare i64 @llvm.bswap.i64(i64) #1
87declare i32 @llvm.bswap.i32(i32) #1
88declare i16 @llvm.bswap.i16(i16) #1
89