[llvm] r318695 - bpf: add a test case for trunc-op optimization

Yonghong Song via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 20 13:37:58 PST 2017


Author: yhs
Date: Mon Nov 20 13:37:58 2017
New Revision: 318695

URL: http://llvm.org/viewvc/llvm-project?rev=318695&view=rev
Log:
bpf: add a test case for trunc-op optimization

Commit b5cbc7760ab8 ("[bpf] allow direct and indirect calls")
allowed more than one function in the bpf program, and
commit 114353884415 ("bpf: fix a bug in trunc-op optimization")
fixed a bug in trunc-op optimization which only showed up
with more than one function in the bpf program.

This patch added a test case for trunc-op optimization
for bpf programs with two functions. Reverting commit
"bpf: fix a bug in trunc-op optimization" will cause
failure for this test case.

Signed-off-by: Yonghong Song <yhs at fb.com>

Added:
    llvm/trunk/test/CodeGen/BPF/remove_truncate_3.ll

Added: llvm/trunk/test/CodeGen/BPF/remove_truncate_3.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/BPF/remove_truncate_3.ll?rev=318695&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/BPF/remove_truncate_3.ll (added)
+++ llvm/trunk/test/CodeGen/BPF/remove_truncate_3.ll Mon Nov 20 13:37:58 2017
@@ -0,0 +1,106 @@
+; RUN: llc < %s -march=bpf -verify-machineinstrs | FileCheck %s
+
+; Source code:
+; struct xdp_md {
+;   unsigned data;
+;   unsigned data_end;
+; };
+;
+; int gbl;
+; int xdp_dummy(struct xdp_md *xdp)
+; {
+;   char tmp;
+;   long addr;
+;
+;   if (gbl) {
+;     long addr1 = (long)xdp->data;
+;     tmp = *(char *)addr1;
+;     if (tmp == 1)
+;       return 3;
+;   } else {
+;     tmp = *(volatile char *)(long)xdp->data_end;
+;     if (tmp == 1)
+;       return 2;
+;   }
+;   addr = (long)xdp->data;
+;   tmp = *(volatile char *)addr;
+;   if (tmp == 0)
+;     return 1;
+;   return 0;
+; }
+;
+; unsigned int rol32(unsigned int word, unsigned int shift)
+; {
+;   return (word << shift) | (word >> ((-shift) & 31));
+; }
+%struct.xdp_md = type { i32, i32 }
+
+ at gbl = common local_unnamed_addr global i32 0, align 4
+
+; Function Attrs: norecurse nounwind
+define i32 @xdp_dummy(%struct.xdp_md* nocapture readonly) local_unnamed_addr #0 {
+  %2 = load i32, i32* @gbl, align 4
+  %3 = icmp eq i32 %2, 0
+  br i1 %3, label %11, label %4
+
+; <label>:4:                                      ; preds = %1
+  %5 = getelementptr inbounds %struct.xdp_md, %struct.xdp_md* %0, i64 0, i32 0
+  %6 = load i32, i32* %5, align 4
+  %7 = zext i32 %6 to i64
+  %8 = inttoptr i64 %7 to i8*
+  %9 = load i8, i8* %8, align 1
+  %10 = icmp eq i8 %9, 1
+  br i1 %10, label %28, label %23
+; CHECK:  r1 = *(u32 *)(r1 + 0)
+; CHECK:  r2 = *(u8 *)(r1 + 0)
+
+; <label>:11:                                     ; preds = %1
+  %12 = getelementptr inbounds %struct.xdp_md, %struct.xdp_md* %0, i64 0, i32 1
+  %13 = load i32, i32* %12, align 4
+  %14 = zext i32 %13 to i64
+; CHECK:  r2 = *(u32 *)(r1 + 4)
+  %15 = inttoptr i64 %14 to i8*
+  %16 = load volatile i8, i8* %15, align 1
+; CHECK:  r2 = *(u8 *)(r2 + 0)
+  %17 = icmp eq i8 %16, 1
+  br i1 %17, label %28, label %18
+
+; <label>:18:                                     ; preds = %11
+  %19 = getelementptr inbounds %struct.xdp_md, %struct.xdp_md* %0, i64 0, i32 0
+  %20 = load i32, i32* %19, align 4
+  %21 = zext i32 %20 to i64
+  %22 = inttoptr i64 %21 to i8*
+  br label %23
+; CHECK: r1 = *(u32 *)(r1 + 0)
+
+; <label>:23:                                     ; preds = %18, %4
+  %24 = phi i8* [ %22, %18 ], [ %8, %4 ]
+; CHECK-NOT: r1 <<= 32
+; CHECK-NOT: r1 >>= 32
+  %25 = load volatile i8, i8* %24, align 1
+; CHECK:  r1 = *(u8 *)(r1 + 0)
+  %26 = icmp eq i8 %25, 0
+  %27 = zext i1 %26 to i32
+  br label %28
+
+; <label>:28:                                     ; preds = %4, %23, %11
+  %29 = phi i32 [ 3, %4 ], [ 2, %11 ], [ %27, %23 ]
+  ret i32 %29
+}
+
+; Function Attrs: norecurse nounwind readnone
+define i32 @rol32(i32, i32) local_unnamed_addr #1 {
+  %3 = shl i32 %0, %1
+; CHECK: r3 <<= 32
+; CHECK: r3 >>= 32
+  %4 = sub i32 0, %1
+  %5 = and i32 %4, 31
+  %6 = lshr i32 %0, %5
+; CHECK: r1 <<= 32
+; CHECK: r1 >>= 32
+  %7 = or i32 %6, %3
+  ret i32 %7
+}
+
+attributes #0 = { norecurse nounwind }
+attributes #1 = { norecurse nounwind readnone }




More information about the llvm-commits mailing list