1; RUN: llc < %s -march=bpf -verify-machineinstrs | FileCheck %s
2
3; Source code:
4;struct __sk_buff;
5;unsigned long long
6;load_byte(void *skb, unsigned long long off) asm("llvm.bpf.load.byte");
7;unsigned long long
8;load_half(void *skb, unsigned long long off) asm("llvm.bpf.load.half");
9;typedef unsigned char      uint8_t;
10;typedef unsigned short     uint16_t;
11;
12;int func_b(struct __sk_buff *skb)
13;{
14;    uint8_t t = load_byte(skb, 0);
15;    return t;
16;}
17;
18;int func_h(struct __sk_buff *skb)
19;{
20;    uint16_t t = load_half(skb, 0);
21;    return t;
22;}
23;
24;int func_w(struct __sk_buff *skb)
25;{
26;    uint32_t t = load_word(skb, 0);
27;    return t;
28;}
29
30%struct.__sk_buff = type opaque
31
32; Function Attrs: nounwind readonly
33define i32 @func_b(%struct.__sk_buff* %skb) local_unnamed_addr #0 {
34entry:
35  %0 = bitcast %struct.__sk_buff* %skb to i8*
36  %call = tail call i64 @llvm.bpf.load.byte(i8* %0, i64 0)
37  %conv = trunc i64 %call to i32
38  %conv1 = and i32 %conv, 255
39; CHECK-NOT:  r0 &= 255
40  ret i32 %conv1
41}
42
43; Function Attrs: nounwind readonly
44declare i64 @llvm.bpf.load.byte(i8*, i64) #1
45
46; Function Attrs: nounwind readonly
47define i32 @func_h(%struct.__sk_buff* %skb) local_unnamed_addr #0 {
48entry:
49  %0 = bitcast %struct.__sk_buff* %skb to i8*
50  %call = tail call i64 @llvm.bpf.load.half(i8* %0, i64 0)
51  %conv = trunc i64 %call to i32
52  %conv1 = and i32 %conv, 65535
53; CHECK-NOT:  r0 &= 65535
54  ret i32 %conv1
55}
56
57; Function Attrs: nounwind readonly
58declare i64 @llvm.bpf.load.half(i8*, i64) #1
59