[llvm] d2b4a67 - [BPF] Fix a bug in BPFAdjustOpt pass for icmp transformation
Yonghong Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 17 09:25:33 PDT 2022
Author: Yonghong Song
Date: 2022-03-17T09:25:18-07:00
New Revision: d2b4a675a8f9895eb06eec8a963c11a84d04ed03
URL: https://github.com/llvm/llvm-project/commit/d2b4a675a8f9895eb06eec8a963c11a84d04ed03
DIFF: https://github.com/llvm/llvm-project/commit/d2b4a675a8f9895eb06eec8a963c11a84d04ed03.diff
LOG: [BPF] Fix a bug in BPFAdjustOpt pass for icmp transformation
When checking a bcc issue related to bcc tool inject.py,
I found a bug in BPFAdjustOpt pass for icmp transformation,
caused by typo's. For the following condition:
Cond2Op != ICmpInst::ICMP_SLT && Cond1Op != ICmpInst::ICMP_SLE
it should be
Cond2Op != ICmpInst::ICMP_SLT && Cond2Op != ICmpInst::ICMP_SLE
This patch fixed the problem and a test case is added.
Differential Revision: https://reviews.llvm.org/D121883
Added:
llvm/test/CodeGen/BPF/adjust-opt-icmp5.ll
Modified:
llvm/lib/Target/BPF/BPFAdjustOpt.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/BPF/BPFAdjustOpt.cpp b/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
index 69d0bca0bd772..1e7f5ffdf875c 100644
--- a/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
+++ b/llvm/lib/Target/BPF/BPFAdjustOpt.cpp
@@ -259,10 +259,10 @@ bool BPFAdjustOptImpl::serializeICMPCrossBB(BasicBlock &BB) {
return false;
if (Cond1Op == ICmpInst::ICMP_SGT || Cond1Op == ICmpInst::ICMP_SGE) {
- if (Cond2Op != ICmpInst::ICMP_SLT && Cond1Op != ICmpInst::ICMP_SLE)
+ if (Cond2Op != ICmpInst::ICMP_SLT && Cond2Op != ICmpInst::ICMP_SLE)
return false;
} else if (Cond1Op == ICmpInst::ICMP_SLT || Cond1Op == ICmpInst::ICMP_SLE) {
- if (Cond2Op != ICmpInst::ICMP_SGT && Cond1Op != ICmpInst::ICMP_SGE)
+ if (Cond2Op != ICmpInst::ICMP_SGT && Cond2Op != ICmpInst::ICMP_SGE)
return false;
} else {
return false;
diff --git a/llvm/test/CodeGen/BPF/adjust-opt-icmp5.ll b/llvm/test/CodeGen/BPF/adjust-opt-icmp5.ll
new file mode 100644
index 0000000000000..5aa8c7eadbf3b
--- /dev/null
+++ b/llvm/test/CodeGen/BPF/adjust-opt-icmp5.ll
@@ -0,0 +1,71 @@
+; RUN: opt -O2 -S -mtriple=bpf-pc-linux %s -o %t1
+; RUN: llc %t1 -o - | FileCheck -check-prefixes=CHECK,CHECK-V1 %s
+; RUN: opt -O2 -S -mtriple=bpf-pc-linux %s -o %t1
+; RUN: llc %t1 -mcpu=v3 -o - | FileCheck -check-prefixes=CHECK,CHECK-V3 %s
+;
+; Source:
+; int bar(int);
+; int test(int *p) {
+; if (*p <= 0 || *p >= 7)
+; return 0;
+; return bar(*p);
+; }
+; Compilation flag:
+; clang -target bpf -O2 -S -emit-llvm -Xclang -disable-llvm-passes test.c
+
+; Function Attrs: nounwind
+define dso_local i32 @test(i32* noundef %p) #0 {
+entry:
+ %retval = alloca i32, align 4
+ %p.addr = alloca i32*, align 8
+ store i32* %p, i32** %p.addr, align 8, !tbaa !3
+ %0 = load i32*, i32** %p.addr, align 8, !tbaa !3
+ %1 = load i32, i32* %0, align 4, !tbaa !7
+ %cmp = icmp sle i32 %1, 0
+ br i1 %cmp, label %if.then, label %lor.lhs.false
+
+lor.lhs.false: ; preds = %entry
+ %2 = load i32*, i32** %p.addr, align 8, !tbaa !3
+ %3 = load i32, i32* %2, align 4, !tbaa !7
+ %cmp1 = icmp sge i32 %3, 7
+ br i1 %cmp1, label %if.then, label %if.end
+
+if.then: ; preds = %lor.lhs.false, %entry
+ store i32 0, i32* %retval, align 4
+ br label %return
+
+if.end: ; preds = %lor.lhs.false
+ %4 = load i32*, i32** %p.addr, align 8, !tbaa !3
+ %5 = load i32, i32* %4, align 4, !tbaa !7
+ %call = call i32 @bar(i32 noundef %5)
+ store i32 %call, i32* %retval, align 4
+ br label %return
+
+return: ; preds = %if.end, %if.then
+ %6 = load i32, i32* %retval, align 4
+ ret i32 %6
+}
+
+; CHECK-LABEL: test
+; CHECK-V1: if r[[#]] s> r[[#]] goto
+; CHECK-V1: if r[[#]] s> 6 goto
+; CHECK-V3: if w[[#]] s< 1 goto
+; CHECK-V3: if w[[#]] s> 6 goto
+
+declare dso_local i32 @bar(i32 noundef) #1
+
+attributes #0 = { nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+
+!llvm.module.flags = !{!0, !1}
+!llvm.ident = !{!2}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{i32 7, !"frame-pointer", i32 2}
+!2 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git 0d37a76d31c05372908908ff2f01fc58bbf575e8)"}
+!3 = !{!4, !4, i64 0}
+!4 = !{!"any pointer", !5, i64 0}
+!5 = !{!"omnipotent char", !6, i64 0}
+!6 = !{!"Simple C/C++ TBAA"}
+!7 = !{!8, !8, i64 0}
+!8 = !{!"int", !5, i64 0}
More information about the llvm-commits
mailing list