summaryrefslogtreecommitdiff
path: root/tools/testing
diff options
context:
space:
mode:
authorEduard Zingerman <eddyz87@gmail.com>2026-10-26 16:38:30 -0700
committerAlexei Starovoitov <ast@kernel.org>2026-10-27 16:26:21 +0000
commita0137c789774bdc2eff9b1b4525741ed118eeba0 (patch)
treef49c192f1cc8f755e4a096efbbb56dc3fc58efc4 /tools/testing
parent344c14e8b3d45e3c643cec1ba6acd3e4691dfe66 (diff)
selftests/bpf: 32-bit copy of the counter compared at the latch
When building SCEV expressions for the loop: w7 = w1; r7 = (zext32 r1) w1 = w7; r1 = (zext32 (zext32 r1)) w1 += 2; r1 = (zext32 (+ (zext32 (zext32 r1)) 2)) Computed SCEV expression for r1: (zext32 (linear r1 2)) Substituting this into r7's expression at the latch: (zext32 (zext32 (linear r1 2))) Without (zext32 (zext32 X)) -> (zext32 X) simplification rule the latch would not be recognized as linear and header_count won't be computed. Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261026-scev-simpler-clamp-v2-10-f373aec9825f@gmail.com
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/selftests/bpf/progs/verifier_scev.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/verifier_scev.c b/tools/testing/selftests/bpf/progs/verifier_scev.c
index 39603c8bf083..37434efd1490 100644
--- a/tools/testing/selftests/bpf/progs/verifier_scev.c
+++ b/tools/testing/selftests/bpf/progs/verifier_scev.c
@@ -3710,4 +3710,31 @@ __naked void dominating_exit_bounds_count(void)
" ::: __clobber_all);
}
+/*
+ * The counter is copied to a callee-saved register for the call and the copy is compared.
+ */
+SEC("xdp")
+__success
+__log_level(2)
+__flag(BPF_F_TEST_STATE_FREQ)
+__msg(" scev at latch 5:")
+__msg(" r7=(zext32 r1) / (zext32 (linear r1 2))")
+__msg("loop header at 1, header_count is 100 ")
+__msg("loop header at 1, widening r1 to 0..198 step 2")
+__naked void post_cond_jlt32_copy(void)
+{
+ asm volatile (" \
+ w1 = 0; \
+1: w7 = w1; \
+ call %[bpf_get_prandom_u32]; \
+ w1 = w7; \
+ w1 += 2; \
+ if w7 < 198 goto 1b; \
+ r0 = 0; \
+ exit; \
+" :
+ : __imm(bpf_get_prandom_u32)
+ : __clobber_all);
+}
+
char _license[] SEC("license") = "GPL";